2019-07-10 10:07:04 +03:00
|
|
|
|
fn test_utf8_char_len() {
|
2020-03-26 19:14:24 +03:00
|
|
|
|
assert utf8_char_len(`a`) == 1
|
|
|
|
|
println(utf8_char_len(`a`))
|
|
|
|
|
s := 'п'
|
|
|
|
|
assert utf8_char_len(s[0]) == 2
|
2019-07-10 10:07:04 +03:00
|
|
|
|
}
|
2021-01-01 12:06:09 +03:00
|
|
|
|
|
|
|
|
|
fn test_utf8_wide_char() {
|
2021-01-04 01:03:45 +03:00
|
|
|
|
$if msvc {
|
|
|
|
|
// TODO: make this test pass msvc too
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-01-02 15:55:21 +03:00
|
|
|
|
r := `✔`
|
2021-01-03 22:29:02 +03:00
|
|
|
|
s := '✔'
|
2022-11-15 16:53:13 +03:00
|
|
|
|
println('r: ${r}')
|
|
|
|
|
println('s: ${s}')
|
2021-01-03 22:29:02 +03:00
|
|
|
|
rstr := r.str()
|
2022-11-15 16:53:13 +03:00
|
|
|
|
println('rstr: ${rstr}')
|
2021-01-04 01:03:45 +03:00
|
|
|
|
assert utf8_char_len(r) == 1
|
|
|
|
|
assert utf8_char_len(s[0]) == 3
|
2021-01-03 22:29:02 +03:00
|
|
|
|
assert s == rstr
|
|
|
|
|
val := rstr.str
|
2021-01-01 12:06:09 +03:00
|
|
|
|
unsafe {
|
2021-01-03 22:29:02 +03:00
|
|
|
|
assert val[0].hex() == 'e2'
|
|
|
|
|
assert val[1].hex() == '9c'
|
|
|
|
|
assert val[2].hex() == '94'
|
2021-01-01 12:06:09 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-28 21:41:50 +03:00
|
|
|
|
|
|
|
|
|
fn test_to_wide_latin() {
|
|
|
|
|
s := 'abc 123'
|
|
|
|
|
w := s.to_wide()
|
|
|
|
|
unsafe {
|
|
|
|
|
assert w[0] == 97
|
|
|
|
|
assert w[1] == 98
|
|
|
|
|
assert w[2] == 99
|
|
|
|
|
assert w[3] == 32
|
|
|
|
|
assert w[4] == 49
|
|
|
|
|
assert w[5] == 50
|
|
|
|
|
assert w[6] == 51
|
|
|
|
|
assert w[7] == 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn test_to_wide_cyrillic() {
|
|
|
|
|
s := 'Проба'
|
|
|
|
|
w := s.to_wide()
|
|
|
|
|
unsafe {
|
|
|
|
|
assert w[0] == 1055
|
|
|
|
|
assert w[1] == 1088
|
|
|
|
|
assert w[2] == 1086
|
|
|
|
|
assert w[3] == 1073
|
|
|
|
|
assert w[4] == 1072
|
|
|
|
|
assert w[5] == 0
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-04 15:49:15 +03:00
|
|
|
|
|
|
|
|
|
const wide_serial_number = [u8(67), 0, 76, 0, 52, 0, 54, 0, 73, 0, 49, 0, 65, 0, 48, 0, 48, 0,
|
|
|
|
|
54, 0, 52, 0, 57, 0, 0, 0, 0]
|
|
|
|
|
|
|
|
|
|
const swide_serial_number = 'CL46I1A00649'
|
|
|
|
|
|
|
|
|
|
fn test_string_from_wide() {
|
|
|
|
|
z := unsafe { string_from_wide(wide_serial_number.data) }
|
|
|
|
|
assert z == swide_serial_number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn test_string_from_wide2() {
|
|
|
|
|
z := unsafe { string_from_wide2(wide_serial_number.data, 12) }
|
|
|
|
|
assert z == swide_serial_number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn test_reverse_cyrillic_with_string_from_wide() {
|
|
|
|
|
s := 'Проба'
|
2023-07-07 02:40:11 +03:00
|
|
|
|
ws := s.to_wide()
|
|
|
|
|
z := unsafe { string_from_wide(ws) }
|
2023-07-04 15:49:15 +03:00
|
|
|
|
assert z == s
|
|
|
|
|
}
|