Skip to content

Commit

Permalink
fixup! 2 wip rename: v2
Browse files Browse the repository at this point in the history
  • Loading branch information
zin- committed Sep 18, 2024
1 parent 7e2a88d commit e6da190
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ void main() {

for (final testCase in [
TestCase(
'pick start',
name: 'pick start',
DateAndTimePeriod(start: DateAndTime.from(now)),
(input) => null,
null,
),
TestCase(
'pick end',
name: 'pick end',
DateAndTimePeriod(end: DateAndTime.from(now)),
(input) => null,
null,
),
]) {
testWidgets(
'Change null: ${testCase.name}.',
skip: true,
(widgetTester) async {
var count = 0;

Expand Down
8 changes: 4 additions & 4 deletions test/core/date_and_time_period_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void main() {

group(": compare", () {
for (var testCase in [
TestCaseV2(
TestCase(
name: "both are not null",
[
DateAndTimePeriod.startNow(),
Expand All @@ -275,17 +275,17 @@ void main() {
DateAndTimePeriod.startNow()
.compareTo(DateAndTimePeriod(end: DateAndTime.now())),
),
TestCaseV2(
TestCase(
name: "both are null",
[null, null],
0,
),
TestCaseV2(
TestCase(
name: "a is null, b is not null",
[null, DateAndTimePeriod.startNow()],
1,
),
TestCaseV2(
TestCase(
name: "a is not null, b is null",
[DateAndTimePeriod.startNow(), null],
-1,
Expand Down
16 changes: 4 additions & 12 deletions test/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,12 @@ Widget buildTestAppWithProvider(
child: buildTestApp(widget),
);

class TestCaseV2<I> {
final I input;
final dynamic expected;
class TestCase<INPUT, EXPECTED> {
final INPUT input;
final EXPECTED expected;
final String? name;

TestCaseV2(this.input, this.expected, {this.name});
}

class TestCase<T> {
final String name;
final T input;
final Function(T input) verify;

TestCase(this.name, this.input, this.verify);
TestCase(this.input, this.expected, {this.name});
}

// Finders
Expand Down
130 changes: 80 additions & 50 deletions test/logger/logger_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ void main() {

group(": on service level is info", () {
for (final testCase in [
TestCase("verbose", Level.verbose, (Level input) {
verifyNever(mockedLoggerWrapper.log(any, any, any, any));
}),
TestCase("info", Level.info, (Level input) {
verify(mockedLoggerWrapper.log(input, any, null, null)).called(1);
}),
TestCase(
name: "verbose",
Level.verbose,
(Level input) =>
verifyNever(mockedLoggerWrapper.log(any, any, any, any)),
),
TestCase(
name: "info",
Level.info,
(Level input) =>
verify(mockedLoggerWrapper.log(input, any, null, null)).called(1),
),
]) {
test(": log level is ${testCase.name}.", () {
final level = testCase.input;
Expand All @@ -38,7 +44,7 @@ void main() {

expect(result, target);

testCase.verify(level);
testCase.expected(level);
});
}
});
Expand Down Expand Up @@ -331,12 +337,17 @@ void main() {
});

for (final testCase in [
TestCase("verbose", Level.verbose, (input) {
verifyNever(mockedLoggerWrapper.log(any, any, any, any));
}),
TestCase("info", Level.info, (input) {
verifyNever(mockedLoggerWrapper.log(any, any, any, any));
}),
TestCase(
name: "verbose",
Level.verbose,
(input) =>
verifyNever(mockedLoggerWrapper.log(any, any, any, any))),
TestCase(
name: "info",
Level.info,
(input) =>
verifyNever(mockedLoggerWrapper.log(any, any, any, any)),
),
]) {
test(
": on error: ${testCase.name}.",
Expand All @@ -345,6 +356,7 @@ void main() {
const errorMessage = "test message future";
final e = Exception(errorMessage);

verifyNever(mockedLoggerWrapper.log(any, any, any, any));
expect(
() => LogService().valueLog(level, Future.error(e)),
throwsA((thrown) {
Expand All @@ -371,25 +383,32 @@ void main() {

group(": alias", () {
for (final testCase in [
TestCase("verbose", verbose, (input) {
verifyNever(mockedLoggerWrapper.log(any, any, any, any));
}),
TestCase("info", info, (input) {
verify(mockedLoggerWrapper.log(Level.info, "info", null, null))
.called(1);
}),
TestCase("warn", warn, (input) {
verify(mockedLoggerWrapper.log(Level.warning, "warn", null, null))
.called(1);
}),
TestCase(
"debug",
name: "verbose",
verbose,
(input) => verifyNever(mockedLoggerWrapper.log(any, any, any, any)),
),
TestCase(
name: "info",
info,
(input) =>
verify(mockedLoggerWrapper.log(Level.info, "info", null, null))
.called(1),
),
TestCase(
name: "warn",
warn,
(input) =>
verify(mockedLoggerWrapper.log(Level.warning, "warn", null, null))
.called(1),
),
TestCase(
name: "debug",
// ignore: deprecated_member_use_from_same_package
debug,
(input) {
verify(mockedLoggerWrapper.log(Level.debug, "debug", null, null))
.called(1);
},
(input) =>
verify(mockedLoggerWrapper.log(Level.debug, "debug", null, null))
.called(1),
),
]) {
test(": ${testCase.name}", () {
Expand All @@ -399,7 +418,7 @@ void main() {

expect(result, testMessage);

testCase.verify(testCase.input);
testCase.expected(testCase.input);
});
}
});
Expand Down Expand Up @@ -830,26 +849,37 @@ void main() {

group(": alias", () {
for (final testCase in [
TestCase("v", v, (input) {
verifyNever(mockedLoggerWrapper.log(any, any, any, any));
}),
TestCase("i", i, (input) {
verify(mockedLoggerWrapper.log(
Level.info, "[start] :: null", null, null))
.called(1);
verify(mockedLoggerWrapper.log(Level.info, "[end] => i", null, null))
.called(1);
}),
TestCase("w", w, (input) {
verify(mockedLoggerWrapper.log(
Level.warning, "[start] :: null", null, null))
.called(1);
verify(mockedLoggerWrapper.log(
Level.warning, "[end] => w", null, null))
.called(1);
}),
TestCase(
"d",
name: "v",
v,
(input) => verifyNever(mockedLoggerWrapper.log(any, any, any, any)),
),
TestCase(
name: "i",
i,
(input) {
verify(mockedLoggerWrapper.log(
Level.info, "[start] :: null", null, null))
.called(1);
verify(mockedLoggerWrapper.log(
Level.info, "[end] => i", null, null))
.called(1);
},
),
TestCase(
name: "w",
w,
(input) {
verify(mockedLoggerWrapper.log(
Level.warning, "[start] :: null", null, null))
.called(1);
verify(mockedLoggerWrapper.log(
Level.warning, "[end] => w", null, null))
.called(1);
},
),
TestCase(
name: "d",
// ignore: deprecated_member_use_from_same_package
d,
(input) {
Expand All @@ -871,7 +901,7 @@ void main() {

expect(result, testMessage);

testCase.verify(testCase.input);
testCase.expected(testCase.input);
});
}
});
Expand Down

0 comments on commit e6da190

Please sign in to comment.