aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2025-09-01 13:10:23 -0400
committerGravatar Peter McGoron 2025-09-01 13:10:23 -0400
commit88d83a868ff85c7386278397a3a38caf3e755844 (patch)
treed72420c07f63d220e7c72e189867211c24232154 /tests
parentthe rest of r7rs (diff)
fix list-tail, add some tests
Diffstat (limited to 'tests')
-rw-r--r--tests/run.scm44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/run.scm b/tests/run.scm
new file mode 100644
index 0000000..f9c5c26
--- /dev/null
+++ b/tests/run.scm
@@ -0,0 +1,44 @@
+(import r7rs
+ (prefix (hascheme base) ha:)
+ (hascheme eager)
+ (srfi 64))
+
+(cond-expand
+ (chicken-5 (test-runner-current (test-runner-create)))
+ (else))
+
+(ha:define
+ (hascheme-natural-numbers)
+ (ha:let loop ((i 0)) (ha:seq i (ha:cons i (loop (ha:+ i 1))))))
+
+(ha:define (square-of-list list) (ha:map ha:square list))
+
+(test-group "lists"
+ (test-assert
+ "cons is lazy, car"
+ (force (ha:car (ha:cons #t (ha:error "boom")))))
+ (test-assert
+ "cons is lazy, cdr"
+ (guard (x ((equal? (force (error-object-message x)) "boom") #t)
+ (else #f))
+ (force (ha:cdr (ha:cons #f (ha:error "boom"))))
+ #f))
+ (test-equal
+ 1000
+ (force (ha:list-ref (hascheme-natural-numbers) 1000)))
+ (let ((flag '()))
+ (test-equal
+ "map is lazy"
+ '(1000)
+ (begin
+ (force (ha:list-ref (ha:map (ha:lambda (x) (set! flag
+ (cons (force x) flag)))
+ (hascheme-natural-numbers))
+ 1000))
+ flag)))
+ (test-equal "runs in bounded space"
+ (square 1000)
+ (force (ha:list-ref (square-of-list (hascheme-natural-numbers))
+ 1000))))
+
+