module scheme fn unicode_hash_text(mut vm VM, source string) string { return write(vm.eval(source) or { panic(err) }) or { panic(err) } } fn test_unicode_full_fold_hash_stream_matches_all_ci_comparisons_and_table_keys() { mut vm := new() for left, right in { 'Straße': 'STRASSE' 'ΟΣ': 'ος' 'µ': 'Μ' 'ffi': 'FFI' 'İ': 'i̇' 'Ꭰ': 'ꭰ' 'sßfffi': 'SSSFFFI' 'A\x00ß': 'a\x00ss' } { assert compare_text(left, right, true) == 0 lh := hashtable_string_ci_hash(mut vm, [string_value(left)]) or { panic(err) } rh := hashtable_string_ci_hash(mut vm, [string_value(right)]) or { panic(err) } assert lh.whole() == rh.whole(), '${left} ${right}' } assert unicode_hash_text(mut vm, '(define h (make-hashtable string-ci-hash string-ci=?)) (hashtable-set! h "Straße" 40) (hashtable-update! h "STRASSE" (lambda (x) (+ x 2)) 0) (hashtable-set! h "ς" 9) (list (hashtable-ref h "strasse" #f) (hashtable-ref h "Σ" #f) (hashtable-size h))') == '(42 9 2)' assert unicode_hash_text(mut vm, '(list (string-ci=? "a­b" "ab") (string-ci=? "İ" "i") (string-ci=? "é" "é") (char-ci=? #\\ß #\\s))') == '(#f #f #f #f)' for a in ['A', 'a', 'b', 's', 'ss', 'ß', 'ffi', 'ffi', 'i', 'i̇', 'İ', 'Σ', 'ς', 'σ', 'Ꭰ', 'ꭰ'] { for b in ['A', 'a', 'b', 's', 'ss', 'ß', 'ffi', 'ffi', 'i', 'i̇', 'İ', 'Σ', 'ς', 'σ', 'Ꭰ', 'ꭰ'] { ab := compare_text(a, b, true) assert ab == -compare_text(b, a, true) for c in ['b', 'ss', 'ffi', 'σ', 'ꭰ'] { if ab <= 0 && compare_text(b, c, true) <= 0 { assert compare_text(a, c, true) <= 0 } } } } } fn test_unicode_ci_hashing_and_table_lookup_share_the_vile_frontend() { mut vm := new() 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 }