;;;; box-test.scm -*- Scheme -*- ;;;; Kon Lovett, Jul '18 (import test) (test-begin "Box") ;;; (import box) (test-group "Box Mutable" (let ((tbox #f)) (test-assert (make-box (void))) (set! tbox (make-box (void))) (test-assert (box? tbox)) (box-set! tbox #t) (test-assert (box-ref tbox)) (test-assert (not (box? 3))) ) ) (test-group "Box Immutable" (let ((tbox #f)) (test-assert (make-box #f #t)) (set! tbox (make-box #f #t)) (test-assert (box? tbox)) (test-assert (not (box-ref tbox))) (test-error (box-set! tbox #t)) ) ) (test-group "Box References" (let ((var (void)) (tbox #f)) (test-assert (make-box-variable var)) (set! tbox (make-box-variable var)) (test-assert (box? tbox)) (test-assert (box-variable? tbox)) (test-assert (not (box-location? tbox))) (test "Unbound Box" (void) (box-ref tbox)) (set! (box-ref tbox) #t) (test-assert "Bound Box" (box-ref tbox)) (test-assert "Bound Var" var) (test-assert (not (box? 3))) ) ) (test-group "Box Swap" (let ((tbox #f)) (test-assert (make-box (void))) (set! tbox (make-box 0)) (test-assert (box? tbox)) (test 1 (box-swap! tbox + 1)) (test 1 (box-ref tbox)) (test 2 (box-swap! tbox add1)) (test 2 (box-ref tbox)) ) ) ;;; (test-end "Box") (test-exit)