Update from master
[jackhill/mal.git] / tests / step7_quote.mal
1 ;; Testing cons function
2 (cons 1 (list))
3 ;=>(1)
4 (cons 1 (list 2))
5 ;=>(1 2)
6 (cons 1 (list 2 3))
7 ;=>(1 2 3)
8 (cons (list 1) (list 2 3))
9 ;=>((1) 2 3)
10
11 (def! a (list 2 3))
12 (cons 1 a)
13 ;=>(1 2 3)
14 a
15 ;=>(2 3)
16
17 ;; Testing concat function
18 (concat)
19 ;=>()
20 (concat (list 1 2))
21 ;=>(1 2)
22 (concat (list 1 2) (list 3 4))
23 ;=>(1 2 3 4)
24 (concat (list 1 2) (list 3 4) (list 5 6))
25 ;=>(1 2 3 4 5 6)
26 (concat (concat))
27 ;=>()
28
29 (def! a (list 1 2))
30 (def! b (list 3 4))
31 (concat a b (list 5 6))
32 ;=>(1 2 3 4 5 6)
33 a
34 ;=>(1 2)
35 b
36 ;=>(3 4)
37
38 ;; Testing regular quote
39 (quote 7)
40 ;=>7
41 '7
42 ;=>7
43 (quote (1 2 3))
44 ;=>(1 2 3)
45 '(1 2 3)
46 ;=>(1 2 3)
47 (quote (1 2 (3 4)))
48 ;=>(1 2 (3 4))
49 '(1 2 (3 4))
50 ;=>(1 2 (3 4))
51
52
53 ;; Testing simple quasiquote
54 (quasiquote 7)
55 ;=>7
56 `7
57 ;=>7
58 (quasiquote (1 2 3))
59 ;=>(1 2 3)
60 `(1 2 3)
61 ;=>(1 2 3)
62 (quasiquote (1 2 (3 4)))
63 ;=>(1 2 (3 4))
64 `(1 2 (3 4))
65 ;=>(1 2 (3 4))
66 (quasiquote (nil))
67 ;=>(nil)
68 `(nil)
69 ;=>(nil)
70
71
72 ;; Testing unquote
73 `~7
74 ;=>7
75 (def! a 8)
76 ;=>8
77 `a
78 ;=>a
79 `~a
80 ;=>8
81 `(1 a 3)
82 ;=>(1 a 3)
83 `(1 ~a 3)
84 ;=>(1 8 3)
85 (def! b '(1 "b" "d"))
86 ;=>(1 "b" "d")
87 `(1 b 3)
88 ;=>(1 b 3)
89 `(1 ~b 3)
90 ;=>(1 (1 "b" "d") 3)
91
92
93 ;; Testing splice-unquote
94 (def! c '(1 "b" "d"))
95 ;=>(1 "b" "d")
96 `(1 c 3)
97 ;=>(1 c 3)
98 `(1 ~@c 3)
99 ;=>(1 1 "b" "d" 3)
100
101
102 ;; Testing symbol equality
103 (= 'abc 'abc)
104 ;=>true
105 (= 'abc 'abcd)
106 ;=>false
107 (= 'abc "abc")
108 ;=>false
109 (= "abc" 'abc)
110 ;=>false
111 (= "abc" (str 'abc))
112 ;=>true
113 (= 'abc nil)
114 ;=>false
115 (= nil 'abc)
116 ;=>false
117
118 ;;;;; Test quine
119 ;;; TODO: needs expect line length fix
120 ;;;((fn* [q] (quasiquote ((unquote q) (quote (unquote q))))) (quote (fn* [q] (quasiquote ((unquote q) (quote (unquote q)))))))
121 ;;;=>((fn* [q] (quasiquote ((unquote q) (quote (unquote q))))) (quote (fn* [q] (quasiquote ((unquote q) (quote (unquote q)))))))
122
123 ;;
124 ;; -------- Optional Functionality --------
125
126 ;; Testing cons, concat, first, rest with vectors
127
128 (cons [1] [2 3])
129 ;=>([1] 2 3)
130 (cons 1 [2 3])
131 ;=>(1 2 3)
132 (concat [1 2] (list 3 4) [5 6])
133 ;=>(1 2 3 4 5 6)
134
135 ;; Testing unquote with vectors
136 (def! a 8)
137 ;=>8
138 `[1 a 3]
139 ;=>(1 a 3)
140 ;;; TODO: fix this
141 ;;;;=>[1 a 3]
142
143 ;; Testing splice-unquote with vectors
144 (def! c '(1 "b" "d"))
145 ;=>(1 "b" "d")
146 `[1 ~@c 3]
147 ;=>(1 1 "b" "d" 3)
148 ;;; TODO: fix this
149 ;;;;=>[1 1 "b" "d" 3]
150