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