vile / scheme / unicode_allocation_test.v
43 lines · 41 sloc · 1.77 KB · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1module scheme
2
3import arena
4
5fn test_prepared_unicode_cursor_scalar_comparison_and_hashing_allocate_no_operation_storage() {
6 mut vm := new()
7 // Warm neither data maps nor caches: the backend data is static.
8 mut region := arena.new()
9 region.push()
10 // Construct arguments outside the measured body, since constructors own strings.
11 left, right := string_value('StraßeΣςİffiᎠ'), string_value('STRASSEσσi̇ffiꭰ')
12 args_left, args_right := [left], [right]
13 ascii := string_value('already lower')
14 before := region.used()
15 for _ in 0 .. 1000 {
16 assert compare_text(left.text(), right.text(), true) == 0
17 assert compare_text('ABC', 'abc', true) == 0
18 assert unicode_simple_fold(`ς`) == `σ`
19 assert unicode_simple_case(`ß`, 0) == `ß`
20 assert unicode_alphabetic(rune(0x345))
21 assert unicode_case_property(`ª`, false)
22 assert unicode_decimal(`٤`) == 4
23 assert hashtable_string_ci_hash(mut vm, args_left) or { panic(err) }.whole() == hashtable_string_ci_hash(mut vm, args_right) or { panic(err) }.whole()
24 assert unicode_transform_value(ascii, .lower) or { panic(err) }.pointer() == ascii.pointer()
25 }
26 assert region.used() == before
27 region.pop()
28 region.free()
29 $if gcboehm ? {
30 // The helper creates its prepared strings before taking the heap counter.
31 l, r := string_value('StraßeΣςİffiᎠ'), string_value('STRASSEσσi̇ffiꭰ')
32 la, ra := [l], [r]
33 gc_collect()
34 heap_before := gc_heap_usage().total_bytes
35 for _ in 0 .. 1000 {
36 assert compare_text(l.text(), r.text(), true) == 0
37 assert unicode_simple_case(`ß`, 0) == `ß`
38 assert unicode_simple_fold(`ς`) == `σ`
39 assert hashtable_string_ci_hash(mut vm, la) or { panic(err) }.whole() == hashtable_string_ci_hash(mut vm, ra) or { panic(err) }.whole()
40 }
41 assert gc_heap_usage().total_bytes == heap_before
42 }
43}
44