| 1 | |
| 2 | import unittest |
| 3 | |
| 4 | from src.text import (tr_lower, tr_upper, strip_invisibles, |
| 5 | join_hyphenation, normalize, fold_for_match) |
| 6 | |
| 7 | |
| 8 | class TrCaseTests(unittest.TestCase): |
| 9 | def test_lower_dotted_I(self): |
| 10 | self.assertEqual(tr_lower("KİTAP"), "kitap") |
| 11 | self.assertEqual(tr_lower("İSTANBUL"), "istanbul") |
| 12 | |
| 13 | def test_lower_dotless_I(self): |
| 14 | self.assertEqual(tr_lower("IŞIK"), "ışık") |
| 15 | self.assertEqual(tr_lower("ISI"), "ısı") |
| 16 | |
| 17 | def test_upper(self): |
| 18 | self.assertEqual(tr_upper("iğne"), "İĞNE") |
| 19 | self.assertEqual(tr_upper("ışık"), "IŞIK") |
| 20 | |
| 21 | |
| 22 | class InvisibleTests(unittest.TestCase): |
| 23 | def test_strip_bom_zero_width(self): |
| 24 | self.assertEqual(strip_invisibles("gen aktarımı"), "gen aktarımı") |
| 25 | self.assertEqual(strip_invisibles("ab"), "ab") |
| 26 | |
| 27 | |
| 28 | class HyphenationTests(unittest.TestCase): |
| 29 | def test_soft_hyphen_join(self): |
| 30 | |
| 31 | self.assertEqual(join_hyphenation("mü\xadhendisliği"), "mühendisliği") |
| 32 | |
| 33 | def test_soft_hyphen_with_newline(self): |
| 34 | self.assertEqual(join_hyphenation("çalış\xad\nmaları"), "çalışmaları") |
| 35 | |
| 36 | def test_linebreak_hyphen_join(self): |
| 37 | self.assertEqual(join_hyphenation("düzen-\nleme"), "düzenleme") |
| 38 | |
| 39 | def test_midline_hyphen_preserved(self): |
| 40 | |
| 41 | self.assertEqual(join_hyphenation("neden-sonuç ilişkisi"), "neden-sonuç ilişkisi") |
| 42 | |
| 43 | |
| 44 | class NormalizeTests(unittest.TestCase): |
| 45 | def test_full_pipeline(self): |
| 46 | raw = "Genetik mü\xadhendisliği DNA'yı\n\n\n\ndeğiştirir." |
| 47 | out = normalize(raw) |
| 48 | self.assertIn("mühendisliği", out) |
| 49 | self.assertNotIn("", out) |
| 50 | self.assertNotIn("\xad", out) |
| 51 | self.assertNotIn(" ", out) |
| 52 | self.assertNotIn("\n\n\n", out) |
| 53 | |
| 54 | def test_preserves_scientific_symbols(self): |
| 55 | |
| 56 | for token in ("CO₂", "H₂O", "3ʹ", "5ʹ", "β-galaktozidaz"): |
| 57 | self.assertIn(token, normalize(f"metin {token} devam")) |
| 58 | |
| 59 | def test_empty(self): |
| 60 | self.assertEqual(normalize(""), "") |
| 61 | |
| 62 | |
| 63 | class FoldTests(unittest.TestCase): |
| 64 | def test_fold_lowercases_keeps_accents(self): |
| 65 | |
| 66 | self.assertEqual(fold_for_match("DNA Polimeraz"), "dna polimeraz") |
| 67 | self.assertEqual(fold_for_match("Çekirdek"), "çekirdek") |
| 68 | |
| 69 | |
| 70 | if __name__ == "__main__": |
| 71 | unittest.main() |