diff options
Diffstat (limited to 'match-test.csc')
| -rw-r--r-- | match-test.csc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/match-test.csc b/match-test.csc new file mode 100644 index 0000000..3fed862 --- /dev/null +++ b/match-test.csc @@ -0,0 +1,42 @@ +(import (scheme base) + (only (csc testing) define-test errorf subtest) + (csc match)) + + +(define-test (test-match t) + (define-record-type <test-case> + (test-case name expr want) + test-case? + (name name) + (expr expr) + (want want)) + (let ((tests (list + (test-case + "simple" + (match 3 + (0 0) + (1 1) + (2 2) + (3 3) + (else 4)) + 3) + (test-case + "match-list" + (match '(1 2 3) + ('() 0) + ((1 2) 1) + ((1 2 3) 2) + ((1 2 3 4) 3) + (else 4)) + 2) + (test-case + "binding" + (match '(1 2 3) + ((1 (! x) 3) x)) + 2)))) + (for-each + (lambda (tc) + (subtest t (name tc) + (unless (equal? (expr tc) (want tc)) + (errorf t "match = {}, want {}." (expr tc) (want tc))))) + tests))) |
