|
| 1 | +import 'package:romanize/romanize.dart'; |
| 2 | +import 'package:romanize/src/romanizers/hebrew.dart'; |
| 3 | +import 'package:test/test.dart'; |
| 4 | + |
| 5 | +void main() { |
| 6 | + setUp(() async { |
| 7 | + await TextRomanizer.ensureInitialized(); |
| 8 | + }); |
| 9 | + |
| 10 | + group('HebrewRomanizer', () { |
| 11 | + const romanizer = HebrewRomanizer(); |
| 12 | + |
| 13 | + test('should have correct language name', () { |
| 14 | + expect(romanizer.language, equals('hebrew')); |
| 15 | + }); |
| 16 | + |
| 17 | + group('isValid', () { |
| 18 | + test('should return true for Hebrew text', () { |
| 19 | + expect(romanizer.isValid('שָׁלוֹם'), isTrue); // Shalom |
| 20 | + expect(romanizer.isValid('עִבְרִית'), isTrue); // Ivrit |
| 21 | + expect(romanizer.isValid('אני'), isTrue); // Ani (unpointed) |
| 22 | + }); |
| 23 | + |
| 24 | + test('should return false for non-Hebrew text', () { |
| 25 | + expect(romanizer.isValid('Hello'), isFalse); |
| 26 | + expect(romanizer.isValid('こんにちは'), isFalse); |
| 27 | + expect(romanizer.isValid('مرحبا'), isFalse); // Arabic |
| 28 | + expect(romanizer.isValid('123'), isFalse); |
| 29 | + }); |
| 30 | + |
| 31 | + test('should return true for mixed Hebrew and other text', () { |
| 32 | + expect(romanizer.isValid('שָׁלוֹם Hello'), isTrue); |
| 33 | + expect(romanizer.isValid('Hello שָׁלוֹם'), isTrue); |
| 34 | + }); |
| 35 | + |
| 36 | + test('should return false for empty string', () { |
| 37 | + expect(romanizer.isValid(''), isFalse); |
| 38 | + }); |
| 39 | + |
| 40 | + test('should return false for whitespace-only string', () { |
| 41 | + expect(romanizer.isValid(' '), isFalse); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + group('romanize', () { |
| 46 | + test('should romanize Hebrew text', () { |
| 47 | + // Shalom: Shin, Qamats, Lamed, Holam Male, Final Mem |
| 48 | + final result = romanizer.romanize('שָׁלוֹם'); |
| 49 | + expect(result, isNotEmpty); |
| 50 | + expect(result, isA<String>()); |
| 51 | + expect(result, equals('shālōm')); |
| 52 | + }); |
| 53 | + |
| 54 | + test('should romanize simple unpointed text', () { |
| 55 | + // Ani: Alef, Nun, Yod |
| 56 | + final result = romanizer.romanize('אני'); |
| 57 | + expect(result, equals('ʾny')); |
| 58 | + }); |
| 59 | + |
| 60 | + test('should handle mixed content', () { |
| 61 | + final result = romanizer.romanize('שָׁלוֹם Hello'); |
| 62 | + expect(result, equals('shālōm Hello')); |
| 63 | + }); |
| 64 | + |
| 65 | + test('should handle empty string', () { |
| 66 | + final result = romanizer.romanize(''); |
| 67 | + expect(result, isEmpty); |
| 68 | + expect(result, equals('')); |
| 69 | + }); |
| 70 | + |
| 71 | + test('should preserve non-Hebrew characters', () { |
| 72 | + final result = romanizer.romanize('שָׁלוֹם Hello 123'); |
| 73 | + expect(result, contains('Hello')); |
| 74 | + expect(result, contains('123')); |
| 75 | + expect(result, equals('shālōm Hello 123')); |
| 76 | + }); |
| 77 | + |
| 78 | + test('should handle longer Hebrew text', () { |
| 79 | + // Bereshit bara Elohim (In the beginning God created) |
| 80 | + // בְּרֵאשִׁית בָּרָא אֱלֹהִים |
| 81 | + // Note: Our romanizer is character-based and might be verbose with Alefs/Yods |
| 82 | + const hebrewText = 'בְּרֵאשִׁית בָּרָא אֱלֹהִים'; |
| 83 | + final result = romanizer.romanize(hebrewText); |
| 84 | + expect(result, isNotEmpty); |
| 85 | + |
| 86 | + // Expected derivation based on map: |
| 87 | + // בְּרֵאשִׁית -> b e r ē ʾ sh i y t -> berēʾshiyt |
| 88 | + // בָּרָא -> b ā r ā ʾ -> bārāʾ |
| 89 | + // אֱלֹהִים -> ʾ e l ō h i y m -> ʾelōhiym |
| 90 | + expect(result, equals('berēʾshiyt bārāʾ ʾelōhiym')); |
| 91 | + }); |
| 92 | + }); |
| 93 | + }); |
| 94 | +} |
0 commit comments