v / vlib / builtin
Raw file | 42 loc (37 sloc) | 1.18 KB | Latest commit hash d4a0d6f73
1fn test_repeat() {
2 r1 := `V`
3 r2 := `👋`
4
5 assert r1.repeat(5) == 'VVVVV'
6 assert r2.repeat(5) == '👋👋👋👋👋'
7
8 assert r1.repeat(1) == r1.str()
9 assert r2.repeat(1) == r2.str()
10
11 assert r1.repeat(0) == ''
12 assert r2.repeat(0) == ''
13}
14
15fn test_length_in_bytes() {
16 assert rune(0x0).length_in_bytes() == 1
17 assert `A`.length_in_bytes() == 1 // latin letter
18 assert rune(0x7F).length_in_bytes() == 1
19 //
20 assert rune(0x80).length_in_bytes() == 2
21 assert `Д`.length_in_bytes() == 2 // cyrillic letter
22 assert rune(0x7FF).length_in_bytes() == 2
23 //
24 assert rune(0x800).length_in_bytes() == 3
25 assert `å–‚`.length_in_bytes() == 3 // hey
26 assert rune(0xFFFF).length_in_bytes() == 3
27 //
28 assert rune(0xD800).length_in_bytes() == -1 // min for surrogates
29 assert rune(0xD866).length_in_bytes() == -1 // invalid
30 assert rune(0xDFFF).length_in_bytes() == -1 // max for surrogates
31 //
32 assert rune(0x100000).length_in_bytes() == 4
33 assert rune(0x10FFD7).length_in_bytes() == 4 // "Supplementary Private Use Area-B" ¯\_(ツ)_/¯
34 assert rune(0x10FFFF).length_in_bytes() == 4
35 //
36 assert rune(0x110000).length_in_bytes() == -1
37}
38
39fn test_bytes() {
40 r1 := `★`
41 assert r1.bytes() == [u8(0xe2), 0x98, 0x85]
42}