module scheme // A slash is an arithmetic operator in Vile identifiers. The ordinary escaped // identifier syntax names these standard constructors without changing infix // parsing or introducing a frontend-specific runtime binding. fn test_vile_direct_escaped_binary_combined_constructor_and_callbacks() { mut vm := new() answer := vm.eval_alt('closed := 0 sink := open-output-bytevector() p := |make-custom-binary-input/output-port|("vile-rx-tx", fn(b, s, n) { bytevector-u8-set!(b, s, 82), 1 }, fn(b, s, n) { put-bytevector(sink, b, s, n), n }, #f, #f, fn() { closed = closed + 1 }) first := get-u8(p) put-u8(p, 87) close-input-port(p) put-u8(p, 88) close-port(p) list(first, get-output-bytevector(sink), closed, input-port?(p), output-port?(p), input-port-open?(p), output-port-open?(p))') or { panic(err.msg()) } assert write(answer) or { panic(err.msg()) } == '(82 #u8(87 88) 1 #t #t #f #f)' assert vm.active.len == 0 } fn test_vile_direct_escaped_text_combined_constructor_uses_character_counts() { mut vm := new() answer := vm.eval_alt('closed := 0 source := "λ😀" at := 0 sink := open-output-string() p := |make-custom-textual-input/output-port|("vile-text", fn(b, s, n) { amount := min(n, string-length(source) - at) string-copy!(b, s, source, at, at + amount) at = at + amount amount }, fn(b, s, n) { put-string(sink, b, s, n), n }, #f, #f, fn() { closed = closed + 1 }) read-back := get-string-n(p, 2) put-string(p, "Ω😀") close-output-port(p) at-eof := eof-object?(get-char(p)) close-port(p) list(read-back, get-output-string(sink), at-eof, closed, input-port?(p), output-port?(p), textual-port?(p))') or { panic(err.msg()) } assert write(answer) or { panic(err.msg()) } == '("λ😀" "Ω😀" #t 1 #t #t #t)' assert vm.active.len == 0 }