Skip to content

Commit

Permalink
chore(tests): integrate sealed world tests and refactor assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
tsinis committed Oct 13, 2024
1 parent b4c3846 commit 7b2be13
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 244 deletions.
2 changes: 1 addition & 1 deletion packages/_sealed_world_tests/lib/tests/advanced_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void assertTest(
int? retry,
}) =>
test(
"throws $AssertionError on $description",
description,
() async {
expect(
createInstance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "../../../model/country/submodels/country_name.dart";
/// {@macro submodels_class_extension}
extension CountryNameExtension on CountryName {
/// Non-nullable alias for a `name`. The common name of the country.
String get common => name;

/// Non-nullable alias for a `fullName`. The official name of the country.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "package:_sealed_world_tests/sealed_world_tests.dart";
import "package:sealed_countries/src/helpers/extensions/country_submodels/capital_extension.dart";
import "package:sealed_countries/src/model/country/submodels/capital.dart";
import "package:sealed_currencies/sealed_currencies.dart";
Expand Down Expand Up @@ -29,40 +30,26 @@ void main() => group("$Capital", () {
});

group("asserts", () {
test(
assertTest(
"not",
() => expect(
() => Capital(
value.deFacto,
deJure: TestData.string,
third: TestData.string,
),
isNot(throwsA(isA<AssertionError>())),
() => Capital(
value.deFacto,
deJure: TestData.string,
third: TestData.string,
),
shouldThrow: false,
);

test(
"name length",
() => expect(
() => Capital(TestData.emptyString),
throwsA(isA<AssertionError>()),
),
);
assertTest("name length", () => Capital(TestData.emptyString));

test(
assertTest(
"deJure length",
() => expect(
() => Capital(value.deFacto, deJure: TestData.emptyString),
throwsA(isA<AssertionError>()),
),
() => Capital(value.deFacto, deJure: TestData.emptyString),
);

test(
assertTest(
"third length",
() => expect(
() => Capital(value.deFacto, third: TestData.emptyString),
throwsA(isA<AssertionError>()),
),
() => Capital(value.deFacto, third: TestData.emptyString),
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "package:_sealed_world_tests/sealed_world_tests.dart";
import "package:sealed_countries/src/helpers/extensions/country_submodels/car_extension.dart";
import "package:sealed_countries/src/model/country/submodels/car.dart";
import "package:sealed_currencies/sealed_currencies.dart";
Expand Down Expand Up @@ -35,21 +36,13 @@ void main() => group("$Car", () {
});

group("asserts", () {
test(
assertTest(
"not",
() => expect(
() => Car(sign: value.sign, isRightSide: value.isRightSide),
isNot(throwsA(isA<AssertionError>())),
),
() => Car(sign: value.sign, isRightSide: value.isRightSide),
shouldThrow: false,
);

test(
"empty sign",
() => expect(
() => Car(sign: TestData.emptyString),
throwsA(isA<AssertionError>()),
),
);
assertTest("empty sign", () => Car(sign: TestData.emptyString));
});

test("toJson", () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "package:_sealed_world_tests/sealed_world_tests.dart";
import "package:sealed_countries/src/helpers/extensions/country_submodels/country_name_extension.dart";
import "package:sealed_countries/src/model/country/submodels/country_name.dart";
import "package:sealed_currencies/sealed_currencies.dart";
Expand Down Expand Up @@ -61,56 +62,33 @@ void main() => group("$CountryName", () {
});

group("asserts", () {
test(
assertTest(
"not",
() => expect(
() => CountryName(
language: value.language,
official: value.official,
common: value.common,
),
isNot(throwsA(isA<AssertionError>())),
() => CountryName(
language: value.language,
official: value.official,
common: value.common,
),
shouldThrow: false,
);

test("empty official", () {
expect(
() => CountryName(
language: const LangEng(),
official: TestData.emptyString,
common: value.common,
),
throwsA(isA<AssertionError>()),
);
expect(
() => CountryName(
language: value.language,
official: TestData.emptyString,
common: value.common,
),
throwsA(isA<AssertionError>()),
);
});

test("empty common", () {
expect(
() => CountryName(
language: const LangEng(),
official: value.official,
common: TestData.emptyString,
),
throwsA(isA<AssertionError>()),
);
assertTest(
"empty official",
() => CountryName(
language: value.language,
official: TestData.emptyString,
common: value.common,
),
);

expect(
() => CountryName(
language: value.language,
official: value.official,
common: TestData.emptyString,
),
throwsA(isA<AssertionError>()),
);
});
assertTest(
"empty common",
() => CountryName(
language: value.language,
official: value.official,
common: TestData.emptyString,
),
);
});

test("toJson", () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "package:_sealed_world_tests/sealed_world_tests.dart";
import "package:sealed_countries/src/helpers/extensions/country_submodels/demonyms_extension.dart";
import "package:sealed_countries/src/model/country/submodels/demonyms.dart";
import "package:sealed_currencies/sealed_currencies.dart";
Expand Down Expand Up @@ -61,39 +62,31 @@ void main() => group("$Demonyms", () {
});

group("asserts", () {
test(
assertTest(
"not",
() => expect(
() => Demonyms(
language: value.language,
female: value.female,
male: value.male,
),
isNot(throwsA(isA<AssertionError>())),
() => Demonyms(
language: value.language,
female: value.female,
male: value.male,
),
shouldThrow: false,
);

test(
assertTest(
"empty female",
() => expect(
() => Demonyms(
language: value.language,
female: TestData.emptyString,
male: value.male,
),
throwsA(isA<AssertionError>()),
() => Demonyms(
language: value.language,
female: TestData.emptyString,
male: value.male,
),
);

test(
assertTest(
"empty male",
() => expect(
() => Demonyms(
language: value.language,
female: value.female,
male: TestData.emptyString,
),
throwsA(isA<AssertionError>()),
() => Demonyms(
language: value.language,
female: value.female,
male: TestData.emptyString,
),
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "package:_sealed_world_tests/sealed_world_tests.dart";
import "package:sealed_countries/src/helpers/extensions/country_submodels/gini_extension.dart";
import "package:sealed_countries/src/model/country/submodels/gini.dart";
import "package:sealed_currencies/sealed_currencies.dart";
Expand Down Expand Up @@ -45,44 +46,33 @@ void main() => group("$Gini", () {
});

group("asserts", () {
test(
assertTest(
"not",
() => expect(
() => Gini(year: value.year, coefficient: value.coefficient),
isNot(throwsA(isA<AssertionError>())),
),
() => Gini(year: value.year, coefficient: value.coefficient),
shouldThrow: false,
);

test(
assertTest(
"wrong year",
() => expect(
() => Gini(
year: Gini.minYear - TestData.integer,
coefficient: value.coefficient,
),
throwsA(isA<AssertionError>()),
() => Gini(
year: Gini.minYear - TestData.integer,
coefficient: value.coefficient,
),
);

test(
assertTest(
"wrong coefficient (too low)",
() => expect(
() => Gini(
year: value.year,
coefficient: Gini.minCoefficient - TestData.float,
),
throwsA(isA<AssertionError>()),
() => Gini(
year: value.year,
coefficient: Gini.minCoefficient - TestData.float,
),
);

test(
assertTest(
"wrong coefficient (too high)",
() => expect(
() => Gini(
year: value.year,
coefficient: Gini.maxCoefficient + TestData.float,
),
throwsA(isA<AssertionError>()),
() => Gini(
year: value.year,
coefficient: Gini.maxCoefficient + TestData.float,
),
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "package:_sealed_world_tests/sealed_world_tests.dart";
import "package:sealed_countries/src/helpers/extensions/country_submodels/idd_extension.dart";
import "package:sealed_countries/src/model/country/submodels/idd.dart";
import "package:sealed_currencies/sealed_currencies.dart";
Expand Down Expand Up @@ -36,20 +37,15 @@ void main() => group("$Idd", () {
});

group("asserts", () {
test(
assertTest(
"not",
() => expect(
() => Idd(root: value.root, suffixes: value.suffixes),
isNot(throwsA(isA<AssertionError>())),
),
() => Idd(root: value.root, suffixes: value.suffixes),
shouldThrow: false,
);

test(
assertTest(
"empty suffixes",
() => expect(
() => Idd(root: value.root, suffixes: const []),
throwsA(isA<AssertionError>()),
),
() => Idd(root: value.root, suffixes: const []),
);
});

Expand Down
Loading

0 comments on commit 7b2be13

Please sign in to comment.