module scheme import os fn protocol_text(mut vm VM, source string) string { return write(vm.eval(source) or { panic('${source}: ${err}') }) or { panic(err) } } fn test_record_protocol_three_levels_laziness_final_descendant_and_reused_partial() { mut vm := new() // The probe writes events; capture it using the ordinary output parameter. program := os.read_file(@VMODROOT + '/scheme/testdata/records/segments-probe.scm') or { panic(err) } assert protocol_text(mut vm, '(define out (open-output-string)) (parameterize ((current-output-port out)) ${program}) (get-output-string out)') == r'"(prepare-c)\n(prepare-c call-c (after-n-c #t) prepare-b call-b (after-n-b #t) prepare-a call-a (a-sees-final #t 20 30))\n(110 31 30)\n(#f 101 13 3 4)\n"' } fn test_record_protocol_multishot_before_and_after_allocation_have_correct_identity() { mut vm := new() program := os.read_file(@VMODROOT + '/scheme/testdata/records/continuation-probe.scm') or { panic(err) } assert protocol_text(mut vm, '(define out (open-output-string)) (parameterize ((current-output-port out)) ${program}) (get-output-string out)') == r'"(#f #f #f (10 11 12) (20 20 20))\n(#t #t #t (13 13 13) (20 20 20))\n"' } fn test_record_protocol_variadic_recursive_and_implicit_default_parent() { mut vm := new() assert protocol_text(mut vm, "(define a (make-record-type-descriptor 'a #f #f #f #f '#((mutable x)))) (define b (make-record-type-descriptor 'b a #f #f #f '#((immutable y)))) (define ax (record-accessor a 0)) (define by (record-accessor b 0)) (define ac (make-record-constructor-descriptor a #f (lambda(p) (lambda xs (let ((r (p (car xs)))) (if (> (car xs) 0) (make-b (- (car xs) 1) 99)) r))))) (define bc (make-record-constructor-descriptor b ac (lambda(n) (lambda(x y) ((n x 'ignored) y))))) (define make-b (record-constructor bc)) (define first (make-b 3 42)) (define direct (record-constructor (make-record-constructor-descriptor b #f (lambda(n)(lambda(x y)((n x)y)))))) (define second (direct 20 22)) (list (ax first) (by first) (ax second) (by second))") == '(3 42 20 22)' }