source: project/release/5/box/trunk/tests/box-test.scm @ 38569

Last change on this file since 38569 was 38569, checked in by Kon Lovett, 10 months ago

add types include, fix predicate types, reflow

File size: 1.4 KB
Line 
1;;;; box-test.scm  -*- Scheme -*-
2;;;; Kon Lovett, Apr '20
3;;;; Kon Lovett, Jul '18
4
5(import test)
6
7(test-begin "Box")
8
9;;;
10
11(import box)
12(import (chicken base))
13(import (only (chicken port) with-output-to-string))
14(import (only (chicken memory representation) procedure-data))
15
16;should be there
17(include "box.types")
18
19;;
20
21(test-group "Box Mutable"
22        (let ((tbox (make-box (void))))
23    (test-assert (box? tbox))
24    (test "#&#<unspecified>" (with-output-to-string (cut display tbox)))
25    (box-set! tbox #t)
26    (test-assert (box-ref tbox))
27    (test-assert (not (box? 3))) )
28)
29
30(test-group "Box Immutable"
31        (let ((tbox (make-box #f #t)))
32    (test-assert (box? tbox))
33    (test "#&#f" (with-output-to-string (cut display tbox)))
34    (test-assert (not (box-ref tbox)))
35    (test-error (box-set! tbox #t)) )
36)
37
38(test-group "Box References"
39        (let* ((var (void))
40               (tbox (make-box-variable var)))
41    (test-assert (box? tbox))
42    (test-assert (box-variable? tbox))
43    (test-assert (not (box-location? tbox)))
44    (test "Unbound Box" (void) (box-ref tbox))
45    (set! (box-ref tbox) #t)
46    (test-assert "Bound Box" (box-ref tbox))
47    (test-assert "Bound Var" var)
48    (test-assert (not (box? 3))) )
49)
50
51(test-group "Box Swap"
52        (let ((tbox (make-box 0)))
53    (test-assert (box? tbox))
54    (test 1 (box-swap! tbox + 1))
55    (test 1 (box-ref tbox))
56    (test 2 (box-swap! tbox add1))
57    (test 2 (box-ref tbox)) )
58)
59
60;;;
61
62(test-end "Box")
63
64(test-exit)
Note: See TracBrowser for help on using the repository browser.