2019-07-10 09:07:04 +02:00
|
|
|
fn test_utf8_char_len() {
|
2020-03-26 17:14:24 +01:00
|
|
|
assert utf8_char_len(`a`) == 1
|
|
|
|
println(utf8_char_len(`a`))
|
|
|
|
s := 'п'
|
|
|
|
assert utf8_char_len(s[0]) == 2
|
2019-07-10 09:07:04 +02:00
|
|
|
}
|
2021-01-01 10:06:09 +01:00
|
|
|
|
|
|
|
fn test_utf8_wide_char() {
|
2021-01-03 23:03:45 +01:00
|
|
|
$if msvc {
|
|
|
|
// TODO: make this test pass msvc too
|
|
|
|
return
|
|
|
|
}
|
2021-01-02 13:55:21 +01:00
|
|
|
r := `✔`
|
2021-01-03 20:29:02 +01:00
|
|
|
s := '✔'
|
|
|
|
println('r: $r')
|
|
|
|
println('s: $s')
|
|
|
|
rstr := r.str()
|
|
|
|
println('rstr: $rstr')
|
2021-01-03 23:03:45 +01:00
|
|
|
assert utf8_char_len(r) == 1
|
|
|
|
assert utf8_char_len(s[0]) == 3
|
2021-01-03 20:29:02 +01:00
|
|
|
assert s == rstr
|
|
|
|
val := rstr.str
|
2021-01-01 10:06:09 +01:00
|
|
|
unsafe {
|
2021-01-03 20:29:02 +01:00
|
|
|
assert val[0].hex() == 'e2'
|
|
|
|
assert val[1].hex() == '9c'
|
|
|
|
assert val[2].hex() == '94'
|
2021-01-01 10:06:09 +01:00
|
|
|
}
|
|
|
|
}
|