rison 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{COPYING.txt → License.txt} +2 -2
- data/README.md +40 -0
- data/Rakefile.rb +3 -79
- data/lib/rison/dump.rb +20 -29
- data/lib/rison/parslet_parser.rb +55 -0
- data/lib/rison/parslet_transform.rb +44 -0
- data/lib/rison.rb +8 -41
- data/rison.gemspec +13 -0
- data/spec/rison_dump_spec.rb +78 -0
- data/spec/rison_load_spec.rb +93 -0
- metadata +53 -53
- data/README.html +0 -57
- data/lib/rison/evaluator.rb +0 -172
- data/lib/rison/grammar.rb +0 -114
- data/lib/rison/lexer.rb +0 -33
- data/lib/rison/parser.rb +0 -360
- data/test/test_dump.rb +0 -70
- data/test/test_parser.rb +0 -106
data/lib/rison/parser.rb
DELETED
@@ -1,360 +0,0 @@
|
|
1
|
-
require 'dhaka'
|
2
|
-
require 'rison/grammar'
|
3
|
-
|
4
|
-
module Rison
|
5
|
-
class Parser < Dhaka::CompiledParser
|
6
|
-
|
7
|
-
self.grammar = Rison::Grammar
|
8
|
-
|
9
|
-
start_with 0
|
10
|
-
|
11
|
-
at_state(48) {
|
12
|
-
for_symbols("'") { shift_to 2 }
|
13
|
-
for_symbols("object") { shift_to 25 }
|
14
|
-
for_symbols("value") { shift_to 50 }
|
15
|
-
for_symbols("number") { shift_to 46 }
|
16
|
-
for_symbols("!") { shift_to 47 }
|
17
|
-
for_symbols("string") { shift_to 26 }
|
18
|
-
for_symbols("array") { shift_to 28 }
|
19
|
-
for_symbols("idstart") { shift_to 38 }
|
20
|
-
for_symbols("integer_token") { shift_to 5 }
|
21
|
-
for_symbols("!t") { shift_to 24 }
|
22
|
-
for_symbols(")") { shift_to 49 }
|
23
|
-
for_symbols("idstart_safe_token") { shift_to 14 }
|
24
|
-
for_symbols("!f") { shift_to 27 }
|
25
|
-
for_symbols("(") { shift_to 29 }
|
26
|
-
for_symbols("id") { shift_to 53 }
|
27
|
-
for_symbols("int") { shift_to 8 }
|
28
|
-
for_symbols("!n") { shift_to 1 }
|
29
|
-
for_symbols("elements") { shift_to 54 }
|
30
|
-
}
|
31
|
-
|
32
|
-
at_state(47) {
|
33
|
-
for_symbols("(") { shift_to 48 }
|
34
|
-
}
|
35
|
-
|
36
|
-
at_state(22) {
|
37
|
-
for_symbols(",", ":", "_End_", ")") { reduce_with "non_empty_string" }
|
38
|
-
}
|
39
|
-
|
40
|
-
at_state(19) {
|
41
|
-
for_symbols("!!", "idstart_safe_token", "integer_token", "!'", "'", "char_token", "idchar_safe_token") { reduce_with "strchar_num" }
|
42
|
-
}
|
43
|
-
|
44
|
-
at_state(5) {
|
45
|
-
for_symbols("!!", ",", "frac_token", "idstart_safe_token", "integer_token", ":", "!'", "_End_", "'", "exponent_token", "char_token", ")", "idchar_safe_token") { reduce_with "integer_literal" }
|
46
|
-
}
|
47
|
-
|
48
|
-
at_state(54) {
|
49
|
-
for_symbols(")") { shift_to 55 }
|
50
|
-
}
|
51
|
-
|
52
|
-
at_state(45) {
|
53
|
-
for_symbols(",", ")") { reduce_with "pair_key_value" }
|
54
|
-
}
|
55
|
-
|
56
|
-
at_state(41) {
|
57
|
-
for_symbols(",", ":", "_End_", ")") { reduce_with "idchars_idchars" }
|
58
|
-
}
|
59
|
-
|
60
|
-
at_state(31) {
|
61
|
-
for_symbols(",", "_End_", ")") { reduce_with "non_empty_object" }
|
62
|
-
}
|
63
|
-
|
64
|
-
at_state(8) {
|
65
|
-
for_symbols("exp") { shift_to 9 }
|
66
|
-
for_symbols("exponent_token") { shift_to 13 }
|
67
|
-
for_symbols("frac") { shift_to 11 }
|
68
|
-
for_symbols("frac_token") { shift_to 10 }
|
69
|
-
for_symbols("!!", ",", "idstart_safe_token", "integer_token", "!'", "_End_", "'", "char_token", ")", "idchar_safe_token") { reduce_with "number_int" }
|
70
|
-
}
|
71
|
-
|
72
|
-
at_state(7) {
|
73
|
-
for_symbols("!!", ",", "idstart_safe_token", "integer_token", ":", "!'", "_End_", "'", "char_token", ")", "idchar_safe_token") { reduce_with "idchar_char" }
|
74
|
-
}
|
75
|
-
|
76
|
-
at_state(53) {
|
77
|
-
for_symbols(",", "_End_", ")") { reduce_with "value_id" }
|
78
|
-
}
|
79
|
-
|
80
|
-
at_state(21) {
|
81
|
-
for_symbols("'") { shift_to 22 }
|
82
|
-
}
|
83
|
-
|
84
|
-
at_state(55) {
|
85
|
-
for_symbols(",", "_End_", ")") { reduce_with "non_empty_array" }
|
86
|
-
}
|
87
|
-
|
88
|
-
at_state(52) {
|
89
|
-
for_symbols(")") { reduce_with "element_values" }
|
90
|
-
}
|
91
|
-
|
92
|
-
at_state(44) {
|
93
|
-
for_symbols("'") { shift_to 2 }
|
94
|
-
for_symbols("object") { shift_to 25 }
|
95
|
-
for_symbols("number") { shift_to 46 }
|
96
|
-
for_symbols("!") { shift_to 47 }
|
97
|
-
for_symbols("string") { shift_to 26 }
|
98
|
-
for_symbols("array") { shift_to 28 }
|
99
|
-
for_symbols("idstart") { shift_to 38 }
|
100
|
-
for_symbols("value") { shift_to 45 }
|
101
|
-
for_symbols("integer_token") { shift_to 5 }
|
102
|
-
for_symbols("!t") { shift_to 24 }
|
103
|
-
for_symbols("idstart_safe_token") { shift_to 14 }
|
104
|
-
for_symbols("!f") { shift_to 27 }
|
105
|
-
for_symbols("(") { shift_to 29 }
|
106
|
-
for_symbols("id") { shift_to 53 }
|
107
|
-
for_symbols("int") { shift_to 8 }
|
108
|
-
for_symbols("!n") { shift_to 1 }
|
109
|
-
}
|
110
|
-
|
111
|
-
at_state(42) {
|
112
|
-
for_symbols(",", ":", "_End_", ")") { reduce_with "id_idstart_idchars" }
|
113
|
-
}
|
114
|
-
|
115
|
-
at_state(36) {
|
116
|
-
for_symbols("members") { shift_to 37 }
|
117
|
-
for_symbols("'") { shift_to 2 }
|
118
|
-
for_symbols("key") { shift_to 43 }
|
119
|
-
for_symbols("idstart") { shift_to 38 }
|
120
|
-
for_symbols("string") { shift_to 33 }
|
121
|
-
for_symbols("idstart_safe_token") { shift_to 14 }
|
122
|
-
for_symbols("pair") { shift_to 35 }
|
123
|
-
for_symbols("id") { shift_to 34 }
|
124
|
-
}
|
125
|
-
|
126
|
-
at_state(3) {
|
127
|
-
for_symbols(",", ":", "_End_", ")") { reduce_with "empty_string" }
|
128
|
-
}
|
129
|
-
|
130
|
-
at_state(39) {
|
131
|
-
for_symbols(",", ":", "_End_", ")") { reduce_with "idchars_int" }
|
132
|
-
}
|
133
|
-
|
134
|
-
at_state(35) {
|
135
|
-
for_symbols(",") { shift_to 36 }
|
136
|
-
for_symbols(")") { reduce_with "member_pair" }
|
137
|
-
}
|
138
|
-
|
139
|
-
at_state(27) {
|
140
|
-
for_symbols(",", "_End_", ")") { reduce_with "value_false" }
|
141
|
-
}
|
142
|
-
|
143
|
-
at_state(18) {
|
144
|
-
for_symbols("!!", "idstart_safe_token", "integer_token", "!'", "'", "char_token", "idchar_safe_token") { reduce_with "strchar_quoted_exclamation" }
|
145
|
-
}
|
146
|
-
|
147
|
-
at_state(11) {
|
148
|
-
for_symbols("exp") { shift_to 12 }
|
149
|
-
for_symbols("!!", ",", "idstart_safe_token", "integer_token", "!'", "_End_", "'", "char_token", ")", "idchar_safe_token") { reduce_with "number_int_frac" }
|
150
|
-
for_symbols("exponent_token") { shift_to 13 }
|
151
|
-
}
|
152
|
-
|
153
|
-
at_state(51) {
|
154
|
-
for_symbols("'") { shift_to 2 }
|
155
|
-
for_symbols("object") { shift_to 25 }
|
156
|
-
for_symbols("value") { shift_to 50 }
|
157
|
-
for_symbols("elements") { shift_to 52 }
|
158
|
-
for_symbols("number") { shift_to 46 }
|
159
|
-
for_symbols("!") { shift_to 47 }
|
160
|
-
for_symbols("string") { shift_to 26 }
|
161
|
-
for_symbols("array") { shift_to 28 }
|
162
|
-
for_symbols("idstart") { shift_to 38 }
|
163
|
-
for_symbols("integer_token") { shift_to 5 }
|
164
|
-
for_symbols("!t") { shift_to 24 }
|
165
|
-
for_symbols("idstart_safe_token") { shift_to 14 }
|
166
|
-
for_symbols("!f") { shift_to 27 }
|
167
|
-
for_symbols("(") { shift_to 29 }
|
168
|
-
for_symbols("id") { shift_to 53 }
|
169
|
-
for_symbols("int") { shift_to 8 }
|
170
|
-
for_symbols("!n") { shift_to 1 }
|
171
|
-
}
|
172
|
-
|
173
|
-
at_state(50) {
|
174
|
-
for_symbols(",") { shift_to 51 }
|
175
|
-
for_symbols(")") { reduce_with "element_value" }
|
176
|
-
}
|
177
|
-
|
178
|
-
at_state(43) {
|
179
|
-
for_symbols(":") { shift_to 44 }
|
180
|
-
}
|
181
|
-
|
182
|
-
at_state(38) {
|
183
|
-
for_symbols("idchars") { shift_to 42 }
|
184
|
-
for_symbols(",", ":", "_End_", ")") { reduce_with "id_idstart" }
|
185
|
-
for_symbols("idstart") { shift_to 17 }
|
186
|
-
for_symbols("integer_token") { shift_to 5 }
|
187
|
-
for_symbols("idstart_safe_token") { shift_to 14 }
|
188
|
-
for_symbols("idchar") { shift_to 40 }
|
189
|
-
for_symbols("idchar_safe_token") { shift_to 7 }
|
190
|
-
for_symbols("int") { shift_to 39 }
|
191
|
-
}
|
192
|
-
|
193
|
-
at_state(37) {
|
194
|
-
for_symbols(")") { reduce_with "member_pairs" }
|
195
|
-
}
|
196
|
-
|
197
|
-
at_state(15) {
|
198
|
-
for_symbols("!!", "idstart_safe_token", "integer_token", "!'", "'", "char_token", "idchar_safe_token") { reduce_with "strchar_idchar" }
|
199
|
-
}
|
200
|
-
|
201
|
-
at_state(12) {
|
202
|
-
for_symbols("!!", ",", "idstart_safe_token", "integer_token", "!'", "_End_", "'", "char_token", ")", "idchar_safe_token") { reduce_with "number_int_frac_exp" }
|
203
|
-
}
|
204
|
-
|
205
|
-
at_state(40) {
|
206
|
-
for_symbols(",", ":", "_End_", ")") { reduce_with "idchars_idchar" }
|
207
|
-
for_symbols("idstart") { shift_to 17 }
|
208
|
-
for_symbols("integer_token") { shift_to 5 }
|
209
|
-
for_symbols("idchars") { shift_to 41 }
|
210
|
-
for_symbols("idstart_safe_token") { shift_to 14 }
|
211
|
-
for_symbols("idchar") { shift_to 40 }
|
212
|
-
for_symbols("idchar_safe_token") { shift_to 7 }
|
213
|
-
for_symbols("int") { shift_to 39 }
|
214
|
-
}
|
215
|
-
|
216
|
-
at_state(34) {
|
217
|
-
for_symbols(":") { reduce_with "key_id" }
|
218
|
-
}
|
219
|
-
|
220
|
-
at_state(32) {
|
221
|
-
for_symbols(",", "_End_", ")") { reduce_with "empty_object" }
|
222
|
-
}
|
223
|
-
|
224
|
-
at_state(23) {
|
225
|
-
for_symbols("_End_") { reduce_with "start" }
|
226
|
-
}
|
227
|
-
|
228
|
-
at_state(17) {
|
229
|
-
for_symbols("!!", ",", "idstart_safe_token", "integer_token", ":", "!'", "_End_", "'", "char_token", ")", "idchar_safe_token") { reduce_with "idchar_idstart" }
|
230
|
-
}
|
231
|
-
|
232
|
-
at_state(16) {
|
233
|
-
for_symbols("idstart") { shift_to 17 }
|
234
|
-
for_symbols("!'") { shift_to 6 }
|
235
|
-
for_symbols("strchars") { shift_to 20 }
|
236
|
-
for_symbols("'") { reduce_with "strchars_char" }
|
237
|
-
for_symbols("integer_token") { shift_to 5 }
|
238
|
-
for_symbols("idchar") { shift_to 15 }
|
239
|
-
for_symbols("char_token") { shift_to 4 }
|
240
|
-
for_symbols("idstart_safe_token") { shift_to 14 }
|
241
|
-
for_symbols("strchar") { shift_to 16 }
|
242
|
-
for_symbols("idchar_safe_token") { shift_to 7 }
|
243
|
-
for_symbols("int") { shift_to 8 }
|
244
|
-
for_symbols("number") { shift_to 19 }
|
245
|
-
for_symbols("!!") { shift_to 18 }
|
246
|
-
}
|
247
|
-
|
248
|
-
at_state(4) {
|
249
|
-
for_symbols("!!", "idstart_safe_token", "integer_token", "!'", "'", "char_token", "idchar_safe_token") { reduce_with "strchar_char" }
|
250
|
-
}
|
251
|
-
|
252
|
-
at_state(49) {
|
253
|
-
for_symbols(",", "_End_", ")") { reduce_with "empty_array" }
|
254
|
-
}
|
255
|
-
|
256
|
-
at_state(25) {
|
257
|
-
for_symbols(",", "_End_", ")") { reduce_with "value_object" }
|
258
|
-
}
|
259
|
-
|
260
|
-
at_state(10) {
|
261
|
-
for_symbols("!!", ",", "idstart_safe_token", "integer_token", "!'", "_End_", "'", "exponent_token", "char_token", ")", "idchar_safe_token") { reduce_with "frac_literal" }
|
262
|
-
}
|
263
|
-
|
264
|
-
at_state(28) {
|
265
|
-
for_symbols(",", "_End_", ")") { reduce_with "value_array" }
|
266
|
-
}
|
267
|
-
|
268
|
-
at_state(26) {
|
269
|
-
for_symbols(",", "_End_", ")") { reduce_with "value_string" }
|
270
|
-
}
|
271
|
-
|
272
|
-
at_state(0) {
|
273
|
-
for_symbols("'") { shift_to 2 }
|
274
|
-
for_symbols("object") { shift_to 25 }
|
275
|
-
for_symbols("value") { shift_to 23 }
|
276
|
-
for_symbols("number") { shift_to 46 }
|
277
|
-
for_symbols("!") { shift_to 47 }
|
278
|
-
for_symbols("string") { shift_to 26 }
|
279
|
-
for_symbols("array") { shift_to 28 }
|
280
|
-
for_symbols("idstart") { shift_to 38 }
|
281
|
-
for_symbols("integer_token") { shift_to 5 }
|
282
|
-
for_symbols("!t") { shift_to 24 }
|
283
|
-
for_symbols("idstart_safe_token") { shift_to 14 }
|
284
|
-
for_symbols("!f") { shift_to 27 }
|
285
|
-
for_symbols("(") { shift_to 29 }
|
286
|
-
for_symbols("id") { shift_to 53 }
|
287
|
-
for_symbols("int") { shift_to 8 }
|
288
|
-
for_symbols("!n") { shift_to 1 }
|
289
|
-
}
|
290
|
-
|
291
|
-
at_state(46) {
|
292
|
-
for_symbols(",", "_End_", ")") { reduce_with "value_number" }
|
293
|
-
}
|
294
|
-
|
295
|
-
at_state(24) {
|
296
|
-
for_symbols(",", "_End_", ")") { reduce_with "value_true" }
|
297
|
-
}
|
298
|
-
|
299
|
-
at_state(20) {
|
300
|
-
for_symbols("'") { reduce_with "strchars_chars" }
|
301
|
-
}
|
302
|
-
|
303
|
-
at_state(13) {
|
304
|
-
for_symbols("!!", ",", "idstart_safe_token", "integer_token", "!'", "_End_", "'", "char_token", ")", "idchar_safe_token") { reduce_with "exponent_literal" }
|
305
|
-
}
|
306
|
-
|
307
|
-
at_state(9) {
|
308
|
-
for_symbols("!!", ",", "idstart_safe_token", "integer_token", "!'", "_End_", "'", "char_token", ")", "idchar_safe_token") { reduce_with "number_int_exp" }
|
309
|
-
}
|
310
|
-
|
311
|
-
at_state(1) {
|
312
|
-
for_symbols(",", "_End_", ")") { reduce_with "value_null" }
|
313
|
-
}
|
314
|
-
|
315
|
-
at_state(33) {
|
316
|
-
for_symbols(":") { reduce_with "key_string" }
|
317
|
-
}
|
318
|
-
|
319
|
-
at_state(30) {
|
320
|
-
for_symbols(")") { shift_to 31 }
|
321
|
-
}
|
322
|
-
|
323
|
-
at_state(29) {
|
324
|
-
for_symbols("'") { shift_to 2 }
|
325
|
-
for_symbols("members") { shift_to 30 }
|
326
|
-
for_symbols("key") { shift_to 43 }
|
327
|
-
for_symbols("idstart") { shift_to 38 }
|
328
|
-
for_symbols("string") { shift_to 33 }
|
329
|
-
for_symbols("idstart_safe_token") { shift_to 14 }
|
330
|
-
for_symbols(")") { shift_to 32 }
|
331
|
-
for_symbols("pair") { shift_to 35 }
|
332
|
-
for_symbols("id") { shift_to 34 }
|
333
|
-
}
|
334
|
-
|
335
|
-
at_state(14) {
|
336
|
-
for_symbols("!!", ",", "idstart_safe_token", "integer_token", ":", "!'", "_End_", "'", "char_token", ")", "idchar_safe_token") { reduce_with "idstart_char" }
|
337
|
-
}
|
338
|
-
|
339
|
-
at_state(6) {
|
340
|
-
for_symbols("!!", "idstart_safe_token", "integer_token", "!'", "'", "char_token", "idchar_safe_token") { reduce_with "strchar_quoted_single_quote" }
|
341
|
-
}
|
342
|
-
|
343
|
-
at_state(2) {
|
344
|
-
for_symbols("'") { shift_to 3 }
|
345
|
-
for_symbols("idstart") { shift_to 17 }
|
346
|
-
for_symbols("!'") { shift_to 6 }
|
347
|
-
for_symbols("integer_token") { shift_to 5 }
|
348
|
-
for_symbols("idchar") { shift_to 15 }
|
349
|
-
for_symbols("char_token") { shift_to 4 }
|
350
|
-
for_symbols("idstart_safe_token") { shift_to 14 }
|
351
|
-
for_symbols("strchar") { shift_to 16 }
|
352
|
-
for_symbols("idchar_safe_token") { shift_to 7 }
|
353
|
-
for_symbols("int") { shift_to 8 }
|
354
|
-
for_symbols("strchars") { shift_to 21 }
|
355
|
-
for_symbols("number") { shift_to 19 }
|
356
|
-
for_symbols("!!") { shift_to 18 }
|
357
|
-
}
|
358
|
-
|
359
|
-
end
|
360
|
-
end
|
data/test/test_dump.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'rational'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'rison'
|
4
|
-
require 'rison/dump'
|
5
|
-
|
6
|
-
class RisonDumpTests < Test::Unit::TestCase
|
7
|
-
def r(object)
|
8
|
-
Rison.dump(object)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_true
|
12
|
-
assert_equal '!t', r(true)
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_false
|
16
|
-
assert_equal '!f', r(false)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_nil
|
20
|
-
assert_equal '!n', r(nil)
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_integers
|
24
|
-
assert_equal '0', r(0)
|
25
|
-
assert_equal '42', r(42)
|
26
|
-
assert_equal '-42', r(-42)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_fractions
|
30
|
-
assert_equal '1.5', r(Rational(3, 2))
|
31
|
-
assert_equal '99.99', r(Rational(9999, 100))
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_ids
|
35
|
-
['a', 'a-z', 'domain.com'].each { |s| assert_equal s, r(s) }
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_strings
|
39
|
-
assert_equal "''", r('')
|
40
|
-
assert_equal "'0a'", r('0a')
|
41
|
-
assert_equal "'-h'", r('-h')
|
42
|
-
assert_equal "'can!'t'", r("can't")
|
43
|
-
assert_equal "'wow!!'", r('wow!')
|
44
|
-
assert_equal "'abc def'", r('abc def')
|
45
|
-
assert_equal "'user@domain.com'", r('user@domain.com')
|
46
|
-
assert_equal "'US $10'", r('US $10')
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_empty_object
|
50
|
-
assert_equal '()', r({})
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_non_empty_objects
|
54
|
-
assert_equal '(a:0)', r({:a => 0})
|
55
|
-
assert_equal '(id:!n,type:/common/document)', r({'id' => nil, 'type' => '/common/document'})
|
56
|
-
assert_equal '(id:!n,type:/common/document)', r({:id => nil, :type => :'/common/document'})
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_empty_array
|
60
|
-
assert_equal '!()', r([])
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_non_empty_arrays
|
64
|
-
assert_equal %{!(!t,!f,!n,'')}, r([true, false, nil, ''])
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_undumpable_objects
|
68
|
-
assert_raises(ArgumentError) { r(Array) }
|
69
|
-
end
|
70
|
-
end
|
data/test/test_parser.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
require 'rational'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'rison'
|
4
|
-
|
5
|
-
class RisonParserTests < Test::Unit::TestCase
|
6
|
-
|
7
|
-
def rison(string)
|
8
|
-
Rison.load(string)
|
9
|
-
end
|
10
|
-
|
11
|
-
def assert_invalid(string)
|
12
|
-
assert_raises(Rison::ParseError) { rison(string) }
|
13
|
-
end
|
14
|
-
|
15
|
-
# cf. http://mjtemplate.org/examples/rison.html
|
16
|
-
|
17
|
-
def test_true
|
18
|
-
assert_equal true, rison('!t')
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_false
|
22
|
-
assert_equal false, rison('!f')
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_null
|
26
|
-
assert_equal nil, rison('!n')
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_zero
|
30
|
-
assert_equal 0, rison('0')
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_positive_integer
|
34
|
-
assert_equal 1, rison('1')
|
35
|
-
assert_equal 12, rison('12')
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_negative_integer
|
39
|
-
assert_equal -3, rison('-3')
|
40
|
-
assert_equal -33, rison('-33')
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_rational
|
44
|
-
assert_equal Rational(3, 2), rison('1.5')
|
45
|
-
assert_equal Rational(9999, 100), rison('99.99')
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_positive_exponent
|
49
|
-
assert_equal 10**30, rison('1e30')
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_negative_exponent
|
53
|
-
assert_equal 10**-30, rison('1e-30')
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_fraction_and_exponent
|
57
|
-
assert_equal 150, rison('1.5e2')
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_ids
|
61
|
-
%w( a a-z domain.com ).each { |s| assert_equal s.to_sym, rison(s) }
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_strings
|
65
|
-
assert_equal '', rison("''")
|
66
|
-
assert_equal '0a', rison("'0a'")
|
67
|
-
assert_equal '-h', rison("'-h'")
|
68
|
-
assert_equal "can't", rison("'can!'t'")
|
69
|
-
assert_equal 'wow!', rison("'wow!!'")
|
70
|
-
assert_equal 'abc def', rison("'abc def'")
|
71
|
-
assert_equal 'user@domain.com', rison("'user@domain.com'")
|
72
|
-
assert_equal 'US $10', rison("'US $10'")
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_empty_object
|
76
|
-
assert_equal Hash.new, rison('()')
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_non_empty_objects
|
80
|
-
expected = {:a => 0}
|
81
|
-
assert_equal expected, rison('(a:0)')
|
82
|
-
|
83
|
-
expected = {:id => nil, :type => :'/common/document'}
|
84
|
-
assert_equal expected, rison('(id:!n,type:/common/document)')
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_empty_array
|
88
|
-
assert_equal [], rison('!()')
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_array
|
92
|
-
assert_equal [ true, false, nil, '' ], rison(%{!(!t,!f,!n,'')})
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_invalid_expressions
|
96
|
-
assert_invalid '-h'
|
97
|
-
assert_invalid '1.5e+2'
|
98
|
-
assert_invalid '1.5E2'
|
99
|
-
assert_invalid '1.5E+2'
|
100
|
-
assert_invalid '1.5E-2'
|
101
|
-
assert_invalid 'abc def'
|
102
|
-
assert_invalid 'US $10'
|
103
|
-
assert_invalid 'user@domain.com'
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|