-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_hyskell.hy
56 lines (45 loc) · 1.02 KB
/
test_hyskell.hy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(require hyskell)
(require hytest)
(defunion Node
(Nint p ival)
(Nstr p sval))
(test-set test-accfor
(test = (list (accfor [x [1 2 3] y [4 5 6]] [x y]))
[[1 4] [1 5] [1 6] [2 4] [2 5] [2 6] [3 4] [3 5] [3 6]]))
(test-set test-defunion
(setv i (Nint 0 7))
(setv s (Nstr 1 "s"))
(test = i.ival 7)
(test = s.sval "s")
(test = i.p 0)
(test = s.p 1)
(test true (isinstance i Node))
(test true (isinstance s Node))
(test = i.-fields ["p" "ival"])
(test = s.-fields ["p" "sval"]))
(test-set test-match
(match [1 2 3]
[[1 2 3] nil])
(match [1 2 3]
[[1 :b 3] (test = b 2)])
(match [1 2 3]
[:v (test = v [1 2 3])])
(match [1 2 3]
[_ nil])
(match (, 1 2 3)
[(, :a :b 3)
(test = a 1)
(test = b 2)])
(match (Nint 0 2)
[(Nint :p 2) (test = p 0)])
(setv x 2)
(match 2 [x nil])
(match [1 2]
[[1 _] nil])
(match [1]
[[1 _] (fail-test "")]
[_ nil])
(match (Nint 1 2)
[(Nint) nil])
(match (Nint 1 2)
[(Nint (:p 1) (:ival 2)) nil]))