@@ -383,6 +383,95 @@ void main() {
383383 });
384384 });
385385
386+ group ('analyze' , () {
387+ test ('should analyze multi-language text correctly' , () {
388+ const input = '你好 Hello 안녕' ;
389+ final result = TextRomanizer .analyze (input);
390+
391+ // Expect: [Word(你好), Sep( ), Word(Hello), Sep( ), Word(안녕)]
392+ expect (result, hasLength (5 ));
393+
394+ // 1. Chinese/Japanese word
395+ expect (result[0 ].rawText, equals ('你好' ));
396+ // Note: Language detection for short strings like '你好' might be 'chinese' or 'japanese'
397+ expect (result[0 ].language, isIn (['chinese' , 'japanese' ]));
398+ expect (result[0 ].romanizedText, isNotEmpty);
399+
400+ // 2. Separator (Space)
401+ expect (result[1 ].rawText, equals (' ' ));
402+ expect (
403+ result[1 ].language,
404+ isEmpty,
405+ ); // Separators have empty string language
406+ expect (result[1 ].romanizedText, equals (' ' ));
407+
408+ // 3. English word (Unsupported/Empty)
409+ expect (result[2 ].rawText, equals ('Hello' ));
410+ expect (
411+ result[2 ].language,
412+ equals ('empty' ),
413+ ); // detectLanguage returns 'empty' for unsupported
414+ expect (result[2 ].romanizedText, equals ('Hello' ));
415+
416+ // 4. Separator (Space)
417+ expect (result[3 ].rawText, equals (' ' ));
418+
419+ // 5. Korean word
420+ expect (result[4 ].rawText, equals ('안녕' ));
421+ expect (result[4 ].language, equals ('korean' ));
422+ expect (result[4 ].romanizedText, isNotEmpty);
423+ });
424+
425+ test ('should preserve punctuation and sentence structure' , () {
426+ const input = 'Hello, World!' ;
427+ final result = TextRomanizer .analyze (input);
428+
429+ final reconstructed = result.map ((r) => r.rawText).join ();
430+ expect (reconstructed, equals (input));
431+ });
432+
433+ test ('should handle repeated words consistently (caching)' , () {
434+ const input = '안녕 & 안녕' ;
435+ final result = TextRomanizer .analyze (input);
436+
437+ final firstWord = result.first;
438+ final lastWord = result.last;
439+
440+ expect (firstWord.rawText, equals ('안녕' ));
441+ expect (lastWord.rawText, equals ('안녕' ));
442+
443+ // The romanization should be identical
444+ expect (firstWord.romanizedText, equals (lastWord.romanizedText));
445+ expect (firstWord.language, equals (lastWord.language));
446+ });
447+
448+ test ('should return empty list for empty input' , () {
449+ final result = TextRomanizer .analyze ('' );
450+ expect (result, isEmpty);
451+ });
452+
453+ test ('should treat whitespace-only input as separators' , () {
454+ const input = ' ' ;
455+ final result = TextRomanizer .analyze (input);
456+
457+ expect (result, isNotEmpty);
458+ expect (result.first.rawText, equals (input));
459+ expect (result.first.language, isEmpty); // Separator
460+ });
461+
462+ test ('should identify specific languages correctly in a sentence' , () {
463+ // Korean + Punctuation + Japanese
464+ const input = '안녕하세요. こんにちは。' ;
465+ final result = TextRomanizer .analyze (input);
466+
467+ final koreanPart = result.firstWhere ((r) => r.rawText == '안녕하세요' );
468+ expect (koreanPart.language, equals ('korean' ));
469+
470+ final japanesePart = result.firstWhere ((r) => r.rawText == 'こんにちは' );
471+ expect (japanesePart.language, equals ('japanese' ));
472+ });
473+ });
474+
386475 group ('supportedLanguages' , () {
387476 test ('should return list of supported languages' , () {
388477 final languages = TextRomanizer .supportedLanguages;
0 commit comments