Basic: pass required tests. Printer fix.
[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
25 ;; Testing read of lists
26 (+ 1 2)
27 ;=>(+ 1 2)
28 ()
29 ;=>()
30 (nil)
31 ;=>(nil)
32 ((3 4))
33 ;=>((3 4))
34 (+ 1 (+ 2 3))
35 ;=>(+ 1 (+ 2 3))
36 ( + 1 (+ 2 3 ) )
37 ;=>(+ 1 (+ 2 3))
38 (* 1 2)
39 ;=>(* 1 2)
40 (** 1 2)
41 ;=>(** 1 2)
42 (* -3 6)
43 ;=>(* -3 6)
44
45 ;; Test commas as whitespace
46 (1 2, 3,,,,),,
47 ;=>(1 2 3)
48
49
50 ;>>> deferrable=True
51
52 ;;
53 ;; -------- Deferrable Functionality --------
54
55 ;; Testing read of nil/true/false
56 nil
57 ;=>nil
58 true
59 ;=>true
60 false
61 ;=>false
62
63 ;; Testing read of strings
64 "abc"
65 ;=>"abc"
66 "abc"
67 ;=>"abc"
68 "abc (with parens)"
69 ;=>"abc (with parens)"
70 "abc\"def"
71 ;=>"abc\"def"
72 ;;;"abc\ndef"
73 ;;;;=>"abc\ndef"
74 ""
75 ;=>""
76
77 ;; Testing reader errors
78 ;;; TODO: fix these so they fail correctly
79 (1 2
80 ; expected ')', got EOF
81 [1 2
82 ; expected ']', got EOF
83 "abc
84 ; expected '"', got EOF
85 (1 "abc
86 ; expected ')', got EOF
87
88 ;; Testing read of quoting
89 '1
90 ;=>(quote 1)
91 '(1 2 3)
92 ;=>(quote (1 2 3))
93 `1
94 ;=>(quasiquote 1)
95 `(1 2 3)
96 ;=>(quasiquote (1 2 3))
97 ~1
98 ;=>(unquote 1)
99 ~(1 2 3)
100 ;=>(unquote (1 2 3))
101 `(1 ~a 3)
102 ;=>(quasiquote (1 (unquote a) 3))
103 ~@(1 2 3)
104 ;=>(splice-unquote (1 2 3))
105
106
107 ;>>> optional=True
108 ;;
109 ;; -------- Optional Functionality --------
110
111 ;; Testing keywords
112 :kw
113 ;=>:kw
114 (:kw1 :kw2 :kw3)
115 ;=>(:kw1 :kw2 :kw3)
116
117 ;; Testing read of vectors
118 [+ 1 2]
119 ;=>[+ 1 2]
120 []
121 ;=>[]
122 [[3 4]]
123 ;=>[[3 4]]
124 [+ 1 [+ 2 3]]
125 ;=>[+ 1 [+ 2 3]]
126 [ + 1 [+ 2 3 ] ]
127 ;=>[+ 1 [+ 2 3]]
128
129 ;; Testing read of hash maps
130 {"abc" 1}
131 ;=>{"abc" 1}
132 {"a" {"b" 2}}
133 ;=>{"a" {"b" 2}}
134 {"a" {"b" {"c" 3}}}
135 ;=>{"a" {"b" {"c" 3}}}
136 { "a" {"b" { "cde" 3 } }}
137 ;=>{"a" {"b" {"cde" 3}}}
138 { :a {:b { :cde 3 } }}
139 ;=>{:a {:b {:cde 3}}}
140
141 ;; Testing read of comments
142 ;; whole line comment (not an exception)
143 1 ; comment after expression
144 ;=>1
145 1; comment after expression
146 ;=>1
147
148 ;; Testing read of ^/metadata
149 ^{"a" 1} [1 2 3]
150 ;=>(with-meta [1 2 3] {"a" 1})
151
152
153 ;; Testing read of @/deref
154 @a
155 ;=>(deref a)