diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-01-11 22:01:23 -0800 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-01-11 22:01:23 -0800 |
| commit | 68986fe0410584c6934c835bb0ee784655f5f8c5 (patch) | |
| tree | d51bc2f3e09df35ef81b7a0c462ff555b4344701 /csc/match-test.csc | |
| parent | Add a first implementation of a macro expander. (diff) | |
| download | chromatopelma-68986fe0410584c6934c835bb0ee784655f5f8c5.tar.zst | |
Move scheme compiler into a separate directory.
Diffstat (limited to 'csc/match-test.csc')
| -rw-r--r-- | csc/match-test.csc | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/csc/match-test.csc b/csc/match-test.csc new file mode 100644 index 0000000..31e7afa --- /dev/null +++ b/csc/match-test.csc @@ -0,0 +1,87 @@ +(import (scheme base) + (only (csc testing) assert-equal test) + (csc match)) + + +(test match-cond + (assert-equal + 3 + (match 3 + ((! 0) 0) + ((! 1) 1) + ((! 2) 2) + ((! 3) 3) + (_ 4)))) + + +(test match-list + (assert-equal + 2 + (match '(1 2 3) + ('() 0) + (((! 1) (! 2)) 1) + (((! 1) (! 2) (! 3)) 2) + (((! 1) (! 2) (! 3) (! 4)) 3) + (_ 4)))) + + +(test match-binding + (assert-equal + 2 + (match '(1 2 3) + (((! 1) x (! 3)) x)))) + + +(test match-destructuring + (assert-equal + 1 + (match '(1 2 3) + ('() 0) + ((head . _) head)))) + + +(test match-ignore + (assert-equal + 2 + (match '(1 2 3) + ((_ _ _ _) 0) + (((! 2) _ _) 1) + (((! 1) _ _) 2) + (_ 3)))) + + +(test match-improper-list + (assert-equal + 2 + (match '(1 2 3) + (((! 2) . _) 1) + (((! 1) . x) (car x)) + (_ 3)))) + + +(test match-symbol + (assert-equal + 2 + (match 'b + ((! 'a) 1) + ((! 'b) 2) + (_ 3)))) + + +(test match-when + (assert-equal + 3 + (match 'b + ((! 'a) 1) + ((! 'b) (when #f) 2) + ((! 'b) (when #t) 3) + (_ 4)))) + + +(test match-when-depending-on-pattern-variable + (assert-equal + 2 + (match 10 + (n (when (= 1 n)) 1) + (n (when (= 10 n)) 2) + (_ 3)))) |
