diff options
Diffstat (limited to 'match-test.csc')
| -rw-r--r-- | match-test.csc | 114 |
1 files changed, 55 insertions, 59 deletions
diff --git a/match-test.csc b/match-test.csc index 104581b..84b488d 100644 --- a/match-test.csc +++ b/match-test.csc @@ -1,63 +1,59 @@ (import (scheme base) - (only (csc testing) define-test errorf subtest) + (only (csc testing) assert-equal test) (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 - "cond" - (match 3 - (0 0) - (1 1) - (2 2) - (3 3) - (_ 4)) - 3) - (test-case - "match-list" - (match '(1 2 3) - ('() 0) - ((1 2) 1) - ((1 2 3) 2) - ((1 2 3 4) 3) - (_ 4)) - 2) - (test-case - "binding" - (match '(1 2 3) - ((1 x 3) x)) - 2) - #;(test-case - "destructuring" - (match '(1 2 3) - ('() 0) - ((head . _) head)) - 1) - #;(test-case - "ignore" - (match '(1 2 3) - ((_ _ _ _) 0) - ((2 _ _) 1) - ((1 _ _) 2) - (_ 3)) - 2) - #;(test-case - "improper list" - (match '(1 2 3) - ((2 . _) 1) - ((1 . x) (car x)) - (_ 3)) - 2)))) - (for-each - (lambda (tc) - (subtest t (name tc) - (unless (equal? (expr tc) (want tc)) - (errorf t "match = {}, want {}." (expr tc) (want tc))))) - tests))) +(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)))) |
