Skip to content
Browse files

unstable/match: forgot the tests for 1a0a06d

  • Loading branch information...
1 parent 1a0a06d commit 59915409a569dd2205aff8851357f96d08bc7b1f @takikawa takikawa committed Sep 17, 2012
Showing with 43 additions and 0 deletions.
  1. +43 −0 collects/unstable/tests/match.rkt
View
43 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))

0 comments on commit 5991540

Please sign in to comment.
Something went wrong with that request. Please try again.