mirror of
https://github.com/h7x4/unofficial_jisho_api_dart.git
synced 2025-09-21 04:55:56 +02:00
Update code
This commit is contained in:
@@ -14,29 +14,13 @@ List<String> getFilePaths(String dirname) {
|
||||
return filenames.map((filename) => path.join(currentdir, 'test', dirname, filename.path)).toList();
|
||||
}
|
||||
|
||||
void runTestCases(List<String> testCaseFiles, String apiFunction) async {
|
||||
void runTestCases(List<String> testCaseFiles, Function apiFunction) async {
|
||||
for (var testCount = 0; testCount < testCaseFiles.length; testCount++) {
|
||||
final file = await File(testCaseFiles[testCount]).readAsString();
|
||||
final testCase = jsonDecode(file);
|
||||
await test('Test ${testCount}', () async {
|
||||
switch(apiFunction) {
|
||||
case 'searchForKanji': {
|
||||
final result = await jisho.searchForKanji(testCase['query']);
|
||||
expect(result.toJson(), testCase['expectedResult']);
|
||||
break;
|
||||
}
|
||||
case 'searchForExamples': {
|
||||
final result = await jisho.searchForExamples(testCase['query']);
|
||||
expect(result, testCase['expectedResult']);
|
||||
break;
|
||||
}
|
||||
case 'scrapeForPhrase': {
|
||||
final result = await jisho.scrapeForPhrase(testCase['query']);
|
||||
expect(result, testCase['expectedResult']);
|
||||
break;
|
||||
}
|
||||
throw 'No API function provided';
|
||||
}
|
||||
final result = await apiFunction(testCase['query']);
|
||||
expect(result, testCase['expectedResult']);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -45,10 +29,8 @@ void main() async {
|
||||
|
||||
await test_local_functions();
|
||||
|
||||
await runTestCases(getFilePaths('kanji_test_cases'), 'searchForKanji');
|
||||
|
||||
await runTestCases(getFilePaths('example_test_cases'), 'searchForExamples');
|
||||
|
||||
await runTestCases(getFilePaths('phrase_scrape_test_cases'), 'scrapeForPhrase');
|
||||
await runTestCases(getFilePaths('kanji_test_cases'), jisho.searchForKanji);
|
||||
await runTestCases(getFilePaths('example_test_cases'), jisho.searchForExamples);
|
||||
await runTestCases(getFilePaths('phrase_scrape_test_cases'), jisho.scrapeForPhrase);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user