X-Git-Url: http://git.lukelau.me/?a=blobdiff_plain;f=tests.scm;h=bcd878a11dfccb8368d930931d5ad00721d8c626;hb=c4a5f8ab1efce20f0e1181ffe34639facb19594a;hp=398793059e48cdd4b4523cf09fa5fc4b43359b3f;hpb=5ea42a37be529974bff32b719bd91e004d1dfcd8;p=scheme.git diff --git a/tests.scm b/tests.scm index 3987930..bcd878a 100644 --- a/tests.scm +++ b/tests.scm @@ -43,6 +43,30 @@ (let ((str (read-file "/tmp/test-output.txt"))) (test str output))) +(test (data-tors '(A . ((foo Int Bool) + (bar Bool)))) + '((foo (A foo constructor) + abs Int (abs Bool A)) + (foo~0 (A foo 0) abs A Int) + (foo~1 (A foo 1) abs A Bool) + (bar (A bar constructor) abs Bool A) + (bar~0 (A bar 0) abs A Bool))) + +(test (data-tors-type-env + '(A . ((foo Int Bool) + (bar Bool)))) + '((foo . (abs Int (abs Bool A))) + (foo~0 . (abs A Int)) + (foo~1 . (abs A Bool)) + (bar . (abs Bool A)) + (bar~0 . (abs A Bool)))) + +(test (expand-pattern-matches '(let ([(foo x y) (foo 123 234)] [z (f 123)]) x)) + '(let ([x (foo~0 (foo 123 234))] + [y (foo~1 (foo 123 234))] + [z (f 123)]) + x)) + (test-types (typecheck '((lambda (x) (+ ((lambda (y) (x y 3)) 5) 2)))) '(abs (abs Int (abs Int Int)) Int)) @@ -95,6 +119,9 @@ (pow 4 2)))) 'Int) + ; ADTs + + (test-types (typecheck '((data A @@ -115,6 +142,19 @@ y))) 'Int) + + ; 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) (x : Int)) : Int))) + (((- : (abs Int (abs Int Int))) (y : Int) (x : Int)) : Int)) : 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) @@ -169,14 +209,22 @@ (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") + + ; adts and pattern matching + +(test-prog '((data A [foo Bool Int]) + (let ([(foo x y) (foo (= 3 3) 42)]) + y)) + 42)