diff --git a/tests/tests/test_normalization.py b/tests/tests/test_normalization.py index a97ec6c5..f6af8d9a 100644 --- a/tests/tests/test_normalization.py +++ b/tests/tests/test_normalization.py @@ -5,6 +5,7 @@ import sys import malaya +import malaya.normalizer.rules import logging logging.basicConfig(level=logging.DEBUG) @@ -23,3 +24,30 @@ def test_normalization(): normalizer = malaya.normalize.normalizer(corrector) string = 'boleh dtg 8pagi esok tak atau minggu depan? 2 oktober 2019 2pm, tlong bayar rm 3.2k sekali tau' normalizer.normalize(string) + + +def test_passport_normalization(): + """ + Test that passport numbers are normalized digit-by-digit, + not expanded as cardinal numbers. Regression test for #253. + """ + normalizer = malaya.normalizer.rules.load() + + # Passport numbers should be spelled out character-by-character + test_cases = [ + 'your passport is EL9568719', + 'ini adalah passport saya A20964577', + ] + + for s in test_cases: + result = normalizer.normalize(s) + normalized = result['normalize'] + + # Should NOT contain cardinal expansions like "million", "thousand", "juta", "ribu" + cardinal_words = ['million', 'thousand', 'hundred', 'juta', 'ribu', 'ratus'] + for word in cardinal_words: + assert word not in normalized.lower(), ( + f'Passport number in "{s}" was expanded as cardinal number ' + f'(found "{word}" in "{normalized}"). ' + f'Expected digit-by-digit expansion.' + )