258 lines
6.2 KiB
Dart
258 lines
6.2 KiB
Dart
import 'package:jadb/models/common/jlpt_level.dart';
|
|
import 'package:jadb/models/word_search/word_search_match_span.dart';
|
|
import 'package:jadb/models/word_search/word_search_result.dart';
|
|
import 'package:jadb/models/word_search/word_search_ruby.dart';
|
|
import 'package:jadb/models/word_search/word_search_sense.dart';
|
|
import 'package:jadb/models/word_search/word_search_sources.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
void main() {
|
|
test('Infer match whole word', () {
|
|
final wordSearchResult = WordSearchResult(
|
|
entryId: 0,
|
|
score: 0,
|
|
isCommon: false,
|
|
jlptLevel: JlptLevel.none,
|
|
kanjiInfo: {},
|
|
readingInfo: {},
|
|
japanese: [WordSearchRuby(base: '仮名')],
|
|
senses: [],
|
|
sources: WordSearchSources.empty(),
|
|
);
|
|
|
|
wordSearchResult.inferMatchSpans('仮名');
|
|
|
|
expect(wordSearchResult.matchSpans, [
|
|
WordSearchMatchSpan(
|
|
spanType: WordSearchMatchSpanType.kanji,
|
|
start: 0,
|
|
end: 2,
|
|
index: 0,
|
|
),
|
|
]);
|
|
});
|
|
|
|
test('Infer match part of word', () {
|
|
final wordSearchResult = WordSearchResult(
|
|
entryId: 0,
|
|
score: 0,
|
|
isCommon: false,
|
|
jlptLevel: JlptLevel.none,
|
|
kanjiInfo: {},
|
|
readingInfo: {},
|
|
japanese: [WordSearchRuby(base: '仮名')],
|
|
senses: [],
|
|
sources: WordSearchSources.empty(),
|
|
);
|
|
|
|
wordSearchResult.inferMatchSpans('仮');
|
|
|
|
expect(wordSearchResult.matchSpans, [
|
|
WordSearchMatchSpan(
|
|
spanType: WordSearchMatchSpanType.kanji,
|
|
start: 0,
|
|
end: 1,
|
|
index: 0,
|
|
),
|
|
]);
|
|
});
|
|
|
|
test('Infer match in middle of word', () {
|
|
final wordSearchResult = WordSearchResult(
|
|
entryId: 0,
|
|
score: 0,
|
|
isCommon: false,
|
|
jlptLevel: JlptLevel.none,
|
|
kanjiInfo: {},
|
|
readingInfo: {},
|
|
japanese: [WordSearchRuby(base: 'ありがとう')],
|
|
senses: [],
|
|
sources: WordSearchSources.empty(),
|
|
);
|
|
|
|
wordSearchResult.inferMatchSpans('りがと');
|
|
|
|
expect(wordSearchResult.matchSpans, [
|
|
WordSearchMatchSpan(
|
|
spanType: WordSearchMatchSpanType.kanji,
|
|
start: 1,
|
|
end: 4,
|
|
index: 0,
|
|
),
|
|
]);
|
|
});
|
|
|
|
test('Infer match in furigana', () {
|
|
final wordSearchResult = WordSearchResult(
|
|
entryId: 0,
|
|
score: 0,
|
|
isCommon: false,
|
|
jlptLevel: JlptLevel.none,
|
|
kanjiInfo: {},
|
|
readingInfo: {},
|
|
japanese: [WordSearchRuby(base: '仮名', furigana: 'かな')],
|
|
senses: [],
|
|
sources: WordSearchSources.empty(),
|
|
);
|
|
|
|
wordSearchResult.inferMatchSpans('かな');
|
|
|
|
expect(wordSearchResult.matchSpans, [
|
|
WordSearchMatchSpan(
|
|
spanType: WordSearchMatchSpanType.kana,
|
|
start: 0,
|
|
end: 2,
|
|
index: 0,
|
|
),
|
|
]);
|
|
});
|
|
|
|
test('Infer match in sense', () {
|
|
final wordSearchResult = WordSearchResult(
|
|
entryId: 0,
|
|
score: 0,
|
|
isCommon: false,
|
|
jlptLevel: JlptLevel.none,
|
|
kanjiInfo: {},
|
|
readingInfo: {},
|
|
japanese: [WordSearchRuby(base: '仮名')],
|
|
senses: [
|
|
WordSearchSense(
|
|
antonyms: [],
|
|
dialects: [],
|
|
englishDefinitions: ['kana'],
|
|
fields: [],
|
|
info: [],
|
|
languageSource: [],
|
|
misc: [],
|
|
partsOfSpeech: [],
|
|
restrictedToKanji: [],
|
|
restrictedToReading: [],
|
|
seeAlso: [],
|
|
),
|
|
],
|
|
sources: WordSearchSources.empty(),
|
|
);
|
|
|
|
wordSearchResult.inferMatchSpans('kana');
|
|
|
|
expect(wordSearchResult.matchSpans, [
|
|
WordSearchMatchSpan(
|
|
spanType: WordSearchMatchSpanType.sense,
|
|
start: 0,
|
|
end: 4,
|
|
index: 0,
|
|
),
|
|
]);
|
|
});
|
|
|
|
test('Infer multiple matches', () {
|
|
final wordSearchResult = WordSearchResult(
|
|
entryId: 0,
|
|
score: 0,
|
|
isCommon: false,
|
|
jlptLevel: JlptLevel.none,
|
|
kanjiInfo: {},
|
|
readingInfo: {},
|
|
japanese: [WordSearchRuby(base: '仮名', furigana: 'かな')],
|
|
senses: [
|
|
WordSearchSense(
|
|
antonyms: [],
|
|
dialects: [],
|
|
englishDefinitions: ['kana', 'the kana'],
|
|
fields: [],
|
|
info: [],
|
|
languageSource: [],
|
|
misc: [],
|
|
partsOfSpeech: [],
|
|
restrictedToKanji: [],
|
|
restrictedToReading: [],
|
|
seeAlso: [],
|
|
),
|
|
],
|
|
sources: WordSearchSources.empty(),
|
|
);
|
|
|
|
wordSearchResult.inferMatchSpans('kana');
|
|
|
|
expect(wordSearchResult.matchSpans, [
|
|
WordSearchMatchSpan(
|
|
spanType: WordSearchMatchSpanType.sense,
|
|
start: 0,
|
|
end: 4,
|
|
index: 0,
|
|
),
|
|
WordSearchMatchSpan(
|
|
spanType: WordSearchMatchSpanType.sense,
|
|
start: 4,
|
|
end: 8,
|
|
index: 0,
|
|
subIndex: 1,
|
|
),
|
|
]);
|
|
});
|
|
|
|
test('Infer match with no matches', () {
|
|
final wordSearchResult = WordSearchResult(
|
|
entryId: 0,
|
|
score: 0,
|
|
isCommon: false,
|
|
jlptLevel: JlptLevel.none,
|
|
kanjiInfo: {},
|
|
readingInfo: {},
|
|
japanese: [WordSearchRuby(base: '仮名', furigana: 'かな')],
|
|
senses: [
|
|
WordSearchSense(
|
|
antonyms: [],
|
|
dialects: [],
|
|
englishDefinitions: ['kana'],
|
|
fields: [],
|
|
info: [],
|
|
languageSource: [],
|
|
misc: [],
|
|
partsOfSpeech: [],
|
|
restrictedToKanji: [],
|
|
restrictedToReading: [],
|
|
seeAlso: [],
|
|
),
|
|
],
|
|
sources: WordSearchSources.empty(),
|
|
);
|
|
|
|
wordSearchResult.inferMatchSpans('xyz');
|
|
|
|
expect(wordSearchResult.matchSpans, isEmpty);
|
|
});
|
|
|
|
test('Infer multiple matches of same substring', () {
|
|
final wordSearchResult = WordSearchResult(
|
|
entryId: 0,
|
|
score: 0,
|
|
isCommon: false,
|
|
jlptLevel: JlptLevel.none,
|
|
kanjiInfo: {},
|
|
readingInfo: {},
|
|
japanese: [WordSearchRuby(base: 'ああ')],
|
|
senses: [],
|
|
sources: WordSearchSources.empty(),
|
|
);
|
|
|
|
wordSearchResult.inferMatchSpans('あ');
|
|
|
|
expect(wordSearchResult.matchSpans, [
|
|
WordSearchMatchSpan(
|
|
spanType: WordSearchMatchSpanType.kanji,
|
|
start: 0,
|
|
end: 1,
|
|
index: 0,
|
|
),
|
|
WordSearchMatchSpan(
|
|
spanType: WordSearchMatchSpanType.kanji,
|
|
start: 1,
|
|
end: 2,
|
|
index: 0,
|
|
),
|
|
]);
|
|
});
|
|
}
|