vile / scheme / custom_text_position_alias_independent_test.v
47 lines · 45 sloc · 2.09 KB · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1module scheme
2
3// Independently identified hidden-read/source alias in frozen118. This file is
4// standalone and deliberately shares no helper or const with another test file.
5const tap_review_fixture = '
6(define tap-source (string-copy "ABCDEFGH")) (define tap-index 0)
7(define tap-buffer #f) (define tap-out #f)
8(define (tap-read b s n)
9 (set! tap-buffer b)
10 (let ((count (min n 4 (- (string-length tap-source) tap-index))))
11 (string-copy! b s tap-source tap-index (+ tap-index count))
12 (set! tap-index (+ tap-index count)) count))
13(define (tap-write b s n)
14 (string-copy! tap-source tap-index b s (+ s n))
15 (set! tap-index (+ tap-index n)) n)
16(define (tap-get) (cons tap-index #f))
17(define (tap-set token) (set! tap-index (car token)) (values))'
18
19fn test_tap_review_hidden_prefix_replay_cannot_overwrite_outgoing_retained_callback_string() {
20 for operation in ['(put-string tap-p tap-out 0 1)', '(write-string tap-out tap-p 0 1)',
21 '(display tap-out tap-p)'] {
22 mut vm := new()
23 vm.eval(tap_review_fixture) or { panic(err.msg()) }
24 p := vm.make_custom_textual_input_output_port('outgoing-reader-alias',
25 vm.lookup('tap-read') or { panic(err.msg()) },
26 vm.lookup('tap-write') or { panic(err.msg()) },
27 vm.lookup('tap-get') or { panic(err.msg()) },
28 vm.lookup('tap-set') or { panic(err.msg()) }, boolean(false),
29 read_size: 4
30 ) or { panic(err.msg()) }
31 vm.define('tap-p', p) or { panic(err.msg()) }
32 assert (vm.read_char(p) or { panic(err.msg()) }).whole() == `A`
33 // Cursor is1; outgoing mutable value is ZBCD, while source remains
34 // ABCDEFGH. Hidden replay needs source A, so reusing this Value as its
35 // destination would change Z back to A before the writer receives it.
36 vm.eval('(set! tap-out tap-buffer) (string-set! tap-out 0 #\\Z)') or { panic(err.msg()) }
37 vm.eval(operation) or { panic(err.msg()) }
38 assert (vm.lookup('tap-source') or { panic(err.msg()) }).text() == if operation == '(display tap-out tap-p)' {
39 'AZBCDFGH'
40 } else {
41 'AZCDEFGH'
42 }
43 assert (vm.lookup('tap-out') or { panic(err.msg()) }).text() == 'ZBCD'
44 assert vm.active.len == 0
45 vm.close_port(p) or { panic(err.msg()) }
46 }
47}
48