DSON 0.0.2 → 0.0.3
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/DSON.gemspec +24 -24
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +50 -48
- data/Rakefile +2 -2
- data/lib/DSON.rb +9 -9
- data/lib/DSON/value.rb +35 -33
- data/lib/DSON/value/array_value.rb +23 -23
- data/lib/DSON/value/false_value.rb +16 -16
- data/lib/DSON/value/hash_value.rb +28 -28
- data/lib/DSON/value/nil_value.rb +16 -17
- data/lib/DSON/value/numeric_value.rb +20 -20
- data/lib/DSON/value/object_value.rb +33 -0
- data/lib/DSON/value/string_value.rb +20 -20
- data/lib/DSON/value/true_value.rb +16 -16
- data/lib/DSON/version.rb +7 -7
- data/spec/dson_spec.rb +390 -369
- data/spec/lib/example_class.rb +14 -0
- metadata +16 -39
- data/lib/DSON/value/variable_value.rb +0 -14
data/lib/DSON/value/nil_value.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
|
-
require 'DSON/value'
|
2
|
-
|
3
|
-
require 'singleton'
|
4
|
-
|
5
|
-
module DSON
|
6
|
-
module Value
|
7
|
-
class NilValue
|
8
|
-
include Value
|
9
|
-
include Singleton
|
10
|
-
|
11
|
-
def such_serialize_wow
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
1
|
+
require 'DSON/value'
|
2
|
+
|
3
|
+
require 'singleton'
|
4
|
+
|
5
|
+
module DSON
|
6
|
+
module Value
|
7
|
+
class NilValue
|
8
|
+
include Value
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
def such_serialize_wow
|
12
|
+
'empty'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,20 +1,20 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require 'DSON/value'
|
3
|
-
|
4
|
-
module DSON
|
5
|
-
module Value
|
6
|
-
class NumericValue
|
7
|
-
include Value
|
8
|
-
|
9
|
-
attr_reader :value
|
10
|
-
|
11
|
-
def initialize(value)
|
12
|
-
@value = value
|
13
|
-
end
|
14
|
-
|
15
|
-
def such_serialize_wow
|
16
|
-
value
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'DSON/value'
|
3
|
+
|
4
|
+
module DSON
|
5
|
+
module Value
|
6
|
+
class NumericValue
|
7
|
+
include Value
|
8
|
+
|
9
|
+
attr_reader :value
|
10
|
+
|
11
|
+
def initialize(value)
|
12
|
+
@value = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def such_serialize_wow
|
16
|
+
value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'DSON/value'
|
3
|
+
|
4
|
+
module DSON
|
5
|
+
module Value
|
6
|
+
class ObjectValue
|
7
|
+
include Value
|
8
|
+
|
9
|
+
attr_reader :value
|
10
|
+
|
11
|
+
def initialize(value)
|
12
|
+
@value = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def such_serialize_wow
|
16
|
+
# Construct a hash of the instance variables
|
17
|
+
object_hash = Hash[
|
18
|
+
value.instance_variables.map do |variable|
|
19
|
+
[remove_at_from_attribute_name(variable), value.instance_variable_get(variable)]
|
20
|
+
end
|
21
|
+
]
|
22
|
+
|
23
|
+
value = DSON::Value.new(object_hash)
|
24
|
+
value.such_serialize_wow
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def remove_at_from_attribute_name(attribute_name)
|
29
|
+
attribute_name[1..-1]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,20 +1,20 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require 'DSON/value'
|
3
|
-
|
4
|
-
module DSON
|
5
|
-
module Value
|
6
|
-
class StringValue
|
7
|
-
include Value
|
8
|
-
|
9
|
-
attr_reader :value
|
10
|
-
|
11
|
-
def initialize(value)
|
12
|
-
@value = value
|
13
|
-
end
|
14
|
-
|
15
|
-
def such_serialize_wow
|
16
|
-
"\"#{value}\""
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'DSON/value'
|
3
|
+
|
4
|
+
module DSON
|
5
|
+
module Value
|
6
|
+
class StringValue
|
7
|
+
include Value
|
8
|
+
|
9
|
+
attr_reader :value
|
10
|
+
|
11
|
+
def initialize(value)
|
12
|
+
@value = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def such_serialize_wow
|
16
|
+
"\"#{value}\""
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require 'DSON/value'
|
2
|
-
|
3
|
-
require 'singleton'
|
4
|
-
|
5
|
-
module DSON
|
6
|
-
module Value
|
7
|
-
class TrueValue
|
8
|
-
include Value
|
9
|
-
include Singleton
|
10
|
-
|
11
|
-
def such_serialize_wow
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
1
|
+
require 'DSON/value'
|
2
|
+
|
3
|
+
require 'singleton'
|
4
|
+
|
5
|
+
module DSON
|
6
|
+
module Value
|
7
|
+
class TrueValue
|
8
|
+
include Value
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
def such_serialize_wow
|
12
|
+
'yes'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
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.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.0.3'
|
7
|
+
end
|
data/spec/dson_spec.rb
CHANGED
@@ -1,369 +1,390 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require 'DSON'
|
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
|
-
end
|
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
|
-
end
|
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
|
-
end
|
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
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
)
|
232
|
-
|
233
|
-
|
234
|
-
end
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
)
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
)
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
#
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
#
|
355
|
-
#
|
356
|
-
|
357
|
-
|
358
|
-
#
|
359
|
-
#
|
360
|
-
#
|
361
|
-
#
|
362
|
-
|
363
|
-
|
364
|
-
#
|
365
|
-
#
|
366
|
-
#
|
367
|
-
|
368
|
-
|
369
|
-
#
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'DSON'
|
3
|
+
|
4
|
+
require_relative 'lib/example_class'
|
5
|
+
|
6
|
+
PUNCTUATION_MATCH = '(,|\.|!|\\?)'
|
7
|
+
AND_MATCH = '(and|also)'
|
8
|
+
|
9
|
+
describe 'DSON simple hash handling' do
|
10
|
+
|
11
|
+
it 'should be correct with an empty hash' do
|
12
|
+
dson_hash = Hash.new
|
13
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
14
|
+
|
15
|
+
expect(dson_string).to eq(
|
16
|
+
'such wow'
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should be correct with a hash with one element' do
|
21
|
+
dson_hash = {
|
22
|
+
dson: 'awesome'
|
23
|
+
}
|
24
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
25
|
+
|
26
|
+
expect(dson_string).to eq(
|
27
|
+
'such "dson" is "awesome" wow'
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should be correct with a hash with two elements' do
|
32
|
+
dson_or_ruby = '("dson" is "awesome"|"ruby" is "great")'
|
33
|
+
|
34
|
+
dson_hash = {
|
35
|
+
dson: 'awesome',
|
36
|
+
ruby: 'great'
|
37
|
+
}
|
38
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
39
|
+
|
40
|
+
expect(dson_string).to match(
|
41
|
+
/such #{dson_or_ruby}#{PUNCTUATION_MATCH} #{dson_or_ruby} wow/
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should be correct with a hash with three elements' do
|
46
|
+
dson_ruby_or_dogescript =
|
47
|
+
'(' \
|
48
|
+
'"dson" is "awesome"' \
|
49
|
+
'|' \
|
50
|
+
'"ruby" is "great"' \
|
51
|
+
'|' \
|
52
|
+
'"dogescript" is "fine"' \
|
53
|
+
')'
|
54
|
+
|
55
|
+
dson_hash = {
|
56
|
+
dson: 'awesome',
|
57
|
+
ruby: 'great',
|
58
|
+
dogescript: 'fine'
|
59
|
+
}
|
60
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
61
|
+
|
62
|
+
regex_string =
|
63
|
+
'such' \
|
64
|
+
' ' +
|
65
|
+
dson_ruby_or_dogescript +
|
66
|
+
PUNCTUATION_MATCH +
|
67
|
+
' ' +
|
68
|
+
dson_ruby_or_dogescript +
|
69
|
+
PUNCTUATION_MATCH +
|
70
|
+
' ' +
|
71
|
+
dson_ruby_or_dogescript +
|
72
|
+
' ' +
|
73
|
+
'wow'
|
74
|
+
|
75
|
+
expect(dson_string).to match(
|
76
|
+
/#{regex_string}/
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'DSON simple array handling' do
|
83
|
+
|
84
|
+
it 'should correctly handle an empty array' do
|
85
|
+
dson_array = Array.new
|
86
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
87
|
+
|
88
|
+
expect(dson_string).to eq(
|
89
|
+
'so many'
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should correctly handle an array with a single element' do
|
94
|
+
dson_array = %w(cheese)
|
95
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
96
|
+
|
97
|
+
expect(dson_string).to eq(
|
98
|
+
'so "cheese" many'
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should correctly handle an array with two elements' do
|
103
|
+
dson_array = %w(cheese wine)
|
104
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
105
|
+
|
106
|
+
expect(dson_string).to match(
|
107
|
+
/so "cheese" #{AND_MATCH} "wine" many/
|
108
|
+
)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should correctly handle an array with three elements' do
|
112
|
+
dson_array = %w(cheese wine bread)
|
113
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
114
|
+
|
115
|
+
expect(dson_string).to match(
|
116
|
+
/so "cheese" #{AND_MATCH} "wine" #{AND_MATCH} "bread" many/
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'DSON nested arrays' do
|
123
|
+
|
124
|
+
it 'should correctly handle empty nested arrays' do
|
125
|
+
dson_array = [[]]
|
126
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
127
|
+
|
128
|
+
expect(dson_string).to eq(
|
129
|
+
'so so many many'
|
130
|
+
)
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should correctly handle nested arrays with elements' do
|
134
|
+
dson_array = ['cheese', []]
|
135
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
136
|
+
|
137
|
+
expect(dson_string).to match(
|
138
|
+
/so "cheese" #{AND_MATCH} so many many/
|
139
|
+
)
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should correctly handle a nested array with an element' do
|
143
|
+
dson_array = [['cheese']]
|
144
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
145
|
+
|
146
|
+
expect(dson_string).to eq(
|
147
|
+
'so so "cheese" many many'
|
148
|
+
)
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should correctly handle a more complex nested array' do
|
152
|
+
dson_array = ['cheese', ['cheese', ['cheese']]]
|
153
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
154
|
+
|
155
|
+
expect(dson_string).to match(
|
156
|
+
/so "cheese" #{AND_MATCH} so "cheese" #{AND_MATCH} so "cheese" many many many/
|
157
|
+
)
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
describe 'DSON nested hashes' do
|
163
|
+
|
164
|
+
it 'should handle a simple nested hash' do
|
165
|
+
dson_hash = {
|
166
|
+
nested: {}
|
167
|
+
}
|
168
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
169
|
+
|
170
|
+
expect(dson_string).to eq(
|
171
|
+
'such "nested" is such wow wow'
|
172
|
+
)
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should handle a further nested hash' do
|
176
|
+
dson_hash = {
|
177
|
+
nested: {
|
178
|
+
further_nested: {
|
179
|
+
}
|
180
|
+
}
|
181
|
+
}
|
182
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
183
|
+
|
184
|
+
expect(dson_string).to eq(
|
185
|
+
'such "nested" is such "further_nested" is such wow wow wow'
|
186
|
+
)
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'should handle other elements in this hash' do
|
190
|
+
dson_hash = {
|
191
|
+
other: 'true',
|
192
|
+
nested: {
|
193
|
+
}
|
194
|
+
}
|
195
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
196
|
+
|
197
|
+
other_or_nested = '("other" is "true"|"nested" is such wow)'
|
198
|
+
|
199
|
+
expect(dson_string).to match(
|
200
|
+
/such #{other_or_nested}#{PUNCTUATION_MATCH} #{other_or_nested} wow/
|
201
|
+
)
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'should handle elements in a nested hash' do
|
205
|
+
dson_hash = {
|
206
|
+
other: 'true',
|
207
|
+
nested: {
|
208
|
+
element: 'great'
|
209
|
+
}
|
210
|
+
}
|
211
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
212
|
+
|
213
|
+
other_or_nested = '("other" is "true"|"nested" is such "element" is "great" wow)'
|
214
|
+
|
215
|
+
expect(dson_string).to match(
|
216
|
+
/such #{other_or_nested}#{PUNCTUATION_MATCH} #{other_or_nested} wow/
|
217
|
+
)
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'should handle multiple elements in the nested hash' do
|
221
|
+
dson_hash = {
|
222
|
+
wine: {
|
223
|
+
white: 'great',
|
224
|
+
red: 'greater'
|
225
|
+
}
|
226
|
+
}
|
227
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
228
|
+
|
229
|
+
white_or_red = '("white" is "great"|"red" is "greater")'
|
230
|
+
|
231
|
+
expect(dson_string).to match(
|
232
|
+
/such "wine" is such #{white_or_red}#{PUNCTUATION_MATCH} #{white_or_red} wow wow/
|
233
|
+
)
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
describe 'DSON hash and array mixes' do
|
239
|
+
|
240
|
+
it 'should handle an array of empty objects' do
|
241
|
+
dson_array = [
|
242
|
+
{}, {}
|
243
|
+
]
|
244
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
245
|
+
|
246
|
+
expect(dson_string).to match(
|
247
|
+
/so such wow #{AND_MATCH} such wow many/
|
248
|
+
)
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'should handle an object with an empty array element' do
|
252
|
+
dson_hash = {
|
253
|
+
array: []
|
254
|
+
}
|
255
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
256
|
+
|
257
|
+
expect(dson_string).to eq(
|
258
|
+
'such "array" is so many wow'
|
259
|
+
)
|
260
|
+
end
|
261
|
+
|
262
|
+
it 'should handle an object with an array element' do
|
263
|
+
dson_hash = {
|
264
|
+
array: %w(olive grape)
|
265
|
+
}
|
266
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
267
|
+
|
268
|
+
expect(dson_string).to match(
|
269
|
+
/such "array" is so "olive" #{AND_MATCH} "grape" many wow/
|
270
|
+
)
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'should handle an array with an object element' do
|
274
|
+
dson_array = [
|
275
|
+
{
|
276
|
+
first_name: 'Cyril',
|
277
|
+
surname: 'Figgis'
|
278
|
+
}
|
279
|
+
]
|
280
|
+
dson_string = DSON.such_serialize_wow(dson_array)
|
281
|
+
|
282
|
+
first_or_last_name = '("first_name" is "Cyril"|"surname" is "Figgis")'
|
283
|
+
|
284
|
+
expect(dson_string).to match(
|
285
|
+
/so such #{first_or_last_name}#{PUNCTUATION_MATCH} #{first_or_last_name} wow many/
|
286
|
+
)
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
describe 'DSON empty' do
|
292
|
+
|
293
|
+
it 'translates a nil object to empty' do
|
294
|
+
dson_hash = {
|
295
|
+
value: nil
|
296
|
+
}
|
297
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
298
|
+
|
299
|
+
expect(dson_string).to eq(
|
300
|
+
'such "value" is empty wow'
|
301
|
+
)
|
302
|
+
end
|
303
|
+
|
304
|
+
end
|
305
|
+
|
306
|
+
describe 'DSON booleans' do
|
307
|
+
|
308
|
+
it 'translates a true object to yes' do
|
309
|
+
dson_hash = {
|
310
|
+
value: true
|
311
|
+
}
|
312
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
313
|
+
|
314
|
+
expect(dson_string).to eq(
|
315
|
+
'such "value" is yes wow'
|
316
|
+
)
|
317
|
+
end
|
318
|
+
|
319
|
+
it 'translates a false object to no' do
|
320
|
+
dson_hash = {
|
321
|
+
value: false
|
322
|
+
}
|
323
|
+
dson_string = DSON.such_serialize_wow(dson_hash)
|
324
|
+
|
325
|
+
expect(dson_string).to eq(
|
326
|
+
'such "value" is no wow'
|
327
|
+
)
|
328
|
+
end
|
329
|
+
|
330
|
+
end
|
331
|
+
|
332
|
+
describe 'ruby objects' do
|
333
|
+
|
334
|
+
it 'translates a trivial class instance to DSON' do
|
335
|
+
ruby_object = DSONSpec::TrivialClass.new
|
336
|
+
dson_string = DSON.such_serialize_wow(ruby_object)
|
337
|
+
|
338
|
+
expect(dson_string).to eq('such wow')
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'translates an example class instance to DSON' do
|
342
|
+
ruby_object = DSONSpec::ExampleClass.new('awesome', 'superb')
|
343
|
+
dson_string = DSON.such_serialize_wow(ruby_object)
|
344
|
+
|
345
|
+
real_or_imaginary = '("name" is "awesome"|"value" is "superb")'
|
346
|
+
|
347
|
+
expect(dson_string).to match(
|
348
|
+
/such #{real_or_imaginary}#{PUNCTUATION_MATCH} #{real_or_imaginary} wow/
|
349
|
+
)
|
350
|
+
end
|
351
|
+
|
352
|
+
end
|
353
|
+
|
354
|
+
# TODO fix when we can do octals generically
|
355
|
+
# describe "DSON numbers" do
|
356
|
+
|
357
|
+
# it "doesn't quote numeric values" do
|
358
|
+
# dson_hash = {
|
359
|
+
# value: 13
|
360
|
+
# }
|
361
|
+
# dson_string = DSON.such_serialize_wow(dson_hash)
|
362
|
+
|
363
|
+
# expect(dson_string).to eq(
|
364
|
+
# 'such "value" is 13 wow'
|
365
|
+
# )
|
366
|
+
# end
|
367
|
+
|
368
|
+
# it "quotes numeric values represented as strings" do
|
369
|
+
# dson_hash = {
|
370
|
+
# value: "13"
|
371
|
+
# }
|
372
|
+
# dson_string = DSON.such_serialize_wow(dson_hash)
|
373
|
+
|
374
|
+
# expect(dson_string).to eq(
|
375
|
+
# 'such "value" is "13" wow'
|
376
|
+
# )
|
377
|
+
# end
|
378
|
+
|
379
|
+
# it "quotes float values" do
|
380
|
+
# dson_hash = {
|
381
|
+
# value: 12.5
|
382
|
+
# }
|
383
|
+
# dson_string = DSON.such_serialize_wow(dson_hash)
|
384
|
+
|
385
|
+
# expect(dson_string).to eq(
|
386
|
+
# 'such "value" is 12.5 wow'
|
387
|
+
# )
|
388
|
+
# end
|
389
|
+
|
390
|
+
# end
|