vile / scheme / unicode_hash_test.v
46 lines · 43 sloc · 1.84 KB · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1module scheme
2
3fn unicode_hash_text(mut vm VM, source string) string {
4 return write(vm.eval(source) or { panic(err) }) or { panic(err) }
5}
6
7fn test_unicode_full_fold_hash_stream_matches_all_ci_comparisons_and_table_keys() {
8 mut vm := new()
9 for left, right in {
10 'Straße': 'STRASSE'
11 'ΟΣ': 'ος'
12 'µ': 'Μ'
13 'ffi': 'FFI'
14 'İ': 'i̇'
15 'Ꭰ': 'ꭰ'
16 'sßfffi': 'SSSFFFI'
17 'A\x00ß': 'a\x00ss'
18 } {
19 assert compare_text(left, right, true) == 0
20 lh := hashtable_string_ci_hash(mut vm, [string_value(left)]) or { panic(err) }
21 rh := hashtable_string_ci_hash(mut vm, [string_value(right)]) or { panic(err) }
22 assert lh.whole() == rh.whole(), '${left} ${right}'
23 }
24 assert unicode_hash_text(mut vm, '(define h (make-hashtable string-ci-hash string-ci=?))
25 (hashtable-set! h "Straße" 40) (hashtable-update! h "STRASSE" (lambda (x) (+ x 2)) 0)
26 (hashtable-set! h "ς" 9) (list (hashtable-ref h "strasse" #f) (hashtable-ref h "Σ" #f) (hashtable-size h))') == '(42 9 2)'
27 assert unicode_hash_text(mut vm, '(list (string-ci=? "a­b" "ab") (string-ci=? "İ" "i") (string-ci=? "é" "é") (char-ci=? #\\ß #\\s))') == '(#f #f #f #f)'
28 for a in ['A', 'a', 'b', 's', 'ss', 'ß', 'ffi', 'ffi', 'i', 'i̇', 'İ', 'Σ', 'ς', 'σ',
29 'Ꭰ', 'ꭰ'] {
30 for b in ['A', 'a', 'b', 's', 'ss', 'ß', 'ffi', 'ffi', 'i', 'i̇', 'İ', 'Σ', 'ς', 'σ',
31 'Ꭰ', 'ꭰ'] {
32 ab := compare_text(a, b, true)
33 assert ab == -compare_text(b, a, true)
34 for c in ['b', 'ss', 'ffi', 'σ', 'ꭰ'] {
35 if ab <= 0 && compare_text(b, c, true) <= 0 {
36 assert compare_text(a, c, true) <= 0
37 }
38 }
39 }
40 }
41}
42
43fn test_unicode_ci_hashing_and_table_lookup_share_the_vile_frontend() {
44 mut vm := new()
45 assert vm.eval_alt('h:=make-hashtable(string-ci-hash,string-ci=?)\nhashtable-set!(h,"Straße",42)\nhashtable-ref(h,"STRASSE",#f)') or { panic(err) }.whole() == 42
46}
47