| 1 | module scheme |
| 2 | |
| 3 | fn unicode_text(mut vm VM, source string) string { |
| 4 | return write(vm.eval(source) or { panic('${source}: ${err}') }) or { panic(err) } |
| 5 | } |
| 6 | |
| 7 | fn test_unicode17_full_casing_folding_and_report_title_errata() { |
| 8 | mut vm := new() |
| 9 | for source, expected in { |
| 10 | '(list (string-upcase "Straße") (string-downcase "ΟΣ") (string-titlecase "who\'s tHERE?"))': '("STRASSE" "ος" "Who\'s There?")' |
| 11 | '(list (string-titlecase "r6rs") (string-titlecase "ßeta") (string-upcase "ffi") (string-titlecase "ffi"))': '("R6rs" "Sseta" "FFI" "Ffi")' |
| 12 | '(list (string-foldcase "İIıi") (string-foldcase "Ꭰꭰ"))': '("i̇iıi" "ᎠᎠ")' |
| 13 | '(list (char-upcase #\\ß) (char-titlecase #\\ß) (char-downcase #\\İ) (char-foldcase #\\İ) (char-foldcase #\\ı))': '(#\\ß #\\ß #\\i #\\İ #\\ı)' |
| 14 | '(list (char-titlecase #\\dz) (char-title-case? #\\Dz) (char-ci=? #\\ς #\\σ) (char-ci=? #\\µ #\\Μ))': '(#\\Dz #t #t #t)' |
| 15 | '(list (char-alphabetic? (integer->char 837)) (char-lower-case? #\\ª) (char-numeric? #\\²) (digit-value #\\²) (digit-value #\\٤))': '(#t #t #f #f 4)' |
| 16 | '(list (eq? (char-general-category #\\a) (string->symbol "Ll")) (char-general-category #\\space) (char-general-category (integer->char 1114111)))': '(#t #!no-fold-case Zs Cn)' |
| 17 | '(list (string-ci=? "Straße" "STRASSE") (string-ci=? "ς" "Σ") (string-ci=? "ffi" "FFI") (string-ci=? "é" "é"))': '(#t #t #t #f)' |
| 18 | '(list (string-normalize-nfd "é") (string-normalize-nfc "é") (string-normalize-nfkd "Affi①") (string-normalize-nfkc "Affi①"))': '("é" "é" "Affi1" "Affi1")' |
| 19 | '(list (string-normalize-nfc "각") (string-normalize-nfd "각") (string-normalize-nfd "À̕"))': '("각" "각" "À̕")' |
| 20 | '(list (string-ci<? "s" "ß") (string-ci<=? "ß" "ss") (string-ci>=? "ffi" "ffi") (string-ci>? "t" "ß"))': '(#t #t #t #t)' |
| 21 | } { |
| 22 | assert unicode_text(mut vm, source) == expected, source |
| 23 | } |
| 24 | assert write(vm.eval_alt('string-upcase("Straße")') or { panic(err) }) or { panic(err) } == '"STRASSE"' |
| 25 | } |
| 26 | |
| 27 | fn test_unicode_unary_errors_and_variadic_comparisons_validate_all_arguments() { |
| 28 | mut vm := new() |
| 29 | for index in 0 .. unicode_native_descriptors.len { |
| 30 | name := unicode_native_descriptors[index].name |
| 31 | for source in ['(${name})', '(${name} 1)', '(${name} "x" "y")'] { |
| 32 | if _ := vm.eval(source) { |
| 33 | assert false, source |
| 34 | } else { |
| 35 | assert err is EvalError |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | for source in ['(string-ci=? "a" "b" 1)', '(char-ci<? #\\z #\\a 1)'] { |
| 40 | if _ := vm.eval(source) { |
| 41 | assert false, source |
| 42 | } else { |
| 43 | assert err is EvalError |
| 44 | } |
| 45 | } |
| 46 | assert unicode_text(mut vm, '(+ 20 22)') == '42' |
| 47 | } |
| 48 | |
| 49 | fn test_unicode_pristine_imports_and_continuations_share_runtime_procedures() { |
| 50 | mut vm := new() |
| 51 | assert unicode_text(mut vm, '(import (rename (only (scheme char) string-foldcase digit-value) (string-foldcase fold))) (list (fold "Straße") (digit-value #\\٤))') == '("strasse" 4)' |
| 52 | assert unicode_text(mut vm, '(import (prefix (rnrs unicode) u:)) (u:string-normalize-nfc "é")') == '"é"' |
| 53 | assert unicode_text(mut vm, '(define original string-upcase) (set! string-upcase #f) (import (prefix (only (vile unicode) string-upcase) p:)) (eq? original p:string-upcase)') == '#t' |
| 54 | assert unicode_text(mut vm, '(define saved #f) (define result (call/cc (lambda (k) (set! saved k) "Straße"))) (p:string-upcase result)') == '"STRASSE"' |
| 55 | assert unicode_text(mut vm, '(saved "ffi")') == '"FFI"' |
| 56 | } |
| 57 | |
| 58 | fn test_unicode_complete_library_catalogs_preserve_pristine_identity_in_both_frontends() { |
| 59 | mut vm := new() |
| 60 | unicode_text(mut vm, '(import (prefix (scheme char) ch:) (prefix (vile unicode) vu:) (prefix (rnrs unicode) ru:))') |
| 61 | chars := (standard_library_export_names('char') or { panic('char catalog absent') }).split(' ') |
| 62 | unicode := (selected_library_export_names('unicode') or { panic('Unicode catalog absent') }).split(' ') |
| 63 | assert chars.len == 22 && unicode.len == 29 |
| 64 | for name in chars { |
| 65 | assert eqv(vm.lookup(name) or { panic(err) }, vm.lookup('ch:' + name) or { panic(err) }) |
| 66 | } |
| 67 | for name in unicode { |
| 68 | assert eqv(vm.lookup(name) or { panic(err) }, vm.lookup('vu:' + name) or { panic(err) }) |
| 69 | assert eqv(vm.lookup(name) or { panic(err) }, vm.lookup('ru:' + name) or { panic(err) }) |
| 70 | } |
| 71 | mut alternate := new() |
| 72 | assert write(alternate.eval_alt('import(only((vile,unicode),string-upcase,string-normalize-nfc))\nstring-upcase(string-normalize-nfc("é"))') or { panic(err) }) or { panic(err) } == '"É"' |
| 73 | } |
| 74 | |