unofficial_jisho_api_dart/test/create_test_cases.dart

35 lines
1.2 KiB
Dart
Raw Normal View History

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