vile / scheme / port_combined_frontend_test.v
49 lines · 47 sloc · 1.74 KB · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1module 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.
6fn test_vile_direct_escaped_binary_combined_constructor_and_callbacks() {
7 mut vm := new()
8 answer := vm.eval_alt('closed := 0
9sink := open-output-bytevector()
10p := |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 })
14first := get-u8(p)
15put-u8(p, 87)
16close-input-port(p)
17put-u8(p, 88)
18close-port(p)
19list(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
25fn test_vile_direct_escaped_text_combined_constructor_uses_character_counts() {
26 mut vm := new()
27 answer := vm.eval_alt('closed := 0
28source := "λ😀"
29at := 0
30sink := open-output-string()
31p := |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 })
40read-back := get-string-n(p, 2)
41put-string(p, "Ω😀")
42close-output-port(p)
43at-eof := eof-object?(get-char(p))
44close-port(p)
45list(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