2020-06-26 11:44:46 +02:00
|
|
|
import 'dart:convert';
|
2020-03-12 10:56:52 +01:00
|
|
|
import 'dart:io';
|
2020-03-08 21:11:32 +01:00
|
|
|
import 'package:path/path.dart' as path;
|
|
|
|
|
2020-06-25 22:42:16 +02:00
|
|
|
import 'package:unofficial_jisho_api/api.dart';
|
2020-03-08 21:11:32 +01:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
List<String> getFilePaths(String dirname) {
|
2020-03-12 10:56:52 +01:00
|
|
|
final currentdir = Directory.current.path;
|
2020-06-26 11:44:46 +02:00
|
|
|
final testDir = path.join(currentdir, 'test', dirname);
|
|
|
|
final filenames = Directory(testDir).listSync();
|
|
|
|
return filenames.map((filename) => path.join(testDir, filename.path));
|
2020-03-08 21:11:32 +01:00
|
|
|
}
|
|
|
|
|
2020-06-26 11:44:46 +02:00
|
|
|
List getTestCases(String directoryName) {
|
|
|
|
final testCaseFiles = getFilePaths(directoryName);
|
|
|
|
var result = [];
|
|
|
|
|
2020-03-08 21:11:32 +01:00
|
|
|
for (var testCount = 0; testCount < testCaseFiles.length; testCount++) {
|
2020-06-26 11:44:46 +02:00
|
|
|
final file = File(testCaseFiles[testCount]).readAsStringSync();
|
|
|
|
result.add(jsonDecode(file));
|
2020-03-08 21:11:32 +01:00
|
|
|
}
|
2020-06-26 11:44:46 +02:00
|
|
|
return result;
|
2020-03-08 21:11:32 +01:00
|
|
|
}
|
|
|
|
|
2020-06-26 11:44:46 +02:00
|
|
|
void main() {
|
|
|
|
group('searchForKanji', () {
|
|
|
|
final testCases = getTestCases('kanji_test_cases');
|
|
|
|
for (var testCase in testCases) {
|
|
|
|
test('Query "${testCase['query']}"', () async {
|
|
|
|
final result = await searchForKanji(testCase['query']);
|
|
|
|
expect(jsonEncode(result), jsonEncode(testCase));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
group('searchForExamples', () {
|
|
|
|
final testCases = getTestCases('example_test_cases');
|
|
|
|
for (var testCase in testCases) {
|
|
|
|
test('Query "${testCase['query']}"', () async {
|
|
|
|
final result = await searchForExamples(testCase['query']);
|
|
|
|
expect(jsonEncode(result), jsonEncode(testCase));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
group('scrapeForPhrase', () {
|
|
|
|
final testCases = getTestCases('phrase_scrape_test_cases');
|
|
|
|
for (var testCase in testCases) {
|
|
|
|
test('Query "${testCase['query']}"', () async {
|
|
|
|
final result = await scrapeForPhrase(testCase['query']);
|
|
|
|
expect(jsonEncode(result), jsonEncode(testCase));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|