runtest: Don't worry about how implementation echoes input
[jackhill/mal.git] / impls / tests / step1_read_print.mal
1 ;; Testing read of numbers
2 1
3 ;=>1
4 7
5 ;=>7
6 7
7 ;=>7
8 -123
9 ;=>-123
10
11
12 ;; Testing read of symbols
13 +
14 ;=>+
15 abc
16 ;=>abc
17 abc
18 ;=>abc
19 abc5
20 ;=>abc5
21 abc-def
22 ;=>abc-def
23
24 ;; Testing non-numbers starting with a dash.
25 -
26 ;=>-
27 -abc
28 ;=>-abc
29 ->>
30 ;=>->>
31
32 ;; Testing read of lists
33 (+ 1 2)
34 ;=>(+ 1 2)
35 ()
36 ;=>()
37 ( )
38 ;=>()
39 (nil)
40 ;=>(nil)
41 ((3 4))
42 ;=>((3 4))
43 (+ 1 (+ 2 3))
44 ;=>(+ 1 (+ 2 3))
45 ( + 1 (+ 2 3 ) )
46 ;=>(+ 1 (+ 2 3))
47 (* 1 2)
48 ;=>(* 1 2)
49 (** 1 2)
50 ;=>(** 1 2)
51 (* -3 6)
52 ;=>(* -3 6)
53 (()())
54 ;=>(() ())
55
56 ;; Test commas as whitespace
57 (1 2, 3,,,,),,
58 ;=>(1 2 3)
59
60
61 ;>>> deferrable=True
62
63 ;;
64 ;; -------- Deferrable Functionality --------
65
66 ;; Testing read of nil/true/false
67 nil
68 ;=>nil
69 true
70 ;=>true
71 false
72 ;=>false
73
74 ;; Testing read of strings
75 "abc"
76 ;=>"abc"
77 "abc"
78 ;=>"abc"
79 "abc (with parens)"
80 ;=>"abc (with parens)"
81 "abc\"def"
82 ;=>"abc\"def"
83 ""
84 ;=>""
85 "\\"
86 ;=>"\\"
87 "\\\\\\\\\\\\\\\\\\"
88 ;=>"\\\\\\\\\\\\\\\\\\"
89 "&"
90 ;=>"&"
91 "'"
92 ;=>"'"
93 "("
94 ;=>"("
95 ")"
96 ;=>")"
97 "*"
98 ;=>"*"
99 "+"
100 ;=>"+"
101 ","
102 ;=>","
103 "-"
104 ;=>"-"
105 "/"
106 ;=>"/"
107 ":"
108 ;=>":"
109 ";"
110 ;=>";"
111 "<"
112 ;=>"<"
113 "="
114 ;=>"="
115 ">"
116 ;=>">"
117 "?"
118 ;=>"?"
119 "@"
120 ;=>"@"
121 "["
122 ;=>"["
123 "]"
124 ;=>"]"
125 "^"
126 ;=>"^"
127 "_"
128 ;=>"_"
129 "`"
130 ;=>"`"
131 "{"
132 ;=>"{"
133 "}"
134 ;=>"}"
135 "~"
136 ;=>"~"
137
138 ;; Testing reader errors
139 (1 2
140 ;/.*(EOF|end of input|unbalanced).*
141 [1 2
142 ;/.*(EOF|end of input|unbalanced).*
143
144 ;;; These should throw some error with no return value
145 "abc
146 ;/.*(EOF|end of input|unbalanced).*
147 "
148 ;/.*(EOF|end of input|unbalanced).*
149 "\"
150 ;/.*(EOF|end of input|unbalanced).*
151 "\\\\\\\\\\\\\\\\\\\"
152 ;/.*(EOF|end of input|unbalanced).*
153 (1 "abc
154 ;/.*(EOF|end of input|unbalanced).*
155 (1 "abc"
156 ;/.*(EOF|end of input|unbalanced).*
157
158 ;; Testing read of quoting
159 '1
160 ;=>(quote 1)
161 '(1 2 3)
162 ;=>(quote (1 2 3))
163 `1
164 ;=>(quasiquote 1)
165 `(1 2 3)
166 ;=>(quasiquote (1 2 3))
167 ~1
168 ;=>(unquote 1)
169 ~(1 2 3)
170 ;=>(unquote (1 2 3))
171 `(1 ~a 3)
172 ;=>(quasiquote (1 (unquote a) 3))
173 ~@(1 2 3)
174 ;=>(splice-unquote (1 2 3))
175
176
177 ;; Testing keywords
178 :kw
179 ;=>:kw
180 (:kw1 :kw2 :kw3)
181 ;=>(:kw1 :kw2 :kw3)
182
183 ;; Testing read of vectors
184 [+ 1 2]
185 ;=>[+ 1 2]
186 []
187 ;=>[]
188 [ ]
189 ;=>[]
190 [[3 4]]
191 ;=>[[3 4]]
192 [+ 1 [+ 2 3]]
193 ;=>[+ 1 [+ 2 3]]
194 [ + 1 [+ 2 3 ] ]
195 ;=>[+ 1 [+ 2 3]]
196 ([])
197 ;=>([])
198
199 ;; Testing read of hash maps
200 {}
201 ;=>{}
202 { }
203 ;=>{}
204 {"abc" 1}
205 ;=>{"abc" 1}
206 {"a" {"b" 2}}
207 ;=>{"a" {"b" 2}}
208 {"a" {"b" {"c" 3}}}
209 ;=>{"a" {"b" {"c" 3}}}
210 { "a" {"b" { "cde" 3 } }}
211 ;=>{"a" {"b" {"cde" 3}}}
212 ;;; The regexp sorcery here ensures that each key goes with the correct
213 ;;; value and that each key appears only once.
214 {"a1" 1 "a2" 2 "a3" 3}
215 ;/{"a([1-3])" \1 "a(?!\1)([1-3])" \2 "a(?!\1)(?!\2)([1-3])" \3}
216 { :a {:b { :cde 3 } }}
217 ;=>{:a {:b {:cde 3}}}
218 {"1" 1}
219 ;=>{"1" 1}
220 ({})
221 ;=>({})
222
223 ;; Testing read of comments
224 ;; whole line comment (not an exception)
225 1 ; comment after expression
226 ;=>1
227 1; comment after expression
228 ;=>1
229
230 ;; Testing read of @/deref
231 @a
232 ;=>(deref a)
233
234 ;>>> soft=True
235 ;>>> optional=True
236 ;;
237 ;; -------- Optional Functionality --------
238
239 ;; Testing read of ^/metadata
240 ^{"a" 1} [1 2 3]
241 ;=>(with-meta [1 2 3] {"a" 1})
242
243
244 ;; Non alphanumerice characters in strings
245 ;;; \t is not specified enough to be tested
246 "\n"
247 ;=>"\n"
248 "#"
249 ;=>"#"
250 "$"
251 ;=>"$"
252 "%"
253 ;=>"%"
254 "."
255 ;=>"."
256 "\\"
257 ;=>"\\"
258 "|"
259 ;=>"|"
260
261 ;; Non alphanumeric characters in comments
262 1;!
263 ;=>1
264 1;"
265 ;=>1
266 1;#
267 ;=>1
268 1;$
269 ;=>1
270 1;%
271 ;=>1
272 1;'
273 ;=>1
274 1;\
275 ;=>1
276 1;\\
277 ;=>1
278 1;\\\
279 ;=>1
280 1;`
281 ;=>1
282 ;;; Hopefully less problematic characters
283 1; &()*+,-./:;<=>?@[]^_{|}~
284
285 ;; FIXME: These tests have no reasons to be optional, but...
286 ;; fantom fails this one
287 "!"
288 ;=>"!"