From 7157bd1d73c95810e0bb7817ce4fc1c47cf58bbe Mon Sep 17 00:00:00 2001 From: h7x4 Date: Thu, 12 Mar 2020 10:56:52 +0100 Subject: [PATCH] fix tests --- lib/src/unofficial_jisho_api_base.dart | 2 +- test/unofficial_jisho_api_test.dart | 43 ++++++++++---------------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/lib/src/unofficial_jisho_api_base.dart b/lib/src/unofficial_jisho_api_base.dart index 0299261..54a5904 100644 --- a/lib/src/unofficial_jisho_api_base.dart +++ b/lib/src/unofficial_jisho_api_base.dart @@ -433,7 +433,7 @@ PhrasePageScrapeResult parsePhrasePageData(pageHtml, query) { return result; } -class API { +class JishoApi { /// Query the official Jisho API for a word or phrase /// diff --git a/test/unofficial_jisho_api_test.dart b/test/unofficial_jisho_api_test.dart index 9f76635..14557cf 100644 --- a/test/unofficial_jisho_api_test.dart +++ b/test/unofficial_jisho_api_test.dart @@ -1,37 +1,37 @@ -import 'dart:io' as io; +import 'dart:io'; import 'package:path/path.dart' as path; import 'dart:convert'; import 'package:unofficial_jisho_api/unofficial_jisho_api.dart'; import 'package:test/test.dart'; -final jisho = API(); +final jisho = JishoApi(); List getFilePaths(String dirname) { - final currentdir = io.Directory.current.path; - final filenames = io.Directory(path.join(currentdir, 'test', dirname)).listSync(); + final currentdir = Directory.current.path; + final filenames = Directory(path.join(currentdir, 'test', dirname)).listSync(); return filenames.map((filename) => path.join(currentdir, 'test', dirname, filename.path)).toList(); } -void runTestCases(testCaseFiles, apiFunction) async { +void runTestCases(List testCaseFiles, String apiFunction) async { for (var testCount = 0; testCount < testCaseFiles.length; testCount++) { - final file = await io.File(testCaseFiles[testCount]).readAsString(); + final file = await File(testCaseFiles[testCount]).readAsString(); final testCase = jsonDecode(file); - test('Test ${testCount}', () async { + await test('Test ${testCount}', () async { switch(apiFunction) { case 'searchForKanji': { - final result = await jisho.searchForKanji(testCase.query); - expect(result, testCase.expectedResult); + final result = await jisho.searchForKanji(testCase['query']); + expect(result, testCase['expectedResult']); break; } case 'searchForExamples': { - final result = await jisho.searchForExamples(testCase.query); - expect(result, testCase.expectedResult); + 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); + final result = await jisho.scrapeForPhrase(testCase['query']); + expect(result, testCase['expectedResult']); break; } throw 'No API function provided'; @@ -40,21 +40,12 @@ void runTestCases(testCaseFiles, apiFunction) async { } } -void main() { +void main() async { - group('Kanji test cases', () { - final filePaths = getFilePaths('kanji_test_cases'); - runTestCases(filePaths, 'searchForKanji'); - }); + await runTestCases(getFilePaths('kanji_test_cases'), 'searchForKanji'); - group('Example test cases', () { - final filePaths = getFilePaths('example_test_cases'); - runTestCases(filePaths, 'searchForExamples'); - }); + await runTestCases(getFilePaths('example_test_cases'), 'searchForExamples'); - group('Phrase scrape test cases', () { - final filePaths = getFilePaths('phrase_scrape_test_cases'); - runTestCases(filePaths, 'scrapeForPhrase'); - }); + await runTestCases(getFilePaths('phrase_scrape_test_cases'), 'scrapeForPhrase'); }