mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-05 18:21:40 +03:00
Add general tests for sumtype matching
This commit is contained in:
parent
f4f94a2f26
commit
9ee9f5fe57
34
test/sumtypes.carp
Normal file
34
test/sumtypes.carp
Normal file
@ -0,0 +1,34 @@
|
||||
;; Generic tests on sumtypes.
|
||||
|
||||
(load "Test.carp")
|
||||
(use Test)
|
||||
|
||||
(deftype A (F [(Fn [] Int)]))
|
||||
(deftype (Nest a) (Nested [a]))
|
||||
|
||||
(def nest (Nest.Nested (Nest.Nested (Nest.Nested 123))))
|
||||
|
||||
(defn one-two-three [] 123)
|
||||
|
||||
(defn m [a]
|
||||
(match a
|
||||
(A.F f) (f)))
|
||||
|
||||
(deftest test
|
||||
(assert-equal test
|
||||
123
|
||||
(m (A.F one-two-three))
|
||||
"match adds lhs bindings to inner environments")
|
||||
(assert-equal test
|
||||
"matched!"
|
||||
(match nest
|
||||
(Nest.Nested (Nest.Nested (Nest.Nested _)))
|
||||
"matched!")
|
||||
"Match matches nested sumtype constructors with underscores")
|
||||
(assert-equal test
|
||||
123
|
||||
(match nest
|
||||
(Nest.Nested (Nest.Nested (Nest.Nested x)))
|
||||
x)
|
||||
"Match matches nested sumtype constructors with variables")
|
||||
)
|
Loading…
Reference in New Issue
Block a user