| 1 | module scheme |
| 2 | |
| 3 | // A slash is an arithmetic operator in Vile identifiers. The ordinary escaped |
| 4 | // identifier syntax names these standard constructors without changing infix |
| 5 | // parsing or introducing a frontend-specific runtime binding. |
| 6 | fn test_vile_direct_escaped_binary_combined_constructor_and_callbacks() { |
| 7 | mut vm := new() |
| 8 | answer := vm.eval_alt('closed := 0 |
| 9 | sink := open-output-bytevector() |
| 10 | p := |make-custom-binary-input/output-port|("vile-rx-tx", |
| 11 | fn(b, s, n) { bytevector-u8-set!(b, s, 82), 1 }, |
| 12 | fn(b, s, n) { put-bytevector(sink, b, s, n), n }, |
| 13 | #f, #f, fn() { closed = closed + 1 }) |
| 14 | first := get-u8(p) |
| 15 | put-u8(p, 87) |
| 16 | close-input-port(p) |
| 17 | put-u8(p, 88) |
| 18 | close-port(p) |
| 19 | list(first, get-output-bytevector(sink), closed, |
| 20 | input-port?(p), output-port?(p), input-port-open?(p), output-port-open?(p))') or { panic(err.msg()) } |
| 21 | assert write(answer) or { panic(err.msg()) } == '(82 #u8(87 88) 1 #t #t #f #f)' |
| 22 | assert vm.active.len == 0 |
| 23 | } |
| 24 | |
| 25 | fn test_vile_direct_escaped_text_combined_constructor_uses_character_counts() { |
| 26 | mut vm := new() |
| 27 | answer := vm.eval_alt('closed := 0 |
| 28 | source := "λ😀" |
| 29 | at := 0 |
| 30 | sink := open-output-string() |
| 31 | p := |make-custom-textual-input/output-port|("vile-text", |
| 32 | fn(b, s, n) { |
| 33 | amount := min(n, string-length(source) - at) |
| 34 | string-copy!(b, s, source, at, at + amount) |
| 35 | at = at + amount |
| 36 | amount |
| 37 | }, |
| 38 | fn(b, s, n) { put-string(sink, b, s, n), n }, |
| 39 | #f, #f, fn() { closed = closed + 1 }) |
| 40 | read-back := get-string-n(p, 2) |
| 41 | put-string(p, "Ω😀") |
| 42 | close-output-port(p) |
| 43 | at-eof := eof-object?(get-char(p)) |
| 44 | close-port(p) |
| 45 | list(read-back, get-output-string(sink), at-eof, closed, |
| 46 | input-port?(p), output-port?(p), textual-port?(p))') or { panic(err.msg()) } |
| 47 | assert write(answer) or { panic(err.msg()) } == '("λ😀" "Ω😀" #t 1 #t #t #t)' |
| 48 | assert vm.active.len == 0 |
| 49 | } |
| 50 | |