step 7 test: Correct a heading to match contents.
[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 (concat (list) (list))
29 ;=>()
30
31 (def! a (list 1 2))
32 (def! b (list 3 4))
33 (concat a b (list 5 6))
34 ;=>(1 2 3 4 5 6)
35 a
36 ;=>(1 2)
37 b
38 ;=>(3 4)
39
40 ;; Testing regular quote
41 (quote 7)
42 ;=>7
43 (quote (1 2 3))
44 ;=>(1 2 3)
45 (quote (1 2 (3 4)))
46 ;=>(1 2 (3 4))
47
48 ;; Testing simple quasiquote
49 (quasiquote 7)
50 ;=>7
51 (quasiquote (1 2 3))
52 ;=>(1 2 3)
53 (quasiquote (1 2 (3 4)))
54 ;=>(1 2 (3 4))
55 (quasiquote (nil))
56 ;=>(nil)
57
58 ;; Testing unquote
59 (quasiquote (unquote 7))
60 ;=>7
61 (def! a 8)
62 ;=>8
63 (quasiquote a)
64 ;=>a
65 (quasiquote (unquote a))
66 ;=>8
67 (quasiquote (1 a 3))
68 ;=>(1 a 3)
69 (quasiquote (1 (unquote a) 3))
70 ;=>(1 8 3)
71 (def! b (quote (1 "b" "d")))
72 ;=>(1 "b" "d")
73 (quasiquote (1 b 3))
74 ;=>(1 b 3)
75 (quasiquote (1 (unquote b) 3))
76 ;=>(1 (1 "b" "d") 3)
77 (quasiquote ((unquote 1) (unquote 2)))
78 ;=>(1 2)
79
80 ;; Testing splice-unquote
81 (def! c (quote (1 "b" "d")))
82 ;=>(1 "b" "d")
83 (quasiquote (1 c 3))
84 ;=>(1 c 3)
85 (quasiquote (1 (splice-unquote c) 3))
86 ;=>(1 1 "b" "d" 3)
87
88
89 ;; Testing symbol equality
90 (= (quote abc) (quote abc))
91 ;=>true
92 (= (quote abc) (quote abcd))
93 ;=>false
94 (= (quote abc) "abc")
95 ;=>false
96 (= "abc" (quote abc))
97 ;=>false
98 (= "abc" (str (quote abc)))
99 ;=>true
100 (= (quote abc) nil)
101 ;=>false
102 (= nil (quote abc))
103 ;=>false
104
105 ;;;;; Test quine
106 ;;; TODO: needs expect line length fix
107 ;;;((fn* [q] (quasiquote ((unquote q) (quote (unquote q))))) (quote (fn* [q] (quasiquote ((unquote q) (quote (unquote q)))))))
108 ;;;=>((fn* [q] (quasiquote ((unquote q) (quote (unquote q))))) (quote (fn* [q] (quasiquote ((unquote q) (quote (unquote q)))))))
109
110 ;>>> deferrable=True
111 ;;
112 ;; -------- Deferrable Functionality --------
113
114 ;; Testing ' (quote) reader macro
115 '7
116 ;=>7
117 '(1 2 3)
118 ;=>(1 2 3)
119 '(1 2 (3 4))
120 ;=>(1 2 (3 4))
121
122 ;; Testing ` (quasiquote) reader macro
123 `7
124 ;=>7
125 `(1 2 3)
126 ;=>(1 2 3)
127 `(1 2 (3 4))
128 ;=>(1 2 (3 4))
129 `(nil)
130 ;=>(nil)
131
132 ;; Testing ~ (unquote) reader macro
133 `~7
134 ;=>7
135 (def! a 8)
136 ;=>8
137 `(1 ~a 3)
138 ;=>(1 8 3)
139 (def! b '(1 "b" "d"))
140 ;=>(1 "b" "d")
141 `(1 b 3)
142 ;=>(1 b 3)
143 `(1 ~b 3)
144 ;=>(1 (1 "b" "d") 3)
145
146 ;; Testing ~@ (splice-unquote) reader macro
147 (def! c '(1 "b" "d"))
148 ;=>(1 "b" "d")
149 `(1 c 3)
150 ;=>(1 c 3)
151 `(1 ~@c 3)
152 ;=>(1 1 "b" "d" 3)
153
154
155 ;>>> optional=True
156 ;;
157 ;; -------- Optional Functionality --------
158
159 ;; Testing cons and concat with vectors
160
161 (cons [1] [2 3])
162 ;=>([1] 2 3)
163 (cons 1 [2 3])
164 ;=>(1 2 3)
165 (concat [1 2] (list 3 4) [5 6])
166 ;=>(1 2 3 4 5 6)
167
168 ;; Testing unquote with vectors
169 (def! a 8)
170 ;=>8
171 `[1 a 3]
172 ;=>(1 a 3)
173 ;;; TODO: fix this
174 ;;;;=>[1 a 3]
175
176 ;; Testing splice-unquote with vectors
177 (def! c '(1 "b" "d"))
178 ;=>(1 "b" "d")
179 `[1 ~@c 3]
180 ;=>(1 1 "b" "d" 3)
181 ;;; TODO: fix this
182 ;;;;=>[1 1 "b" "d" 3]
183