2 Commits

Author SHA1 Message Date
8827893101 search: prefer Iterable over List in some public APIs
All checks were successful
Build and test / build (push) Successful in 7m51s
2026-04-14 17:55:40 +09:00
28c4403e2d test/romaji_transliteration: add tests for iteration marks and yori ligature
All checks were successful
Build and test / build (push) Successful in 6m56s
2026-04-13 22:06:03 +09:00
5 changed files with 37 additions and 10 deletions

View File

@@ -18,12 +18,12 @@ extension JaDBConnection on DatabaseExecutor {
searchKanjiWithDbConnection(this, kanji);
/// Search for a kanji in the database.
Future<Map<String, KanjiSearchResult>> jadbGetManyKanji(Set<String> kanji) =>
Future<Map<String, KanjiSearchResult>> jadbGetManyKanji(Iterable<String> kanji) =>
searchManyKanjiWithDbConnection(this, kanji);
/// Filter a list of characters, and return the ones that are listed in the kanji dictionary.
Future<List<String>> filterKanji(
List<String> kanji, {
Iterable<String> kanji, {
bool deduplicate = false,
}) => filterKanjiWithDbConnection(this, kanji, deduplicate);

View File

@@ -6,7 +6,7 @@ import 'package:sqflite_common/sqflite.dart';
/// If [deduplicate] is true, the returned list will deduplicate the input kanji list before returning the filtered results.
Future<List<String>> filterKanjiWithDbConnection(
DatabaseExecutor connection,
List<String> kanji,
Iterable<String> kanji,
bool deduplicate,
) async {
final Set<String> filteredKanji = await connection
@@ -14,7 +14,7 @@ Future<List<String>> filterKanjiWithDbConnection(
SELECT "literal"
FROM "${KANJIDICTableNames.character}"
WHERE "literal" IN (${kanji.map((_) => '?').join(',')})
''', kanji)
''', kanji.toList())
.then((value) => value.map((e) => e['literal'] as String).toSet());
if (deduplicate) {

View File

@@ -274,7 +274,7 @@ Future<KanjiSearchResult?> searchKanjiWithDbConnection(
/// Searches for multiple kanji at once, returning a map of kanji to their search results.
Future<Map<String, KanjiSearchResult>> searchManyKanjiWithDbConnection(
DatabaseExecutor connection,
Set<String> kanji,
Iterable<String> kanji,
) async {
if (kanji.isEmpty) {
return {};

View File

@@ -229,7 +229,7 @@ CREATE TABLE "JMdict_SenseGlossary" (
PRIMARY KEY ("senseId", "phrase")
) WITHOUT ROWID;
-- CREATE INDEX "JMdict_SenseGlossary_byPhrase" ON JMdict_SenseGlossary("phrase");
CREATE INDEX "JMdict_SenseGlossary_byPhrase" ON JMdict_SenseGlossary("phrase");
CREATE TABLE "JMdict_SenseGlossaryType" (
"senseId" INTEGER NOT NULL REFERENCES "JMdict_Sense"("senseId"),

View File

@@ -8,7 +8,7 @@ void main() {
expect(result, 'かたまり');
});
test('Basic test with diacritics', () {
test('Basic test with dakuten', () {
final result = transliterateLatinToHiragana('gadamari');
expect(result, 'がだまり');
});
@@ -54,7 +54,7 @@ void main() {
test('Basic test', expectSpans('katamari', ['', '', '', '']));
test(
'Basic test with diacritics',
'Basic test with dakuten',
expectSpans('gadamari', ['', '', '', '']),
);
test('wi and we', expectSpans('wiwe', ['うぃ', 'うぇ']));
@@ -72,7 +72,7 @@ void main() {
expect(result, 'katamari');
});
test('Basic test with diacritics', () {
test('Basic test with dakuten', () {
final result = transliterateHiraganaToLatin('がだまり');
expect(result, 'gadamari');
});
@@ -91,6 +91,21 @@ void main() {
final result = transliterateHiraganaToLatin('かっぱ');
expect(result, 'kappa');
});
test('Iteration mark', () {
final result = transliterateHiraganaToLatin('さゝき');
expect(result, 'sasaki');
}, skip: 'Not yet implemented');
test('Iteration mark with dakuten', () {
final result = transliterateHiraganaToLatin('あひゞき');
expect(result, 'ahibiki');
}, skip: 'Not yet implemented');
test('Yori', () {
final result = transliterateHiraganaToLatin('');
expect(result, 'yori');
}, skip: 'Not yet implemented');
});
group('Hiragana -> Romaji Spans', () {
@@ -110,7 +125,7 @@ void main() {
test('Basic test', expectSpans('かたまり', ['ka', 'ta', 'ma', 'ri']));
test(
'Basic test with diacritics',
'Basic test with dakuten',
expectSpans('がだまり', ['ga', 'da', 'ma', 'ri']),
);
test('wi and we', expectSpans('うぃうぇ', ['whi', 'whe']));
@@ -118,5 +133,17 @@ void main() {
// TODO: fix the implementation
// test('Double consonant', expectSpans('かっぱ', ['ka', 'ppa']));
test(
'Iteration mark',
expectSpans('さゝき', ['sa', 'sa', 'ki']),
skip: 'Not yet implemented',
);
test(
'Iteration mark with dakuten',
expectSpans('あひゞき', ['a', 'hi', 'bi', 'ki']),
skip: 'Not yet implemented',
);
test('Yori', expectSpans('', ['yori']), skip: 'Not yet implemented');
});
}