64 lines
2.6 KiB
Dart
64 lines
2.6 KiB
Dart
|
|
import 'dart:io';
|
||
|
|
|
||
|
|
import 'package:flutter_test/flutter_test.dart';
|
||
|
|
import 'package:halkyon_learn_flutter/src/feature/dictionary/data/device_dictionaries.dart';
|
||
|
|
import 'package:halkyon_learn_flutter/src/feature/dictionary/data/device_dictionary_store.dart';
|
||
|
|
import 'package:halkyon_learn_flutter/src/feature/dictionary/data/japanese_analyser.dart';
|
||
|
|
import 'package:halkyon_learn_flutter/src/feature/dictionary/model/sentence_words.dart';
|
||
|
|
import 'package:integration_test/integration_test.dart';
|
||
|
|
|
||
|
|
// Japanese cut on the device for real (ADR 0012): MeCab as the package's
|
||
|
|
// build hook compiles it for the platform, IPADIC as the curator packs it,
|
||
|
|
// and JMdict as an instance exports it. On the desktop,
|
||
|
|
//
|
||
|
|
// flutter test integration_test/japanese_analyser_test.dart -d linux \
|
||
|
|
// --dart-define=IPADIC_PACK=<mecab-ipadic.tar.gz> \
|
||
|
|
// --dart-define=JMDICT_EXPORT=<jmdict-en-….jsonl.gz>
|
||
|
|
//
|
||
|
|
// with the files an instance serves at /device-dictionaries/ (both named in
|
||
|
|
// `dictionary.deviceFiles('ja')`); the curator's `curate ipadic` writes the
|
||
|
|
// pack.
|
||
|
|
const _pack = String.fromEnvironment('IPADIC_PACK');
|
||
|
|
const _export = String.fromEnvironment('JMDICT_EXPORT');
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||
|
|
|
||
|
|
late Directory folder;
|
||
|
|
|
||
|
|
setUpAll(() async {
|
||
|
|
folder = Directory.systemTemp.createTempSync('japanese');
|
||
|
|
unpackIpadic(File(_pack), Directory('${folder.path}/ipadic'));
|
||
|
|
await buildDeviceDictionary(
|
||
|
|
File(_export),
|
||
|
|
File('${folder.path}/jmdict.sqlite'),
|
||
|
|
);
|
||
|
|
});
|
||
|
|
tearDownAll(() => folder.deleteSync(recursive: true));
|
||
|
|
|
||
|
|
String cut(List<SentencePart> parts) => [
|
||
|
|
for (final part in parts)
|
||
|
|
if (part.isWord) part.text else '(${part.text})',
|
||
|
|
].join(' ');
|
||
|
|
|
||
|
|
testWidgets('cuts lines into words as Jisho.org does, and finds each in '
|
||
|
|
'JMdict', (tester) async {
|
||
|
|
final lines = await tester.runAsync(
|
||
|
|
() => IsolateJapaneseAnalyser().wordsOf(
|
||
|
|
ipadic: '${folder.path}/ipadic',
|
||
|
|
database: '${folder.path}/jmdict.sqlite',
|
||
|
|
sentences: ['今日はいい天気ですね。', 'お前がもうろくだよ', '勉強している', '静かな部屋'],
|
||
|
|
),
|
||
|
|
);
|
||
|
|
|
||
|
|
final [weather, senile, study, room] = lines!;
|
||
|
|
expect(cut(weather), '今日 は いい 天気 です ね (。)');
|
||
|
|
expect(weather.first.entries.first.headword, '今日');
|
||
|
|
expect(cut(senile), 'お前 が もうろく だ よ');
|
||
|
|
expect(senile[2].entries.first.headword, '耄碌');
|
||
|
|
expect(study.single.entries.first.headword, '勉強');
|
||
|
|
expect(study.single.steps, isNotEmpty);
|
||
|
|
expect(cut(room), '静かな 部屋');
|
||
|
|
expect(room.first.entries.first.headword, '静か');
|
||
|
|
});
|
||
|
|
}
|