unicode

Branch: main

Switch branches or tags

Branch: main
Go to file t

413 files indexed

History
Code

normalization/hangul_wbtest.mbt
1///|2test "hangul syllable detection" {3  // 가 (U+AC00) is the first Hangul syllable4  assert_true(is_hangul_syllable('\u{AC00}'))5  // 힣 (U+D7A3) is the last Hangul syllable6  assert_true(is_hangul_syllable('\u{D7A3}'))7  // ASCII is not a Hangul syllable8  assert_false(is_hangul_syllable('A'))9  // Just before Hangul block10  assert_false(is_hangul_syllable('\u{ABFF}'))11  // Just after Hangul block12  assert_false(is_hangul_syllable('\u{D7A4}'))13}1415///|16test "hangul jamo detection" {17  // Leading consonant jamo (L)18  assert_true(is_hangul_l('\u{1100}')) // ᄀ19  assert_true(is_hangul_l('\u{1112}')) // ᄒ (last L)20  assert_false(is_hangul_l('\u{1113}')) // Beyond L range21  // Vowel jamo (V)22  assert_true(is_hangul_v('\u{1161}')) // ᅡ23  assert_true(is_hangul_v('\u{1175}')) // ᅵ (last V)24  assert_false(is_hangul_v('\u{1176}')) // Beyond V range25  // Trailing consonant jamo (T)26  assert_false(is_hangul_t('\u{11A7}')) // T_BASE itself is not valid27  assert_true(is_hangul_t('\u{11A8}')) // ᆨ (first T)28  assert_true(is_hangul_t('\u{11C2}')) // ᇂ (last T)29}3031///|32test "hangul LV syllable detection" {33  // 가 (U+AC00) is LV (no trailing)34  assert_true(is_hangul_lv('\u{AC00}'))35  // 각 (U+AC01) is LVT (has trailing ᆨ)36  assert_false(is_hangul_lv('\u{AC01}'))37  // 나 (U+B098) is LV38  assert_true(is_hangul_lv('\u{B098}'))39}4041///|42test "hangul decomposition LV" {43  // 가 (U+AC00) = ᄀ (U+1100) + ᅡ (U+1161)44  let result = nfd("\u{AC00}").to_array()45  @debug.debug_inspect(result, content="['ᄀ', 'ᅡ']")46}4748///|49test "hangul decomposition LVT" {50  // 각 (U+AC01) = ᄀ (U+1100) + ᅡ (U+1161) + ᆨ (U+11A8)51  let result = nfd("\u{AC01}").to_array()52  @debug.debug_inspect(result, content="['ᄀ', 'ᅡ', 'ᆨ']")53}5455///|56test "hangul decomposition various" {57  // 한 (U+D55C) = ᄒ (U+1112) + ᅡ (U+1161) + ᆫ (U+11AB)58  let result = nfd("\u{D55C}").to_array()59  @debug.debug_inspect(result, content="['ᄒ', 'ᅡ', 'ᆫ']")60}6162///|63test "hangul composition L+V" {64  // ᄀ + ᅡ -> 가65  let result = try_compose_hangul('\u{1100}', '\u{1161}')66  @debug.debug_inspect(result, content="Some('가')")67}6869///|70test "hangul composition LV+T" {71  // 가 + ᆨ -> 각72  let result = try_compose_hangul('\u{AC00}', '\u{11A8}')73  @debug.debug_inspect(result, content="Some('각')")74}7576///|77test "hangul composition invalid" {78  // L + T should not compose79  let result = try_compose_hangul('\u{1100}', '\u{11A8}')80  @debug.debug_inspect(result, content="None")81  // V + V should not compose82  let result2 = try_compose_hangul('\u{1161}', '\u{1162}')83  @debug.debug_inspect(result2, content="None")84  // ASCII should not compose85  let result3 = try_compose_hangul('A', 'B')86  @debug.debug_inspect(result3, content="None")87}8889///|90test "hangul roundtrip" {91  // Decompose and recompose should give same result92  let original = '\u{AC01}' // 각93  let decomposed = nfd(original.to_string()).to_array()94  // Compose L + V first95  let lv = try_compose_hangul(decomposed[0], decomposed[1])96  guard lv is Some(lv_val) else { fail("L+V should compose") }97  // Then compose LV + T98  let lvt = try_compose_hangul(lv_val, decomposed[2])99  @debug.debug_inspect(lvt, content="Some('각')")100}101