diff --git a/collects/unstable/tests/match.rkt b/collects/unstable/tests/match.rkt new file mode 100644 index 0000000000..4c20b037b6 --- /dev/null +++ b/collects/unstable/tests/match.rkt @@ -0,0 +1,43 @@ +#lang racket/base + +(require rackunit + unstable/match) + +(define/match ((curried x) y) + [((? number? x) y) (+ x y)] + [((? symbol? x) y) x]) + +(check-equal? ((curried 3) 5) 8) +(check-equal? ((curried 'foo) 5) 'foo) + +(define/match (fact n) + [(0) 1] + [(n) (* n (fact (sub1 n)))]) + +(check-equal? (fact 0) 1) +(check-equal? (fact 5) 120) + +(define/match (foo #:bar [bar 5] [baz 7]) + [(5 7) #t] + [(_ _) #f]) + +(check-true (foo)) +(check-true (foo #:bar 5 7)) +(check-false (foo #:bar 7 8)) + +(define/match (foo2 #:qux qux #:bar [bar 5] [baz 7]) + [(1 5 7) #t] + [(_ _ _) #f]) + +(check-true (foo2 #:qux 1)) +(check-false (foo2 #:qux 2)) +(check-true (foo2 #:qux 1 #:bar 5 7)) + +(define/match (f [x 3] . rst) + [(3 '(1 2)) #t] + [(_ _) #f]) + +(check-true (f 3 1 2)) +(check-false (f)) +(check-false (f 2)) +(check-false (f 2 4 5))