Skip to content

Commit

Permalink
added tests for match with num types
Browse files Browse the repository at this point in the history
  • Loading branch information
Yarin Heffes authored and YarinHeffes committed Jan 17, 2025
1 parent 2df3c41 commit 85594ba
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion tests/pattern-matching-tests.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,29 @@
(match x
(0 "zero")
(1 "one")
(2 "two")))))
(2 "two")
(_ "error")))))
(is (== (f 0)
"zero"))
(is (== (f 1)
"one"))
(is (== (f 2)
"two"))))

(define-test test-match-on-nums ()

(let ((f (fn (x)
(match x
(0 "zero")
(1 "one")
(2 "two")))))
(is (== (f (the IFix 0))
"zero"))
(is (== (f (the U8 1))
"one"))
(is (== (f (the I16 2))
"two"))))

(define-test test-match-lists ()
(let ((f (fn (xs)
(match xs
Expand All @@ -34,7 +49,27 @@
(is (== (f (MFoo 9)) 9))
(is (== (f (MBar (Tuple 7 8))) 7))))

(define-test test-match-on-fractions ()
(is (match 1/4
(1/4 True)
(_ False))))

(define-test test-match-on-single-floats ()
(is (match 0.15f0
(0.15f0 True)
(_ False))))

(define-test test-match-on-double-floats ()
(is (match 0.15d0
(0.15d0 True)
(_ False))))

(define-test test-match-on-strings ()
(is (match "red"
("red" True)
(_ False))))

(define-test test-match-on-chars ()
(is (match #\c
(#\c True)
(_ False))))

0 comments on commit 85594ba

Please sign in to comment.