X-Git-Url: https://git.lukelau.me/?p=scheme.git;a=blobdiff_plain;f=tests.scm;h=4e14fb6ab8ee3634b1fce5be5166d55fe8455d96;hp=30d23f61ed6375c786574a1d18056eb0278b398a;hb=89ef32141732e6d0bbfc7484b465844b62d8d139;hpb=844dcd052c6f551d9936693c2b4c49cf920c7051 diff --git a/tests.scm b/tests.scm index 30d23f6..4e14fb6 100644 --- a/tests.scm +++ b/tests.scm @@ -43,9 +43,19 @@ (let ((str (read-file "/tmp/test-output.txt"))) (test str output))) -(test (data-tors '(data A +(test (data-tors (data-layout '(data A (foo Int Bool) - (bar Bool))) + (bar Bool)))) + '((foo . (constructor . (abs Int (abs Bool A)))) + (foo~0 . (0 . (abs A Int))) + (foo~1 . (1 . (abs A Bool))) + (bar . (constructor . (abs Bool A))) + (bar~0 . (0 . (abs A Bool))))) + +(test (data-tors-env + (data-layout '(data A + (foo Int Bool) + (bar Bool)))) '((foo . (abs Int (abs Bool A))) (foo~0 . (abs A Int)) (foo~1 . (abs A Bool)) @@ -104,6 +114,9 @@ (pow 4 2)))) 'Int) + ; ADTs + + (test-types (typecheck '((data A @@ -124,6 +137,27 @@ y))) 'Int) + + ; pattern matching +(test (let-bindings '(let ([(foo x) a]) x)) + '((x (foo~0 a)))) + +(test (let-bindings '(let ([x (foo 42)] [(foo y) x]) x)) + '((x (foo 42)) + (y (foo~0 x)))) + + ; type annotations + +(test (annotate-types + '((let ([x 42] + [y (+ 1 x)]) + (- y x)))) + + '((let () + ((let ((x 42 : Int) + (y ((((+ : (abs Int (abs Int Int))) (1 : Int)) : (abs Int Int)) (x : Int)) : Int)) + (((((- : (abs Int (abs Int Int))) (y : Int)) : (abs Int Int)) (x : Int)) : Int)))))) + (test-expr '(+ 1 2) 3) (test-expr '(bool->int (= 2 0)) 0) (test-expr '((lambda (x) ((lambda (y) (+ x y)) 42)) 100) 142) @@ -178,14 +212,15 @@ (pow 4 2)) 16) -(test-prog-stdout '(let ([f (lambda (n) - (if (= n 0) - 0 - (let () - (print "a") - (g (- n 1)))))] - [g (lambda (m) - (let () - (print "b") - (f (- m 1))))]) - (f 10)) "ababababab") + ; mutual recursion +;; (test-prog-stdout '((let ([f (lambda (n) +;; (if (= n 0) +;; 0 +;; (let () +;; (print "a") +;; (g (- n 1)))))] +;; [g (lambda (m) +;; (let () +;; (print "b") +;; (f (- m 1))))]) +;; (f 10))) "ababababab")