import 'package:flutter_test/flutter_test.dart'; import 'package:halkyon_learn_flutter/src/feature/dictionary/model/japanese_deinflection.dart'; /// The words [text] deinflects to that a dictionary entry of [pos] fits. Set wordsOf(String text, List pos) => { for (final each in deinflect(text)) if (each.fits(pos)) each.text, }; void main() { test('the text as it stands comes first, and fits any word', () { final first = deinflect('天気').first; expect(first.text, '天気'); expect(first.steps, isEmpty); expect(first.form, isNull); expect(first.fits(const ['n']), isTrue); }); test('verbs come back to their dictionary form', () { expect(wordsOf('会いました', ['v5u']), contains('会う')); expect(wordsOf('読んだ', ['v5m']), contains('読む')); expect(wordsOf('読んでいない', ['v5m']), contains('読む')); expect(wordsOf('食べられなかった', ['v1']), contains('食べる')); expect(wordsOf('出ていった', ['v1']), contains('出る')); expect(wordsOf('残っている', ['v5r']), contains('残る')); expect(wordsOf('続けよう', ['v1']), contains('続ける')); expect(wordsOf('行かなければ', ['v5k-s']), contains('行く')); expect(wordsOf('なりたい', ['v5r']), contains('なる')); expect(wordsOf('使える', ['v5u']), contains('使う')); expect(wordsOf('食べちゃった', ['v1']), contains('食べる')); expect(wordsOf('読まれた', ['v5m']), contains('読む')); expect(wordsOf('来ない', ['vk']), contains('来る')); expect(wordsOf('きました', ['vk']), contains('くる')); }); test('adjectives and nouns taking する come back too', () { expect(wordsOf('面白そう', ['adj-i']), contains('面白い')); expect(wordsOf('早く', ['adj-i']), contains('早い')); expect(wordsOf('高くなかった', ['adj-i']), contains('高い')); expect(wordsOf('高すぎた', ['adj-i']), contains('高い')); expect(wordsOf('勉強した', ['n', 'vs']), contains('勉強')); }); test('a form only counts for a word of its class', () { // 読んだ as the past of an ichidan verb 読んる doesn't exist; as the // past of a godan verb in ぬ or ぶ it would, were there such a word. expect(wordsOf('読んだ', ['v1']), isNot(contains('読む'))); expect(wordsOf('食べた', ['v5r']), isNot(contains('食べる'))); expect(wordsOf('早く', ['v1']), isNot(contains('早い'))); }); test('stems and forms that only lead on are never offered as words', () { expect( deinflect('食べて').map((each) => each.form), isNot(contains(JapaneseForm.te)), ); expect( deinflect('会いました').map((each) => each.form), isNot(contains(JapaneseForm.masuStem)), ); }); test('says how it got there, the last step first', () { final cake = deinflect('食べられなかった').firstWhere( (each) => each.text == '食べる' && each.form == JapaneseForm.ichidan, ); expect(cake.steps, ['passive or potential', 'negative', 'past']); }); }