mirror of
https://github.com/h7x4/unofficial_jisho_api_dart.git
synced 2025-12-20 17:24:36 +01:00
Update to 3.0.0
- Add fromJson factories for all objects
- Make some properties use getters, to reduce redundant data
- Make all objects comparable with the equatable package
- Make all objects immutable with a constant constructor
as a result of making them comparable
This commit is contained in:
@@ -14,9 +14,9 @@ List<String> getFilePaths(String dirname) {
|
||||
.toList();
|
||||
}
|
||||
|
||||
List getTestCases(String directoryName) {
|
||||
List<dynamic> getTestCases(String directoryName) {
|
||||
final testCaseFiles = getFilePaths(directoryName);
|
||||
var result = [];
|
||||
final result = <dynamic>[];
|
||||
|
||||
for (var testCount = 0; testCount < testCaseFiles.length; testCount++) {
|
||||
final file = File(testCaseFiles[testCount]).readAsStringSync();
|
||||
@@ -27,32 +27,53 @@ List getTestCases(String directoryName) {
|
||||
|
||||
void main() {
|
||||
group('searchForKanji', () {
|
||||
final testCases = getTestCases('kanji_test_cases');
|
||||
final testCases = getTestCases('kanji_test_cases')
|
||||
.map((e) => KanjiResult.fromJson(e))
|
||||
.toList();
|
||||
for (var testCase in testCases) {
|
||||
test('Query "${testCase['query']}"', () async {
|
||||
final result = await searchForKanji(testCase['query']);
|
||||
expect(jsonEncode(result), jsonEncode(testCase));
|
||||
test('Query "${testCase.query}"', () async {
|
||||
final result = await searchForKanji(testCase.query);
|
||||
expect(result, testCase);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
group('searchForExamples', () {
|
||||
final testCases = getTestCases('example_test_cases');
|
||||
final testCases = getTestCases('example_test_cases')
|
||||
.map((e) => ExampleResults.fromJson(e))
|
||||
.toList();
|
||||
for (var testCase in testCases) {
|
||||
test('Query "${testCase['query']}"', () async {
|
||||
final result = await searchForExamples(testCase['query']);
|
||||
expect(jsonEncode(result), jsonEncode(testCase));
|
||||
test('Query "${testCase.query}"', () async {
|
||||
final result = await searchForExamples(testCase.query);
|
||||
expect(result, testCase);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
group('scrapeForPhrase', () {
|
||||
final testCases = getTestCases('phrase_scrape_test_cases');
|
||||
final testCases = getTestCases('phrase_scrape_test_cases')
|
||||
.map((e) => PhrasePageScrapeResult.fromJson(e))
|
||||
.toList();
|
||||
for (var testCase in testCases) {
|
||||
test('Query "${testCase['query']}"', () async {
|
||||
final result = await scrapeForPhrase(testCase['query']);
|
||||
expect(jsonEncode(result), jsonEncode(testCase));
|
||||
test('Query "${testCase.query}"', () async {
|
||||
final result = await scrapeForPhrase(testCase.query);
|
||||
expect(result, testCase);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
group('equatable', () {
|
||||
// searchForExample returns random results, not stable for testing.
|
||||
// I will assume it works if all the other works, and rather wait for
|
||||
// reports in Github issues if something is broken.
|
||||
final kanjiSearch = [searchForKanji('関'), searchForKanji('関')];
|
||||
final phraseScrape = [scrapeForPhrase('関係'), scrapeForPhrase('関係')];
|
||||
final phraseSearch = [searchForPhrase('関係'), searchForPhrase('関係')];
|
||||
for (var testCase in [kanjiSearch, phraseScrape, phraseSearch]) {
|
||||
test('Equate ${testCase[0].runtimeType}' , () async {
|
||||
expect(await testCase[0], await testCase[1]);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user