Merge pull request #402 from bjh21/bjh21-unterminated-string-fixes
[jackhill/mal.git] / 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 ;;;"abc\ndef"
84 ;;;;=>"abc\ndef"
85 ""
86 ;=>""
87
88 ;; Testing reader errors
89 (1 2
90 ;/.*(EOF|end of input|unbalanced).*
91 [1 2
92 ;/.*(EOF|end of input|unbalanced).*
93
94 ;;; These should throw some error with no return value
95 "abc
96 ;/.*(EOF|end of input|unbalanced).*
97 (1 "abc
98 ;/.*(EOF|end of input|unbalanced).*
99 (1 "abc"
100 ;/.*(EOF|end of input|unbalanced).*
101
102 ;; Testing read of quoting
103 '1
104 ;=>(quote 1)
105 '(1 2 3)
106 ;=>(quote (1 2 3))
107 `1
108 ;=>(quasiquote 1)
109 `(1 2 3)
110 ;=>(quasiquote (1 2 3))
111 ~1
112 ;=>(unquote 1)
113 ~(1 2 3)
114 ;=>(unquote (1 2 3))
115 `(1 ~a 3)
116 ;=>(quasiquote (1 (unquote a) 3))
117 ~@(1 2 3)
118 ;=>(splice-unquote (1 2 3))
119
120
121 ;>>> optional=True
122 ;;
123 ;; -------- Optional Functionality --------
124
125 ;; Testing keywords
126 :kw
127 ;=>:kw
128 (:kw1 :kw2 :kw3)
129 ;=>(:kw1 :kw2 :kw3)
130
131 ;; Testing read of vectors
132 [+ 1 2]
133 ;=>[+ 1 2]
134 []
135 ;=>[]
136 [ ]
137 ;=>[]
138 [[3 4]]
139 ;=>[[3 4]]
140 [+ 1 [+ 2 3]]
141 ;=>[+ 1 [+ 2 3]]
142 [ + 1 [+ 2 3 ] ]
143 ;=>[+ 1 [+ 2 3]]
144 ([])
145 ;=>([])
146
147 ;; Testing read of hash maps
148 {}
149 ;=>{}
150 { }
151 ;=>{}
152 {"abc" 1}
153 ;=>{"abc" 1}
154 {"a" {"b" 2}}
155 ;=>{"a" {"b" 2}}
156 {"a" {"b" {"c" 3}}}
157 ;=>{"a" {"b" {"c" 3}}}
158 { "a" {"b" { "cde" 3 } }}
159 ;=>{"a" {"b" {"cde" 3}}}
160 ;;; The regexp sorcery here ensures that each key goes with the correct
161 ;;; value and that each key appears only once.
162 {"a1" 1 "a2" 2 "a3" 3}
163 ;/{"a([1-3])" \1 "a(?!\1)([1-3])" \2 "a(?!\1)(?!\2)([1-3])" \3}
164 { :a {:b { :cde 3 } }}
165 ;=>{:a {:b {:cde 3}}}
166 ({})
167 ;=>({})
168
169 ;; Testing read of comments
170 ;; whole line comment (not an exception)
171 1 ; comment after expression
172 ;=>1
173 1; comment after expression
174 ;=>1
175
176 ;; Testing read of ^/metadata
177 ^{"a" 1} [1 2 3]
178 ;=>(with-meta [1 2 3] {"a" 1})
179
180
181 ;; Testing read of @/deref
182 @a
183 ;=>(deref a)