blob: 985b5fbf0f315e935736019b90ce9a448b4d06c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
|
;; Testing read of nil/true/false
nil
;=>nil
true
;=>true
false
;=>false
;; Testing read of numbers
1
;=>1
7
;=>7
7
;=>7
;; Testing read of symbols
+
;=>+
abc
;=>abc
abc
;=>abc
abc5
;=>abc5
abc-def
;=>abc-def
;; Testing read of strings
"abc"
;=>"abc"
"abc"
;=>"abc"
"abc (with parens)"
;=>"abc (with parens)"
"abc\"def"
;=>"abc\"def"
;;;"abc\ndef"
;;;;=>"abc\ndef"
""
;=>""
;; Testing read of lists
(+ 1 2)
;=>(+ 1 2)
((3 4))
;=>((3 4))
(+ 1 (+ 2 3))
;=>(+ 1 (+ 2 3))
( + 1 (+ 2 3 ) )
;=>(+ 1 (+ 2 3))
(* 1 2)
;=>(* 1 2)
(** 1 2)
;=>(** 1 2)
;; Test commas as whitespace
(1 2, 3,,,,),,
;=>(1 2 3)
;; Testing read of quoting
'1
;=>(quote 1)
'(1 2 3)
;=>(quote (1 2 3))
`1
;=>(quasiquote 1)
`(1 2 3)
;=>(quasiquote (1 2 3))
~1
;=>(unquote 1)
~(1 2 3)
;=>(unquote (1 2 3))
~@(1 2 3)
;=>(splice-unquote (1 2 3))
;;
;; Testing reader errors
;;; TODO: fix these so they fail correctly
(1 2
; expected ')', got EOF
[1 2
; expected ']', got EOF
"abc
; expected '"', got EOF
;;
;; -------- Optional Functionality --------
;; Testing keywords
:kw
;=>:kw
(:kw1 :kw2 :kw3)
;=>(:kw1 :kw2 :kw3)
;; Testing read of vectors
[+ 1 2]
;=>[+ 1 2]
[[3 4]]
;=>[[3 4]]
[+ 1 [+ 2 3]]
;=>[+ 1 [+ 2 3]]
[ + 1 [+ 2 3 ] ]
;=>[+ 1 [+ 2 3]]
;; Testing read of hash maps
{"abc" 1}
;=>{"abc" 1}
{"a" {"b" 2}}
;=>{"a" {"b" 2}}
{"a" {"b" {"c" 3}}}
;=>{"a" {"b" {"c" 3}}}
{ "a" {"b" { "cde" 3 } }}
;=>{"a" {"b" {"cde" 3}}}
{ :a {:b { :cde 3 } }}
;=>{:a {:b {:cde 3}}}
;; Testing read of comments
;; whole line comment (not an exception)
1 ; comment after expression
;=>1
1; comment after expression
;=>1
;; Testing read of ^/metadata
^{"a" 1} [1 2 3]
;=>(with-meta [1 2 3] {"a" 1})
;; Testing read of @/deref
@a
;=>(deref a)
|