vile / scheme / goops_method_protocol_prod_test.v
29 lines · 28 sloc · 1.31 KB · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1module scheme
2
3// Production builds remove assertions, including any evaluation inside them.
4// Keep evaluator setup and verification explicit in these gates.
5fn test_goops_production_method_factories_and_lexical_argument_locations() {
6 mut vm := new()
7 value := vm.eval('(define m
8 (method* ((x <number>) #:optional (z 3) #:key (y 2))
9 (set! x (+ x 1)) (set! z (+ z 2))
10 (lambda () (next-method))))
11 (define bound ((slot-ref m (quote make-procedure)) (lambda args args)))
12 (define first (bound 4))
13 (define second (bound 8 10 #:y 9))
14 (list (method-procedure m) (first) (second))') or { panic(err) }
15 text := write(value) or { panic(err) }
16 if text != '(#f (5 5) (9 12 #:y 9))' { panic('wrong escaped lexical-next bindings: ${text}') }
17 vm.eval('(define saved #f)
18 (define-method (g (x <number>)) (* x 2))
19 (add-method! g (make <method> #:specializers (list <integer>)
20 #:make-procedure (lambda (next)
21 (let ((offset (call/cc (lambda (k) (set! saved k) 10))))
22 (lambda (x) (+ offset (next x)))))))') or { panic(err) }
23 first := vm.eval('(g 4)') or { panic(err) }
24 second := vm.eval('(saved 20)') or { panic(err) }
25 third := vm.eval('(saved 30)') or { panic(err) }
26 if first.whole() != 18 || second.whole() != 28 || third.whole() != 38 {
27 panic('method factory continuation did not preserve the evaluator call')
28 }
29}
30