DSON 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +22 -22
- data/.travis.yml +6 -0
- data/DSON.gemspec +28 -24
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +61 -62
- data/Rakefile +6 -2
- data/lib/DSON.rb +14 -13
- data/lib/DSON/value.rb +94 -98
- data/lib/DSON/value/array_value.rb +49 -47
- data/lib/DSON/value/false_value.rb +21 -21
- data/lib/DSON/value/hash_value.rb +56 -59
- data/lib/DSON/value/nil_value.rb +21 -21
- data/lib/DSON/value/numeric_value.rb +40 -20
- data/lib/DSON/value/object_value.rb +37 -37
- data/lib/DSON/value/string_value.rb +26 -25
- data/lib/DSON/value/true_value.rb +21 -21
- data/lib/DSON/version.rb +7 -7
- data/spec/lib/example_class.rb +15 -15
- data/spec/parsing_spec.rb +364 -292
- data/spec/serialization_spec.rb +378 -390
- metadata +57 -15
@@ -1,21 +1,21 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require 'DSON/value'
|
3
|
-
|
4
|
-
require 'singleton'
|
5
|
-
|
6
|
-
module DSON
|
7
|
-
module Value
|
8
|
-
class TrueValue
|
9
|
-
include Value
|
10
|
-
include Singleton
|
11
|
-
|
12
|
-
def self.so_parse
|
13
|
-
true
|
14
|
-
end
|
15
|
-
|
16
|
-
def such_serialize_wow
|
17
|
-
'yes'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'DSON/value'
|
3
|
+
|
4
|
+
require 'singleton'
|
5
|
+
|
6
|
+
module DSON
|
7
|
+
module Value
|
8
|
+
class TrueValue
|
9
|
+
include Value
|
10
|
+
include Singleton
|
11
|
+
|
12
|
+
def self.so_parse
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
def such_serialize_wow
|
17
|
+
'yes'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/DSON/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
|
3
|
-
# Part of the DSON module use to keep track of
|
4
|
-
# the version
|
5
|
-
module DSON
|
6
|
-
VERSION = '0.
|
7
|
-
end
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
# Part of the DSON module use to keep track of
|
4
|
+
# the version
|
5
|
+
module DSON
|
6
|
+
VERSION = '0.2.0'
|
7
|
+
end
|
data/spec/lib/example_class.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
module DSONSpec
|
3
|
-
class TrivialClass
|
4
|
-
end
|
5
|
-
|
6
|
-
class ExampleClass
|
7
|
-
attr_accessor :name
|
8
|
-
attr_accessor :value
|
9
|
-
|
10
|
-
def initialize(name, value)
|
11
|
-
@name = name
|
12
|
-
@value = value
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module DSONSpec
|
3
|
+
class TrivialClass
|
4
|
+
end
|
5
|
+
|
6
|
+
class ExampleClass
|
7
|
+
attr_accessor :name
|
8
|
+
attr_accessor :value
|
9
|
+
|
10
|
+
def initialize(name, value)
|
11
|
+
@name = name
|
12
|
+
@value = value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/parsing_spec.rb
CHANGED
@@ -1,292 +1,364 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require 'DSON'
|
3
|
-
|
4
|
-
describe 'simple hashes' do
|
5
|
-
|
6
|
-
it 'parses an empty DSON hash' do
|
7
|
-
dson_string = 'such wow'
|
8
|
-
parsed_dson = DSON.so_parse(dson_string)
|
9
|
-
|
10
|
-
expect(parsed_dson.keys.size).to eq(0)
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'parses a DSON hash with one element' do
|
14
|
-
dson_string = 'such "dson" is "parsed" wow'
|
15
|
-
parsed_dson = DSON.so_parse(dson_string)
|
16
|
-
|
17
|
-
expect(parsed_dson['dson']).to eq('parsed')
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'parses a DSON hash with two elements with , separator' do
|
21
|
-
dson_string = 'such "dson" is "parsed", "language" is "ruby" wow'
|
22
|
-
parsed_dson = DSON.so_parse(dson_string)
|
23
|
-
|
24
|
-
expect(parsed_dson['dson']).to eq('parsed')
|
25
|
-
expect(parsed_dson['language']).to eq('ruby')
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'parses a DSON hash with two elements with . separator' do
|
29
|
-
dson_string = 'such "dson" is "parsed". "language" is "ruby" wow'
|
30
|
-
parsed_dson = DSON.so_parse(dson_string)
|
31
|
-
|
32
|
-
expect(parsed_dson['dson']).to eq('parsed')
|
33
|
-
expect(parsed_dson['language']).to eq('ruby')
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'parses a DSON hash with two elements with ! separator' do
|
37
|
-
dson_string = 'such "dson" is "parsed"! "language" is "ruby" wow'
|
38
|
-
parsed_dson = DSON.so_parse(dson_string)
|
39
|
-
|
40
|
-
expect(parsed_dson['dson']).to eq('parsed')
|
41
|
-
expect(parsed_dson['language']).to eq('ruby')
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'parses a DSON hash with two elements with ? separator' do
|
45
|
-
dson_string = 'such "dson" is "parsed"? "language" is "ruby" wow'
|
46
|
-
parsed_dson = DSON.so_parse(dson_string)
|
47
|
-
|
48
|
-
expect(parsed_dson['dson']).to eq('parsed')
|
49
|
-
expect(parsed_dson['language']).to eq('ruby')
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'parses a DSON hash with three elements' do
|
53
|
-
dson_string = 'such "dson" is "parsed"! "language" is "ruby". "separators" is "varied" wow'
|
54
|
-
parsed_dson = DSON.so_parse(dson_string)
|
55
|
-
|
56
|
-
expect(parsed_dson['dson']).to eq('parsed')
|
57
|
-
expect(parsed_dson['language']).to eq('ruby')
|
58
|
-
expect(parsed_dson['separators']).to eq('varied')
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
describe 'parsing simple arrays' do
|
64
|
-
|
65
|
-
it 'parses an empty DSON array' do
|
66
|
-
dson_string = 'so many'
|
67
|
-
parsed_dson = DSON.so_parse(dson_string)
|
68
|
-
|
69
|
-
expect(parsed_dson.size).to eq(0)
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'parses a DSON array with one element' do
|
73
|
-
dson_string = 'so "test" many'
|
74
|
-
parsed_dson = DSON.so_parse(dson_string)
|
75
|
-
|
76
|
-
expect(parsed_dson[0]).to eq('test')
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'parses a DSON array with two elements and "and" separator' do
|
80
|
-
dson_string = 'so "test" and "quality" many'
|
81
|
-
parsed_dson = DSON.so_parse(dson_string)
|
82
|
-
|
83
|
-
expect(parsed_dson[0]).to eq('test')
|
84
|
-
expect(parsed_dson[1]).to eq('quality')
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'parses a DSON array with twp elements and "also" separator' do
|
88
|
-
dson_string = 'so "test" also "quality" many'
|
89
|
-
parsed_dson = DSON.so_parse(dson_string)
|
90
|
-
|
91
|
-
expect(parsed_dson[0]).to eq('test')
|
92
|
-
expect(parsed_dson[1]).to eq('quality')
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'parses a DSON array with a mix of separators' do
|
96
|
-
dson_string = 'so "test" also "quality" and "awesome" many'
|
97
|
-
parsed_dson = DSON.so_parse(dson_string)
|
98
|
-
|
99
|
-
expect(parsed_dson[0]).to eq('test')
|
100
|
-
expect(parsed_dson[1]).to eq('quality')
|
101
|
-
expect(parsed_dson[2]).to eq('awesome')
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'parses an array with " and " and " also " in a value' do
|
105
|
-
dson_string = 'so " and " also " also " and " and " many'
|
106
|
-
parsed_dson = DSON.so_parse(dson_string)
|
107
|
-
|
108
|
-
expect(parsed_dson[0]).to eq(' and ')
|
109
|
-
expect(parsed_dson[1]).to eq(' also ')
|
110
|
-
expect(parsed_dson[2]).to eq(' and ')
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
describe 'parsing nested arrays' do
|
116
|
-
|
117
|
-
it 'parses empty nested arrays' do
|
118
|
-
dson_string = 'so so many many'
|
119
|
-
parsed_dson = DSON.so_parse(dson_string)
|
120
|
-
|
121
|
-
expect(parsed_dson.size).to eq(1)
|
122
|
-
expect(parsed_dson[0].size).to eq(0)
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'should correctly handle nested arrays with elements' do
|
126
|
-
dson_string = 'so "cheese" also so many many'
|
127
|
-
parsed_dson = DSON.so_parse(dson_string)
|
128
|
-
|
129
|
-
expect(parsed_dson[0]).to eq('cheese')
|
130
|
-
expect(parsed_dson[1].size).to eq(0)
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'should correctly handle a nested array with an element' do
|
134
|
-
dson_string = 'so so "cheese" many many'
|
135
|
-
parsed_dson = DSON.so_parse(dson_string)
|
136
|
-
|
137
|
-
expect(parsed_dson[0][0]).to eq('cheese')
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'should correctly handle a more complex nested array' do
|
141
|
-
dson_string = 'so "cheese" and so "cheese" also so "cheese" many many many'
|
142
|
-
parsed_dson = DSON.so_parse(dson_string)
|
143
|
-
|
144
|
-
expect(parsed_dson[0]).to eq('cheese')
|
145
|
-
expect(parsed_dson[1][0]).to eq('cheese')
|
146
|
-
expect(parsed_dson[1][1][0]).to eq('cheese')
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'parses a hash with " is "" in one of the keys' do
|
150
|
-
dson_string = 'such " is " is "cheese" wow'
|
151
|
-
parsed_dson = DSON.so_parse(dson_string)
|
152
|
-
|
153
|
-
expect(parsed_dson[' is ']).to eq('cheese')
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'parses a hash with " is " in one of the values' do
|
157
|
-
dson_string = 'such "cheese" is " is " wow'
|
158
|
-
parsed_dson = DSON.so_parse(dson_string)
|
159
|
-
|
160
|
-
expect(parsed_dson['cheese']).to eq(' is ')
|
161
|
-
end
|
162
|
-
|
163
|
-
it 'parses a hash with a comma in one of the keys' do
|
164
|
-
dson_string = 'such "," is "cheese" wow'
|
165
|
-
parsed_dson = DSON.so_parse(dson_string)
|
166
|
-
|
167
|
-
expect(parsed_dson[',']).to eq('cheese')
|
168
|
-
end
|
169
|
-
|
170
|
-
it 'parses a hash with an exclaimation mark in one of the values' do
|
171
|
-
dson_string = 'such "cheese" is "," wow'
|
172
|
-
parsed_dson = DSON.so_parse(dson_string)
|
173
|
-
|
174
|
-
expect(parsed_dson['cheese']).to eq(',')
|
175
|
-
end
|
176
|
-
|
177
|
-
end
|
178
|
-
|
179
|
-
describe 'DSON nested hashes' do
|
180
|
-
it 'should handle a simple nested hash' do
|
181
|
-
dson_string = 'such "nested" is such wow wow'
|
182
|
-
parsed_dson = DSON.so_parse(dson_string)
|
183
|
-
|
184
|
-
expect(parsed_dson['nested'].keys.size).to eq(0)
|
185
|
-
end
|
186
|
-
|
187
|
-
it 'should handle a further nested hash' do
|
188
|
-
dson_string = 'such "nested" is such "further_nested" is such wow wow wow'
|
189
|
-
parsed_dson = DSON.so_parse(dson_string)
|
190
|
-
|
191
|
-
expect(parsed_dson['nested']['further_nested'].keys.size).to eq(0)
|
192
|
-
end
|
193
|
-
|
194
|
-
it 'should handle other elements in this hash' do
|
195
|
-
dson_string = 'such "other" is "true"! "nested" is such wow wow'
|
196
|
-
parsed_dson = DSON.so_parse(dson_string)
|
197
|
-
|
198
|
-
expect(parsed_dson['other']).to eq('true')
|
199
|
-
expect(parsed_dson['nested'].keys.size).to eq(0)
|
200
|
-
end
|
201
|
-
|
202
|
-
it 'should handle elements in a nested hash' do
|
203
|
-
dson_string = 'such "other" is "true". "nested" is such "element" is "great" wow wow'
|
204
|
-
parsed_dson = DSON.so_parse(dson_string)
|
205
|
-
|
206
|
-
expect(parsed_dson['other']).to eq('true')
|
207
|
-
expect(parsed_dson['nested']['element']).to eq('great')
|
208
|
-
end
|
209
|
-
|
210
|
-
it 'should handle multiple elements in the nested hash' do
|
211
|
-
dson_string = 'such "wine" is such "white" is "great"? "red" is "greater" wow wow'
|
212
|
-
parsed_dson = DSON.so_parse(dson_string)
|
213
|
-
|
214
|
-
expect(parsed_dson['wine']['white']).to eq('great')
|
215
|
-
expect(parsed_dson['wine']['red']).to eq('greater')
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
describe 'DSON hash and array mixes' do
|
220
|
-
|
221
|
-
it 'should handle an array of empty objects' do
|
222
|
-
dson_string = 'so such wow also such wow many'
|
223
|
-
parsed_dson = DSON.so_parse(dson_string)
|
224
|
-
|
225
|
-
expect(parsed_dson.size).to eq(2)
|
226
|
-
expect(parsed_dson[0].keys.size).to eq(0)
|
227
|
-
expect(parsed_dson[1].keys.size).to eq(0)
|
228
|
-
end
|
229
|
-
|
230
|
-
it 'should handle an object with an empty array element' do
|
231
|
-
dson_string = 'such "array" is so many wow'
|
232
|
-
parsed_dson = DSON.so_parse(dson_string)
|
233
|
-
|
234
|
-
expect(parsed_dson['array'].size).to eq(0)
|
235
|
-
end
|
236
|
-
|
237
|
-
it 'should handle an object with an array element' do
|
238
|
-
dson_string = 'such "array" is so "olive" also "grape" many wow'
|
239
|
-
parsed_dson = DSON.so_parse(dson_string)
|
240
|
-
|
241
|
-
expect(parsed_dson['array'][0]).to eq('olive')
|
242
|
-
expect(parsed_dson['array'][1]).to eq('grape')
|
243
|
-
end
|
244
|
-
|
245
|
-
it 'should handle an array with an object element' do
|
246
|
-
dson_string = 'so such "first_name" is "Cyril", "surname" is "Figgis" wow many'
|
247
|
-
parsed_dson = DSON.so_parse(dson_string)
|
248
|
-
|
249
|
-
expect(parsed_dson[0]['first_name']).to eq('Cyril')
|
250
|
-
expect(parsed_dson[0]['surname']).to eq('Figgis')
|
251
|
-
end
|
252
|
-
|
253
|
-
end
|
254
|
-
|
255
|
-
describe 'parsing DSON booleans' do
|
256
|
-
it 'should translate yes in a hash to true' do
|
257
|
-
dson_string = 'such "dson" is yes wow'
|
258
|
-
parsed_dson = DSON.so_parse(dson_string)
|
259
|
-
|
260
|
-
expect(parsed_dson['dson']).to be_a(TrueClass)
|
261
|
-
end
|
262
|
-
|
263
|
-
it 'should translate yes in an array to true' do
|
264
|
-
dson_string = 'so yes many'
|
265
|
-
parsed_dson = DSON.so_parse(dson_string)
|
266
|
-
|
267
|
-
expect(parsed_dson[0]).to be_a(TrueClass)
|
268
|
-
end
|
269
|
-
|
270
|
-
it 'should translate no in a hash to false' do
|
271
|
-
dson_string = 'such "json" is no wow'
|
272
|
-
parsed_dson = DSON.so_parse(dson_string)
|
273
|
-
|
274
|
-
expect(parsed_dson['json']).to be_a(FalseClass)
|
275
|
-
end
|
276
|
-
|
277
|
-
it 'should translate no in an array to false' do
|
278
|
-
dson_string = 'so no many'
|
279
|
-
parsed_dson = DSON.so_parse(dson_string)
|
280
|
-
|
281
|
-
expect(parsed_dson[0]).to be_a(FalseClass)
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
describe 'parsing DSON empty' do
|
286
|
-
it 'should translate empty to nil' do
|
287
|
-
dson_string = 'so empty many'
|
288
|
-
parsed_dson = DSON.so_parse(dson_string)
|
289
|
-
|
290
|
-
expect(parsed_dson[0]).to be_nil
|
291
|
-
end
|
292
|
-
end
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'DSON'
|
3
|
+
|
4
|
+
describe 'simple hashes' do
|
5
|
+
|
6
|
+
it 'parses an empty DSON hash' do
|
7
|
+
dson_string = 'such wow'
|
8
|
+
parsed_dson = DSON.so_parse(dson_string)
|
9
|
+
|
10
|
+
expect(parsed_dson.keys.size).to eq(0)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'parses a DSON hash with one element' do
|
14
|
+
dson_string = 'such "dson" is "parsed" wow'
|
15
|
+
parsed_dson = DSON.so_parse(dson_string)
|
16
|
+
|
17
|
+
expect(parsed_dson['dson']).to eq('parsed')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'parses a DSON hash with two elements with , separator' do
|
21
|
+
dson_string = 'such "dson" is "parsed", "language" is "ruby" wow'
|
22
|
+
parsed_dson = DSON.so_parse(dson_string)
|
23
|
+
|
24
|
+
expect(parsed_dson['dson']).to eq('parsed')
|
25
|
+
expect(parsed_dson['language']).to eq('ruby')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'parses a DSON hash with two elements with . separator' do
|
29
|
+
dson_string = 'such "dson" is "parsed". "language" is "ruby" wow'
|
30
|
+
parsed_dson = DSON.so_parse(dson_string)
|
31
|
+
|
32
|
+
expect(parsed_dson['dson']).to eq('parsed')
|
33
|
+
expect(parsed_dson['language']).to eq('ruby')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'parses a DSON hash with two elements with ! separator' do
|
37
|
+
dson_string = 'such "dson" is "parsed"! "language" is "ruby" wow'
|
38
|
+
parsed_dson = DSON.so_parse(dson_string)
|
39
|
+
|
40
|
+
expect(parsed_dson['dson']).to eq('parsed')
|
41
|
+
expect(parsed_dson['language']).to eq('ruby')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'parses a DSON hash with two elements with ? separator' do
|
45
|
+
dson_string = 'such "dson" is "parsed"? "language" is "ruby" wow'
|
46
|
+
parsed_dson = DSON.so_parse(dson_string)
|
47
|
+
|
48
|
+
expect(parsed_dson['dson']).to eq('parsed')
|
49
|
+
expect(parsed_dson['language']).to eq('ruby')
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'parses a DSON hash with three elements' do
|
53
|
+
dson_string = 'such "dson" is "parsed"! "language" is "ruby". "separators" is "varied" wow'
|
54
|
+
parsed_dson = DSON.so_parse(dson_string)
|
55
|
+
|
56
|
+
expect(parsed_dson['dson']).to eq('parsed')
|
57
|
+
expect(parsed_dson['language']).to eq('ruby')
|
58
|
+
expect(parsed_dson['separators']).to eq('varied')
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'parsing simple arrays' do
|
64
|
+
|
65
|
+
it 'parses an empty DSON array' do
|
66
|
+
dson_string = 'so many'
|
67
|
+
parsed_dson = DSON.so_parse(dson_string)
|
68
|
+
|
69
|
+
expect(parsed_dson.size).to eq(0)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'parses a DSON array with one element' do
|
73
|
+
dson_string = 'so "test" many'
|
74
|
+
parsed_dson = DSON.so_parse(dson_string)
|
75
|
+
|
76
|
+
expect(parsed_dson[0]).to eq('test')
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'parses a DSON array with two elements and "and" separator' do
|
80
|
+
dson_string = 'so "test" and "quality" many'
|
81
|
+
parsed_dson = DSON.so_parse(dson_string)
|
82
|
+
|
83
|
+
expect(parsed_dson[0]).to eq('test')
|
84
|
+
expect(parsed_dson[1]).to eq('quality')
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'parses a DSON array with twp elements and "also" separator' do
|
88
|
+
dson_string = 'so "test" also "quality" many'
|
89
|
+
parsed_dson = DSON.so_parse(dson_string)
|
90
|
+
|
91
|
+
expect(parsed_dson[0]).to eq('test')
|
92
|
+
expect(parsed_dson[1]).to eq('quality')
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'parses a DSON array with a mix of separators' do
|
96
|
+
dson_string = 'so "test" also "quality" and "awesome" many'
|
97
|
+
parsed_dson = DSON.so_parse(dson_string)
|
98
|
+
|
99
|
+
expect(parsed_dson[0]).to eq('test')
|
100
|
+
expect(parsed_dson[1]).to eq('quality')
|
101
|
+
expect(parsed_dson[2]).to eq('awesome')
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'parses an array with " and " and " also " in a value' do
|
105
|
+
dson_string = 'so " and " also " also " and " and " many'
|
106
|
+
parsed_dson = DSON.so_parse(dson_string)
|
107
|
+
|
108
|
+
expect(parsed_dson[0]).to eq(' and ')
|
109
|
+
expect(parsed_dson[1]).to eq(' also ')
|
110
|
+
expect(parsed_dson[2]).to eq(' and ')
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
describe 'parsing nested arrays' do
|
116
|
+
|
117
|
+
it 'parses empty nested arrays' do
|
118
|
+
dson_string = 'so so many many'
|
119
|
+
parsed_dson = DSON.so_parse(dson_string)
|
120
|
+
|
121
|
+
expect(parsed_dson.size).to eq(1)
|
122
|
+
expect(parsed_dson[0].size).to eq(0)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should correctly handle nested arrays with elements' do
|
126
|
+
dson_string = 'so "cheese" also so many many'
|
127
|
+
parsed_dson = DSON.so_parse(dson_string)
|
128
|
+
|
129
|
+
expect(parsed_dson[0]).to eq('cheese')
|
130
|
+
expect(parsed_dson[1].size).to eq(0)
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should correctly handle a nested array with an element' do
|
134
|
+
dson_string = 'so so "cheese" many many'
|
135
|
+
parsed_dson = DSON.so_parse(dson_string)
|
136
|
+
|
137
|
+
expect(parsed_dson[0][0]).to eq('cheese')
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'should correctly handle a more complex nested array' do
|
141
|
+
dson_string = 'so "cheese" and so "cheese" also so "cheese" many many many'
|
142
|
+
parsed_dson = DSON.so_parse(dson_string)
|
143
|
+
|
144
|
+
expect(parsed_dson[0]).to eq('cheese')
|
145
|
+
expect(parsed_dson[1][0]).to eq('cheese')
|
146
|
+
expect(parsed_dson[1][1][0]).to eq('cheese')
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'parses a hash with " is "" in one of the keys' do
|
150
|
+
dson_string = 'such " is " is "cheese" wow'
|
151
|
+
parsed_dson = DSON.so_parse(dson_string)
|
152
|
+
|
153
|
+
expect(parsed_dson[' is ']).to eq('cheese')
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'parses a hash with " is " in one of the values' do
|
157
|
+
dson_string = 'such "cheese" is " is " wow'
|
158
|
+
parsed_dson = DSON.so_parse(dson_string)
|
159
|
+
|
160
|
+
expect(parsed_dson['cheese']).to eq(' is ')
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'parses a hash with a comma in one of the keys' do
|
164
|
+
dson_string = 'such "," is "cheese" wow'
|
165
|
+
parsed_dson = DSON.so_parse(dson_string)
|
166
|
+
|
167
|
+
expect(parsed_dson[',']).to eq('cheese')
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'parses a hash with an exclaimation mark in one of the values' do
|
171
|
+
dson_string = 'such "cheese" is "," wow'
|
172
|
+
parsed_dson = DSON.so_parse(dson_string)
|
173
|
+
|
174
|
+
expect(parsed_dson['cheese']).to eq(',')
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
describe 'DSON nested hashes' do
|
180
|
+
it 'should handle a simple nested hash' do
|
181
|
+
dson_string = 'such "nested" is such wow wow'
|
182
|
+
parsed_dson = DSON.so_parse(dson_string)
|
183
|
+
|
184
|
+
expect(parsed_dson['nested'].keys.size).to eq(0)
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should handle a further nested hash' do
|
188
|
+
dson_string = 'such "nested" is such "further_nested" is such wow wow wow'
|
189
|
+
parsed_dson = DSON.so_parse(dson_string)
|
190
|
+
|
191
|
+
expect(parsed_dson['nested']['further_nested'].keys.size).to eq(0)
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should handle other elements in this hash' do
|
195
|
+
dson_string = 'such "other" is "true"! "nested" is such wow wow'
|
196
|
+
parsed_dson = DSON.so_parse(dson_string)
|
197
|
+
|
198
|
+
expect(parsed_dson['other']).to eq('true')
|
199
|
+
expect(parsed_dson['nested'].keys.size).to eq(0)
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'should handle elements in a nested hash' do
|
203
|
+
dson_string = 'such "other" is "true". "nested" is such "element" is "great" wow wow'
|
204
|
+
parsed_dson = DSON.so_parse(dson_string)
|
205
|
+
|
206
|
+
expect(parsed_dson['other']).to eq('true')
|
207
|
+
expect(parsed_dson['nested']['element']).to eq('great')
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'should handle multiple elements in the nested hash' do
|
211
|
+
dson_string = 'such "wine" is such "white" is "great"? "red" is "greater" wow wow'
|
212
|
+
parsed_dson = DSON.so_parse(dson_string)
|
213
|
+
|
214
|
+
expect(parsed_dson['wine']['white']).to eq('great')
|
215
|
+
expect(parsed_dson['wine']['red']).to eq('greater')
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe 'DSON hash and array mixes' do
|
220
|
+
|
221
|
+
it 'should handle an array of empty objects' do
|
222
|
+
dson_string = 'so such wow also such wow many'
|
223
|
+
parsed_dson = DSON.so_parse(dson_string)
|
224
|
+
|
225
|
+
expect(parsed_dson.size).to eq(2)
|
226
|
+
expect(parsed_dson[0].keys.size).to eq(0)
|
227
|
+
expect(parsed_dson[1].keys.size).to eq(0)
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'should handle an object with an empty array element' do
|
231
|
+
dson_string = 'such "array" is so many wow'
|
232
|
+
parsed_dson = DSON.so_parse(dson_string)
|
233
|
+
|
234
|
+
expect(parsed_dson['array'].size).to eq(0)
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'should handle an object with an array element' do
|
238
|
+
dson_string = 'such "array" is so "olive" also "grape" many wow'
|
239
|
+
parsed_dson = DSON.so_parse(dson_string)
|
240
|
+
|
241
|
+
expect(parsed_dson['array'][0]).to eq('olive')
|
242
|
+
expect(parsed_dson['array'][1]).to eq('grape')
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'should handle an array with an object element' do
|
246
|
+
dson_string = 'so such "first_name" is "Cyril", "surname" is "Figgis" wow many'
|
247
|
+
parsed_dson = DSON.so_parse(dson_string)
|
248
|
+
|
249
|
+
expect(parsed_dson[0]['first_name']).to eq('Cyril')
|
250
|
+
expect(parsed_dson[0]['surname']).to eq('Figgis')
|
251
|
+
end
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
|
+
describe 'parsing DSON booleans' do
|
256
|
+
it 'should translate yes in a hash to true' do
|
257
|
+
dson_string = 'such "dson" is yes wow'
|
258
|
+
parsed_dson = DSON.so_parse(dson_string)
|
259
|
+
|
260
|
+
expect(parsed_dson['dson']).to be_a(TrueClass)
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'should translate yes in an array to true' do
|
264
|
+
dson_string = 'so yes many'
|
265
|
+
parsed_dson = DSON.so_parse(dson_string)
|
266
|
+
|
267
|
+
expect(parsed_dson[0]).to be_a(TrueClass)
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'should translate no in a hash to false' do
|
271
|
+
dson_string = 'such "json" is no wow'
|
272
|
+
parsed_dson = DSON.so_parse(dson_string)
|
273
|
+
|
274
|
+
expect(parsed_dson['json']).to be_a(FalseClass)
|
275
|
+
end
|
276
|
+
|
277
|
+
it 'should translate no in an array to false' do
|
278
|
+
dson_string = 'so no many'
|
279
|
+
parsed_dson = DSON.so_parse(dson_string)
|
280
|
+
|
281
|
+
expect(parsed_dson[0]).to be_a(FalseClass)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
describe 'parsing DSON empty' do
|
286
|
+
it 'should translate empty to nil' do
|
287
|
+
dson_string = 'so empty many'
|
288
|
+
parsed_dson = DSON.so_parse(dson_string)
|
289
|
+
|
290
|
+
expect(parsed_dson[0]).to be_nil
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
describe 'parsing numbers' do
|
295
|
+
it 'should translate a positive float to a base 10 float' do
|
296
|
+
dson_string = 'such "number" is 22.88 wow'
|
297
|
+
parsed_dson = DSON.so_parse(dson_string)
|
298
|
+
|
299
|
+
expect(parsed_dson["number"]).to eq 19.125
|
300
|
+
end
|
301
|
+
|
302
|
+
it 'should translate a negative float to a base 10 float' do
|
303
|
+
dson_string = 'such "number" is -22.88 wow'
|
304
|
+
parsed_dson = DSON.so_parse(dson_string)
|
305
|
+
|
306
|
+
expect(parsed_dson["number"]).to eq -19.125
|
307
|
+
end
|
308
|
+
|
309
|
+
it 'should translate a positive integer to a base 10 integer' do
|
310
|
+
dson_string = 'such "number" is 15 wow'
|
311
|
+
parsed_dson = DSON.so_parse(dson_string)
|
312
|
+
|
313
|
+
expect(parsed_dson["number"]).to eq 13
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'should translate a negative integer to a base 10 integer' do
|
317
|
+
dson_string = 'such "number" is -15 wow'
|
318
|
+
parsed_dson = DSON.so_parse(dson_string)
|
319
|
+
|
320
|
+
expect(parsed_dson["number"]).to eq -13
|
321
|
+
end
|
322
|
+
|
323
|
+
it 'should translate a number in the very format to a base 10 number' do
|
324
|
+
dson_string = 'such "number" is 42very3 wow'
|
325
|
+
parsed_dson = DSON.so_parse(dson_string)
|
326
|
+
|
327
|
+
expect(parsed_dson["number"]).to eq 17408
|
328
|
+
end
|
329
|
+
|
330
|
+
it 'should translate a number in the VERY format to a base 10 number' do
|
331
|
+
dson_string = 'such "number" is 42VERY3 wow'
|
332
|
+
parsed_dson = DSON.so_parse(dson_string)
|
333
|
+
|
334
|
+
expect(parsed_dson["number"]).to eq 17408
|
335
|
+
end
|
336
|
+
|
337
|
+
it 'should translate a number in the very format with a negative exponent' do
|
338
|
+
dson_string = 'such "number" is 42very-3 wow'
|
339
|
+
parsed_dson = DSON.so_parse(dson_string)
|
340
|
+
|
341
|
+
expect(parsed_dson["number"]).to eq 0.06640625
|
342
|
+
end
|
343
|
+
|
344
|
+
it 'should translate a number in the very format with a negative coefficient' do
|
345
|
+
dson_string = 'such "number" is -42very3 wow'
|
346
|
+
parsed_dson = DSON.so_parse(dson_string)
|
347
|
+
|
348
|
+
expect(parsed_dson["number"]).to eq -17408
|
349
|
+
end
|
350
|
+
|
351
|
+
it 'should translate a number in the very format a when coefficient and exponent are floats' do
|
352
|
+
dson_string = 'such "number" is 42.88very13.13'
|
353
|
+
parsed_dson = DSON.so_parse(dson_string)
|
354
|
+
|
355
|
+
expect(parsed_dson["number"]).to eq 431345013035.9022
|
356
|
+
end
|
357
|
+
|
358
|
+
it 'should translate a number in the very format with coefficnient and exponent are negative floats' do
|
359
|
+
dson_string = 'such "number" is -42.88very-1.13'
|
360
|
+
parsed_dson = DSON.so_parse(dson_string)
|
361
|
+
|
362
|
+
expect(parsed_dson["number"]).to eq -3.0711975623692616
|
363
|
+
end
|
364
|
+
end
|