Merge commit 'e47ddca2f8d80145386a377fc81a738d89c46cf0'
[jackhill/mal.git] / tests / step1_read_print.mal
1 ;; Testing read of nil/true/false
2 nil
3 ;=>nil
4 true
5 ;=>true
6 false
7 ;=>false
8
9
10 ;; Testing read of numbers
11 1
12 ;=>1
13 7
14 ;=>7
15 7
16 ;=>7
17
18
19 ;; Testing read of symbols
20 +
21 ;=>+
22 abc
23 ;=>abc
24 abc
25 ;=>abc
26 abc5
27 ;=>abc5
28 abc-def
29 ;=>abc-def
30
31
32 ;; Testing read of strings
33 "abc"
34 ;=>"abc"
35 "abc"
36 ;=>"abc"
37 "abc (with parens)"
38 ;=>"abc (with parens)"
39 "abc\"def"
40 ;=>"abc\"def"
41 ;;;"abc\ndef"
42 ;;;;=>"abc\ndef"
43
44
45 ;; Testing read of lists
46 (+ 1 2)
47 ;=>(+ 1 2)
48 ((3 4))
49 ;=>((3 4))
50 (+ 1 (+ 2 3))
51 ;=>(+ 1 (+ 2 3))
52 ( + 1 (+ 2 3 ) )
53 ;=>(+ 1 (+ 2 3))
54
55 ;; Testing read of vectors
56 [+ 1 2]
57 ;=>[+ 1 2]
58 [[3 4]]
59 ;=>[[3 4]]
60 [+ 1 [+ 2 3]]
61 ;=>[+ 1 [+ 2 3]]
62 [ + 1 [+ 2 3 ] ]
63 ;=>[+ 1 [+ 2 3]]
64
65 ;; Testing read of hash maps
66 {"abc" 1}
67 ;=>{"abc" 1}
68 {"a" {"b" 2}}
69 ;=>{"a" {"b" 2}}
70 {"a" {"b" {"c" 3}}}
71 ;=>{"a" {"b" {"c" 3}}}
72 { "a" {"b" { "cde" 3 } }}
73 ;=>{"a" {"b" {"cde" 3}}}
74
75 ;; Test commas as whitespace
76 [1 2, 3,,,,],,
77 ;=>[1 2 3]
78
79 ;;
80 ;; Testing reader errors
81 (1 2
82 ; expected ')', got EOF
83 [1 2
84 ; expected ']', got EOF
85 "abc
86 ; expected '"', got EOF
87
88 ;;
89 ;; -------- Optional Functionality --------
90
91 ;; Testing read of comments
92 ;; whole line comment (not an exception)
93 1 ; comment after expression
94 ;=>1
95 1; comment after expression
96 ;=>1
97
98 ;; Testing read of quoting
99 '1
100 ;=>(quote 1)
101 '(1 2 3)
102 ;=>(quote (1 2 3))
103 `1
104 ;=>(quasiquote 1)
105 `(1 2 3)
106 ;=>(quasiquote (1 2 3))
107 ~1
108 ;=>(unquote 1)
109 ~(1 2 3)
110 ;=>(unquote (1 2 3))
111 ~@(1 2 3)
112 ;=>(splice-unquote (1 2 3))
113
114
115 ;; Testing read of ^/metadata
116 ^{"a" 1} [1 2 3]
117 ;=>(with-meta [1 2 3] {"a" 1})
118
119
120 ;; Testing read of @/deref
121 @a
122 ;=>(deref a)