util/romaji_transliteration: add functions to generate transliteration spans
All checks were successful
Build and test / evals (push) Successful in 18m58s
All checks were successful
Build and test / evals (push) Successful in 18m58s
This commit is contained in:
@@ -37,6 +37,35 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('Romaji -> Hiragana Spans', () {
|
||||
void Function() expectSpans(String input, List<String> expected) => () {
|
||||
final result = transliterateLatinToHiraganaSpan(input);
|
||||
final trans = transliterateLatinToHiragana(input);
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
expect(
|
||||
trans.substring(
|
||||
result[i].$2,
|
||||
i == result.length - 1 ? trans.length : result[i + 1].$2,
|
||||
),
|
||||
expected[i],
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
test('Basic test', expectSpans('katamari', ['か', 'た', 'ま', 'り']));
|
||||
test(
|
||||
'Basic test with diacritics',
|
||||
expectSpans('gadamari', ['が', 'だ', 'ま', 'り']),
|
||||
);
|
||||
test('wi and we', expectSpans('wiwe', ['うぃ', 'うぇ']));
|
||||
test('nb = mb', expectSpans('kanpai', ['か', 'ん', 'ぱ', 'い']));
|
||||
test('nb = mb', expectSpans('kampai', ['か', 'ん', 'ぱ', 'い']));
|
||||
test('Double n', expectSpans('konnichiha', ['こ', 'ん', 'に', 'ち', 'は']));
|
||||
|
||||
// TODO: fix the implementation
|
||||
// test('Double consonant', expectSpans('kappa', ['か', 'っぱ']));
|
||||
});
|
||||
|
||||
group('Hiragana -> Romaji', () {
|
||||
test('Basic test', () {
|
||||
final result = transliterateHiraganaToLatin('かたまり');
|
||||
@@ -63,4 +92,31 @@ void main() {
|
||||
expect(result, 'kappa');
|
||||
});
|
||||
});
|
||||
|
||||
group('Hiragana -> Romaji Spans', () {
|
||||
void Function() expectSpans(String input, List<String> expected) => () {
|
||||
final result = transliterateHiraganaToLatinSpan(input);
|
||||
final trans = transliterateHiraganaToLatin(input);
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
expect(
|
||||
trans.substring(
|
||||
result[i].$2,
|
||||
i == result.length - 1 ? trans.length : result[i + 1].$2,
|
||||
),
|
||||
expected[i],
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
test('Basic test', expectSpans('かたまり', ['ka', 'ta', 'ma', 'ri']));
|
||||
test(
|
||||
'Basic test with diacritics',
|
||||
expectSpans('がだまり', ['ga', 'da', 'ma', 'ri']),
|
||||
);
|
||||
test('wi and we', expectSpans('うぃうぇ', ['whi', 'whe']));
|
||||
test('Double n', expectSpans('こんにちは', ['ko', 'n', 'ni', 'chi', 'ha']));
|
||||
|
||||
// TODO: fix the implementation
|
||||
// test('Double consonant', expectSpans('かっぱ', ['ka', 'ppa']));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user