module scheme // Independently identified hidden-read/source alias in frozen118. This file is // standalone and deliberately shares no helper or const with another test file. const tap_review_fixture = ' (define tap-source (string-copy "ABCDEFGH")) (define tap-index 0) (define tap-buffer #f) (define tap-out #f) (define (tap-read b s n) (set! tap-buffer b) (let ((count (min n 4 (- (string-length tap-source) tap-index)))) (string-copy! b s tap-source tap-index (+ tap-index count)) (set! tap-index (+ tap-index count)) count)) (define (tap-write b s n) (string-copy! tap-source tap-index b s (+ s n)) (set! tap-index (+ tap-index n)) n) (define (tap-get) (cons tap-index #f)) (define (tap-set token) (set! tap-index (car token)) (values))' fn test_tap_review_hidden_prefix_replay_cannot_overwrite_outgoing_retained_callback_string() { for operation in ['(put-string tap-p tap-out 0 1)', '(write-string tap-out tap-p 0 1)', '(display tap-out tap-p)'] { mut vm := new() vm.eval(tap_review_fixture) or { panic(err.msg()) } p := vm.make_custom_textual_input_output_port('outgoing-reader-alias', vm.lookup('tap-read') or { panic(err.msg()) }, vm.lookup('tap-write') or { panic(err.msg()) }, vm.lookup('tap-get') or { panic(err.msg()) }, vm.lookup('tap-set') or { panic(err.msg()) }, boolean(false), read_size: 4 ) or { panic(err.msg()) } vm.define('tap-p', p) or { panic(err.msg()) } assert (vm.read_char(p) or { panic(err.msg()) }).whole() == `A` // Cursor is1; outgoing mutable value is ZBCD, while source remains // ABCDEFGH. Hidden replay needs source A, so reusing this Value as its // destination would change Z back to A before the writer receives it. vm.eval('(set! tap-out tap-buffer) (string-set! tap-out 0 #\\Z)') or { panic(err.msg()) } vm.eval(operation) or { panic(err.msg()) } assert (vm.lookup('tap-source') or { panic(err.msg()) }).text() == if operation == '(display tap-out tap-p)' { 'AZBCDFGH' } else { 'AZCDEFGH' } assert (vm.lookup('tap-out') or { panic(err.msg()) }).text() == 'ZBCD' assert vm.active.len == 0 vm.close_port(p) or { panic(err.msg()) } } }