2020-06-23 12:30:07 +02:00
|
|
|
import 'dart:io';
|
|
|
|
import 'package:path/path.dart' as path;
|
|
|
|
import 'dart:convert';
|
|
|
|
|
2020-06-25 22:42:16 +02:00
|
|
|
import 'package:unofficial_jisho_api/api.dart';
|
2020-06-23 12:30:07 +02:00
|
|
|
|
|
|
|
final encoder = JsonEncoder.withIndent(' ');
|
|
|
|
final currentdir = Directory.current.path;
|
|
|
|
|
|
|
|
void writeCases(Function apiFunction, String folderName, List<String> queries) async {
|
|
|
|
final dir = path.join(currentdir, 'test', folderName);
|
|
|
|
|
|
|
|
for (var testCount = 0; testCount < queries.length; testCount++) {
|
|
|
|
final result = await apiFunction(queries[testCount]);
|
|
|
|
final content = encoder.convert(result);
|
|
|
|
final filePath = path.join(dir, '${testCount}.json');
|
|
|
|
|
|
|
|
await File(filePath).writeAsString(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const kanjiQueries = ['車', '家', '楽', '極上', '贄', 'ネガティブ', 'wegmwrlgkrgmg', '水'];
|
|
|
|
const exampleQueries = ['車', '日本人', '彼*叩く', '皆', 'ネガティブ', 'grlgmregmneriireg'];
|
|
|
|
const phraseQueries = ['車', '日本人', '皆', 'ネガティブ', 'grlgmregmneriireg'];
|
|
|
|
|
|
|
|
void main() async {
|
2020-06-25 22:42:16 +02:00
|
|
|
await writeCases(searchForKanji, 'kanji_test_cases', kanjiQueries);
|
|
|
|
await writeCases(searchForExamples, 'example_test_cases', exampleQueries);
|
|
|
|
await writeCases(scrapeForPhrase, 'phrase_scrape_test_cases', phraseQueries);
|
2020-06-23 12:30:07 +02:00
|
|
|
}
|