diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-01-09 11:16:17 -0800 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-01-09 11:16:17 -0800 |
| commit | e7d0eefb6f766968fe0de26556da1353ec9bd0ab (patch) | |
| tree | af8b4015ddc64690655219e8367da1b7249f8a3a /match-test.csc | |
| parent | Use load to evaluate each library's tests. (diff) | |
| download | chromatopelma-e7d0eefb6f766968fe0de26556da1353ec9bd0ab.tar.zst | |
Add a library for pattern matching.
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))) |
