www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

test-unsafe.rkt (1482B)


      1 #lang typed/racket
      2 
      3 (require delay-pure
      4          syntax/macro-testing
      5          typed/rackunit)
      6 
      7 ;; unsafe-pure/stateless within pure-thunk/stateless
      8 (let ()
      9   (define x 1)
     10   (define f
     11     (pure-thunk/stateless
     12      (λ ()
     13        (+ (unsafe-pure/stateless (set! x (add1 x))
     14                                  x)
     15           1))))
     16   (check-equal? (list (f) (f) (f)) '(3 4 5)))
     17 
     18 ;; unsafe-pure/stateless within pure-thunk/stateful
     19 (let ()
     20   (define x 1)
     21   (define f
     22     (pure-thunk/stateful
     23      (λ ()
     24        (+ (unsafe-pure/stateless (set! x (add1 x))
     25                                  x)
     26           1))))
     27   (check-equal? (list (f) (f) (f)) '(3 4 5)))
     28 
     29 ;; unsafe-operation/mutating within pure-thunk/stateless
     30 (check-exn #px"unsafe-operation/mutating disallowed within pure/stateless"
     31            (λ ()
     32              (convert-compile-time-error
     33               (let ()
     34                 (define x 1)
     35                 (define f
     36                   (pure-thunk/stateless
     37                    (λ ()
     38                      (+ (unsafe-operation/mutating (set! x (add1 x))
     39                                                    x)
     40                         1))))
     41                 (check-equal? (list (f) (f) (f)) '(3 4 5))))))
     42 
     43 ;; unsafe-operation/mutating within pure-thunk/stateful
     44 (let ()
     45   (define x 1)
     46   (define f
     47     (pure-thunk/stateful
     48      (λ ()
     49        (+ (unsafe-operation/mutating (set! x (add1 x))
     50                                      x)
     51           1))))
     52   (check-equal? (list (f) (f) (f)) '(3 4 5)))