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

Last change on this file since 36480 was 36480, checked in by Kon Lovett, 2 years ago

srfi-111

File size: 1.6 KB
Line 
1;;;; box-test.scm  -*- Scheme -*-
2;;;; Kon Lovett, Jul '18
3
4(import test)
5
6(test-begin "Box")
7
8;;;
9
10(import box)
11
12;;
13
14(import (only (chicken platform) features))
15
16(test-group "Box Support"
17  (test-assert "SRFI 111"
18    (let loop ((rem (features)))
19      (cond
20        ((null? rem)
21          #f )
22        ((eq? #:srfi-111 (car rem))
23          #t )
24        (else
25          (loop (cdr rem)) ) ) ) )
26)
27
28;;
29
30(test-group "Box Mutable"
31        (let ((tbox #f))
32    (test-assert (make-box (void)))
33    (set! tbox (make-box (void)))
34    (test-assert (box? tbox))
35    (box-set! tbox #t)
36    (test-assert (box-ref tbox))
37    (test-assert (not (box? 3))) )
38)
39
40(test-group "Box Immutable"
41        (let ((tbox #f))
42    (test-assert (make-box #f #t))
43    (set! tbox (make-box #f #t))
44    (test-assert (box? tbox))
45    (test-assert (not (box-ref tbox)))
46    (test-error (box-set! tbox #t)) )
47)
48
49(test-group "Box References"
50        (let ((var (void))
51        (tbox #f))
52    (test-assert (make-box-variable var))
53    (set! tbox (make-box-variable var))
54    (test-assert (box? tbox))
55    (test-assert (box-variable? tbox))
56    (test-assert (not (box-location? tbox)))
57    (test "Unbound Box" (void) (box-ref tbox))
58    (set! (box-ref tbox) #t)
59    (test-assert "Bound Box" (box-ref tbox))
60    (test-assert "Bound Var" var)
61    (test-assert (not (box? 3))) )
62)
63
64(test-group "Box Swap"
65        (let ((tbox #f))
66    (test-assert (make-box (void)))
67    (set! tbox (make-box 0))
68    (test-assert (box? tbox))
69    (test 1 (box-swap! tbox + 1))
70    (test 1 (box-ref tbox))
71    (test 2 (box-swap! tbox add1))
72    (test 2 (box-ref tbox)) )
73)
74
75;;;
76
77(test-end "Box")
78
79(test-exit)
Note: See TracBrowser for help on using the repository browser.