@@ -7,29 +7,29 @@ void main() {
77 });
88
99 group ('ChineseRomanizer' , () {
10- const romanizer = ChineseRomanizer ();
11-
1210 test ('should have correct language name' , () {
11+ const romanizer = ChineseRomanizer ();
1312 expect (romanizer.language, equals ('chinese' ));
1413 });
1514
1615 group ('isValid' , () {
16+ const romanizer = ChineseRomanizer ();
17+
1718 test ('should return true for Simplified Chinese text' , () {
1819 expect (romanizer.isValid ('你好' ), isTrue);
1920 expect (romanizer.isValid ('中国' ), isTrue);
2021 expect (romanizer.isValid ('北京' ), isTrue);
2122 });
2223
2324 test ('should return true for Traditional Chinese text' , () {
24- expect (romanizer.isValid ('你好 ' ), isTrue);
25- expect (romanizer.isValid ('臺灣 ' ), isTrue);
25+ expect (romanizer.isValid ('臺灣 ' ), isTrue); // Taiwan
26+ expect (romanizer.isValid ('繁體 ' ), isTrue); // Traditional
2627 });
2728
2829 test ('should return false for non-Chinese text' , () {
2930 expect (romanizer.isValid ('Hello' ), isFalse);
30- expect (romanizer.isValid ('こんにちは' ), isFalse);
31- expect (romanizer.isValid ('안녕하세요' ), isFalse);
32- expect (romanizer.isValid ('Привет' ), isFalse);
31+ expect (romanizer.isValid ('こんにちは' ), isFalse); // Japanese
32+ expect (romanizer.isValid ('안녕하세요' ), isFalse); // Korean
3333 expect (romanizer.isValid ('123' ), isFalse);
3434 });
3535
@@ -38,57 +38,84 @@ void main() {
3838 expect (romanizer.isValid ('Hello 你好' ), isTrue);
3939 });
4040
41- test ('should return false for empty string ' , () {
41+ test ('should return false for empty or whitespace-only strings ' , () {
4242 expect (romanizer.isValid ('' ), isFalse);
43- });
44-
45- test ('should return false for whitespace-only string' , () {
4643 expect (romanizer.isValid (' ' ), isFalse);
4744 });
4845 });
4946
5047 group ('romanize' , () {
51- test ('should romanize Chinese text to Pinyin' , () {
52- final result = romanizer.romanize ('你好' );
53- expect (result, isNotEmpty);
54- expect (result, isA <String >());
55- // Should contain pinyin syllables separated by spaces
56- expect (result.split (' ' ).length, greaterThanOrEqualTo (1 ));
48+ group ('ToneAnnotation.mark (default)' , () {
49+ const romanizer = ChineseRomanizer ();
50+
51+ test ('should romanize with tone marks' , () {
52+ // Ni Hao
53+ expect (romanizer.romanize ('你好' ), equals ('nǐ hǎo' ));
54+ // Shi Jie (World)
55+ expect (romanizer.romanize ('世界' ), equals ('shì jiè' ));
56+ });
57+
58+ test ('should handle Traditional Chinese' , () {
59+ // Taiwan -> Tai Wan
60+ expect (romanizer.romanize ('臺灣' ), equals ('tái wān' ));
61+ });
5762 });
5863
59- test ('should handle longer Chinese text' , () {
60- final result = romanizer.romanize ('你好世界' );
61- expect (result, isNotEmpty);
62- expect (result, isA <String >());
64+ group ('ToneAnnotation.number' , () {
65+ const romanizer = ChineseRomanizer (
66+ toneAnnotation: ToneAnnotation .number,
67+ );
68+
69+ test ('should romanize with tone numbers' , () {
70+ expect (romanizer.romanize ('你好' ), equals ('ni3 hao3' ));
71+ expect (romanizer.romanize ('世界' ), equals ('shi4 jie4' ));
72+ });
73+
74+ test ('should handle neutral tones if applicable' , () {
75+ // "ma" (question particle) is often neutral (5 or no number),
76+ // dependent on pinyin package dictionary.
77+ // We test a standard char 'ma' 吗 -> ma
78+ // Using a known neutral tone char might be tricky depending on package version,
79+ // so we rely on standard numbered output.
80+ expect (romanizer.romanize ('吗' ), anyOf (contains ('ma' ), contains ('5' )));
81+ });
6382 });
6483
65- test ('should handle mixed content' , () {
66- final result = romanizer.romanize ('你好 Hello' );
67- expect (result, isNotEmpty);
68- });
84+ group ('ToneAnnotation.none' , () {
85+ const romanizer = ChineseRomanizer (toneAnnotation: ToneAnnotation .none);
6986
70- test ('should handle empty string' , () {
71- final result = romanizer.romanize ('' );
72- expect (result, isEmpty);
87+ test ('should romanize without tones' , () {
88+ expect (romanizer.romanize ('你好' ), equals ('ni hao' ));
89+ expect (romanizer.romanize ('世界' ), equals ('shi jie' ));
90+ });
7391 });
7492
75- test ('should preserve non-Chinese characters' , () {
76- final result = romanizer.romanize ('你好 Hello 123' );
77- expect (result, contains ('Hello' ));
78- expect (result, contains ('123' ));
79- });
93+ group ('Edge cases and Mixed content' , () {
94+ const romanizer = ChineseRomanizer ();
8095
81- test ('should handle common Chinese phrases' , () {
82- final result1 = romanizer.romanize ('谢谢' );
83- final result2 = romanizer.romanize ('再见' );
84- expect (result1, isNotEmpty);
85- expect (result2, isNotEmpty);
86- });
96+ test ('should handle multiline text' , () {
97+ const input = '你好\n 世界' ;
98+ // Implementation processes line by line and uses writeln,
99+ // so we expect a newline after every line.
100+ final result = romanizer.romanize (input);
101+ expect (result, equals ('nǐ hǎo\n shì jiè\n ' ));
102+ });
103+
104+ test ('should preserve non-Chinese characters' , () {
105+ final result = romanizer.romanize ('你好 Hello 123' );
106+
107+ expect (result, contains ('nǐ hǎo' ));
108+ expect (result, contains ('Hello' ));
109+ expect (result, contains ('123' ));
110+ });
111+
112+ test ('should handle empty string' , () {
113+ expect (romanizer.romanize ('' ), isEmpty);
114+ });
87115
88- test ('should handle numbers and punctuation' , () {
89- final result = romanizer.romanize ('你好123!' );
90- expect (result, isNotEmpty);
91- expect (result, contains ('123' ));
116+ test ('should handle whitespace only' , () {
117+ expect (romanizer.romanize (' ' ), isEmpty);
118+ });
92119 });
93120 });
94121 });
0 commit comments