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