normalization/hangul_wbtest.mbt1///|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
///|
test "hangul syllable detection" {
// 가 (U+AC00) is the first Hangul syllable
assert_true(is_hangul_syllable('\u{AC00}'))
// 힣 (U+D7A3) is the last Hangul syllable
assert_true(is_hangul_syllable('\u{D7A3}'))
// ASCII is not a Hangul syllable
assert_false(is_hangul_syllable('A'))
// Just before Hangul block
assert_false(is_hangul_syllable('\u{ABFF}'))
// Just after Hangul block
assert_false(is_hangul_syllable('\u{D7A4}'))
}
///|
test "hangul jamo detection" {
// Leading consonant jamo (L)
assert_true(is_hangul_l('\u{1100}')) // ᄀ
assert_true(is_hangul_l('\u{1112}')) // ᄒ (last L)
assert_false(is_hangul_l('\u{1113}')) // Beyond L range
// Vowel jamo (V)
assert_true(is_hangul_v('\u{1161}')) // ᅡ
assert_true(is_hangul_v('\u{1175}')) // ᅵ (last V)
assert_false(is_hangul_v('\u{1176}')) // Beyond V range
// Trailing consonant jamo (T)
assert_false(is_hangul_t('\u{11A7}')) // T_BASE itself is not valid
assert_true(is_hangul_t('\u{11A8}')) // ᆨ (first T)
assert_true(is_hangul_t('\u{11C2}')) // ᇂ (last T)
}
///|
test "hangul LV syllable detection" {
// 가 (U+AC00) is LV (no trailing)
assert_true(is_hangul_lv('\u{AC00}'))
// 각 (U+AC01) is LVT (has trailing ᆨ)
assert_false(is_hangul_lv('\u{AC01}'))
// 나 (U+B098) is LV
assert_true(is_hangul_lv('\u{B098}'))
}
///|
test "hangul decomposition LV" {
// 가 (U+AC00) = ᄀ (U+1100) + ᅡ (U+1161)
let result = nfd("\u{AC00}").to_array()
@debug.debug_inspect(result, content="['ᄀ', 'ᅡ']")
}
///|
test "hangul decomposition LVT" {
// 각 (U+AC01) = ᄀ (U+1100) + ᅡ (U+1161) + ᆨ (U+11A8)
let result = nfd("\u{AC01}").to_array()
@debug.debug_inspect(result, content="['ᄀ', 'ᅡ', 'ᆨ']")
}
///|
test "hangul decomposition various" {
// 한 (U+D55C) = ᄒ (U+1112) + ᅡ (U+1161) + ᆫ (U+11AB)
let result = nfd("\u{D55C}").to_array()
@debug.debug_inspect(result, content="['ᄒ', 'ᅡ', 'ᆫ']")
}
///|
test "hangul composition L+V" {
// ᄀ + ᅡ -> 가
let result = try_compose_hangul('\u{1100}', '\u{1161}')
@debug.debug_inspect(result, content="Some('가')")
}
///|
test "hangul composition LV+T" {
// 가 + ᆨ -> 각
let result = try_compose_hangul('\u{AC00}', '\u{11A8}')
@debug.debug_inspect(result, content="Some('각')")
}
///|
test "hangul composition invalid" {
// L + T should not compose
let result = try_compose_hangul('\u{1100}', '\u{11A8}')
@debug.debug_inspect(result, content="None")
// V + V should not compose
let result2 = try_compose_hangul('\u{1161}', '\u{1162}')
@debug.debug_inspect(result2, content="None")
// ASCII should not compose
let result3 = try_compose_hangul('A', 'B')
@debug.debug_inspect(result3, content="None")
}
///|
test "hangul roundtrip" {
// Decompose and recompose should give same result
let original = '\u{AC01}' // 각
let decomposed = nfd(original.to_string()).to_array()
// Compose L + V first
let lv = try_compose_hangul(decomposed[0], decomposed[1])
guard lv is Some(lv_val) else { fail("L+V should compose") }
// Then compose LV + T
let lvt = try_compose_hangul(lv_val, decomposed[2])
@debug.debug_inspect(lvt, content="Some('각')")
}