-
Notifications
You must be signed in to change notification settings - Fork 3
/
pp-toml-tests.lisp
223 lines (180 loc) · 5.34 KB
/
pp-toml-tests.lisp
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
(defpackage :pp-toml-tests
(:use :common-lisp
:pp-toml
:fiveam
:generic-comparability)
(:export :run-tests))
(in-package :pp-toml-tests)
(use-package :pp-toml)
(def-suite pp-toml-suite
:description "The tests.")
(in-suite pp-toml-suite)
(defun run-tests ()
(let ((results (run 'pp-toml-suite)))
(explain! results)
(results-status results)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(test keygroup-tests
(is (esrap:parse 'keygroup "[foo.bar]
"))
(is (esrap:parse 'keygroup "[foo]
")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(test keyvalue-tests
(is (esrap:parse 'keyvalue "title = \"TOML Example\"
" ))
(is (esrap:parse 'keyvalue "
title = \"TOML Example\"
" )))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(test preamble-tests
(is (esrap:parse 'preamble
"title = \"TOML Example\"
bunco = false
billy = 1
")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(test comment-tests
(let ((basic "Foooo"))
(is (string= basic
(strip-comments basic))))
(let ((input "Hi #comment")
(expected "Hi "))
(is (string= expected
(strip-comments input))))
(let ((input "\"With #comment\"")
(expected "\"With #comment\"" ))
(is (string= expected
(strip-comments input))))
(let ((input "\"With #comment\" #trailing")
(expected "\"With #comment\" " ))
(is (string= expected
(strip-comments input))))
;; Let's go hardmode
(let ((input "\"With #comment\" #trailing #comment")
(expected "\"With #comment\" " ))
(is (string= expected
(strip-comments input))))
;; Challenge mode accepted
(let ((input "\"With #comment\" #A trailing \"str # ing\" here")
(expected "\"With #comment\" " ))
(is (string= expected
(strip-comments input))))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(test multi-line-tests
(is (esrap:parse 'preamble "thing2 = \"other\nthing\"
"))
(is (pp-toml:parse-string "thing2 = \"other\nthing\"
"))
(is (pp-toml:parse-string "bio = \"GitHub Cofounder & CEO\nLikes tater tots and beer.\"
dob=1979-05-27T07:32:00Z
dob2 = 2013-10-22T07:32:00Z
"
))
)
(test datetime-tests
(is
(esrap:parse 'datetime "1979-05-27T07:32:00Z"))
(is
(esrap:parse 'value "1980-05-27T07:32:00Z"))
(is
(esrap:parse 'keyvalue "dt = 1981-05-27T07:32:00Z
"))
(is (esrap:parse 'datetime "1979-05-27T00:32:00-07:00"))
(is (esrap:parse 'datetime "1979-05-27T00:32:00.999999-07:00"))
)
(defun collect (&rest chars)
(format nil "~{~c~}" chars))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(test value-tests
(is (esrap:parse 'value "1983-05-27T07:32:00Z"))
(is (esrap:parse 'value "1"))
(is (esrap:parse 'value "10.1"))
(is (esrap:parse 'value "true"))
(is (esrap:parse 'value "false"))
(is (esrap:parse 'value "[1]"))
(is (esrap:parse 'value "[1,1]"))
(is (esrap:parse 'value "[1,2,]"))
(is (esrap:parse 'value "[[3],2,]"))
(is (esrap:parse 'value "[1,[4],[5,5,],1]"))
;; string equality checks
(is (equalp '(:string "aabb")
(esrap:parse 'value "\"aabb\"")))
(is (equalp '(:string "anoto")
(esrap:parse 'value "\"anoto\"")))
(is (equalp (list
:string
(collect #\X #\X #\Backspace #\Y #\Y))
(esrap:parse 'value "\"XX\\bYY\"")))
(is (equalp (list
:string
(collect #\X #\X #\Tab #\Y #\Y))
(esrap:parse 'value "\"XX\\tYY\"")))
(is (equalp (list
:string
(collect #\X #\X #\Newline #\Y #\Y))
(esrap:parse 'value "\"XX\\nYY\"")))
(is (equalp (list
:string
(collect #\X #\X #\Return #\Y #\Y))
(esrap:parse 'value "\"XX\\rYY\"")))
;; \"
(is (equalp (list
:string
(collect #\X #\X #\" #\Y #\Y))
(esrap:parse 'value "\"XX\\\"YY\"")))
;; Currently failing - the \/ isn't getting translated into /
;; (is (equalp (list
;; :string
;; (collect #\X #\X #\/ #\Y #\Y))
;; (esrap:parse 'value "\"XX\\/YY\"")))
(is (equalp (list
:string
(collect #\X #\X #\\ #\Y #\Y))
(esrap:parse 'value "\"XX\\\YY\"")))
(is (equalp (list
:string
(collect #\X #\X (code-char 3456) #\Y #\Y))
(esrap:parse 'value "\"XX\\u3456YY\"")))
(is (equal '(:string "abcd") (esrap:parse 'value "'abcd'")))
(is (equal '(:string "ab\"cd") (esrap:parse 'value "'ab\"cd'"))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(test parse-tests
(is
(pp-toml:parse-string "title = \"TOML Example\"
[foo]
baffle = 1
binky=true
blaq=\"beautiful\"
"))
(pp-toml:parse-string
"
title = \"TOML Example\"
[owner]
name = \"Tom Preston-Werner\"
organization = \"GitHub\"
bio = \"GitHub Cofounder & CEO\nLikes tater tots and beer.\"
dob = 1979-05-27T07:32:00Z
[database]
server = \"192.168.1.1\"
ports = [ 8001, 8001, 8002 ]
connection_max = 5000
enabled = true
[servers]
[servers.alpha]
ip = \"10.0.0.1\"
dc = \"eqdc10\"
[servers.beta]
ip = \"10.0.0.2\"
dc = \"eqdc10\"
"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(test top-level-tests
(is (equals (pp-toml:parse-toml " ")
(make-hash-table :test #'equal)))
(is (equals (pp-toml:parse-toml "# fooo ")
(make-hash-table :test #'equal)))
(is (equals (pp-toml:parse-toml "# fooo
# bar ")
(make-hash-table :test #'equal))))