DSON 0.0.3 → 0.1.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/README.md +13 -1
- data/lib/DSON.rb +4 -0
- data/lib/DSON/value.rb +63 -0
- data/lib/DSON/value/array_value.rb +24 -0
- data/lib/DSON/value/false_value.rb +5 -0
- data/lib/DSON/value/hash_value.rb +31 -0
- data/lib/DSON/value/nil_value.rb +5 -0
- data/lib/DSON/value/object_value.rb +5 -1
- data/lib/DSON/value/string_value.rb +5 -0
- data/lib/DSON/value/true_value.rb +5 -0
- data/lib/DSON/version.rb +2 -2
- data/spec/lib/example_class.rb +1 -0
- data/spec/parsing_spec.rb +292 -0
- data/spec/{dson_spec.rb → serialization_spec.rb} +4 -4
- metadata +16 -14
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# DSON
|
2
2
|
|
3
|
-
Such serialization! Totally pure-ruby also completely DSON. Wow!
|
3
|
+
Such serialization now also parsing! Totally pure-ruby also completely DSON. Wow!
|
4
4
|
|
5
5
|
Currently known deficiencies:
|
6
6
|
* Number handling (needs to be octal, currently treated as string)
|
@@ -21,6 +21,8 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
+
*Serialization*
|
25
|
+
|
24
26
|
Currently supports a ruby object, hash and array data structure and outputs it's representation in DSON ([Doge Serialized Object notation](http://dogeon.org/)). By way of an example, try:
|
25
27
|
|
26
28
|
require 'DSON'
|
@@ -41,6 +43,16 @@ Correct to the DSON spec.
|
|
41
43
|
|
42
44
|
Try it out with custom ruby objects too!
|
43
45
|
|
46
|
+
*Parsing*
|
47
|
+
|
48
|
+
Surrently should parse a DSON object given as a string. Not the world's best put together parse but should function reasonably with general DSON strings. Try
|
49
|
+
|
50
|
+
require 'DSON'
|
51
|
+
|
52
|
+
puts DSON.so_parse(
|
53
|
+
'such "ruby" is "pure", "supports" is so "hash" also "array" many wow'
|
54
|
+
)
|
55
|
+
|
44
56
|
## Contributing
|
45
57
|
|
46
58
|
1. Fork it ( https://github.com/[my-github-username]/DSON/fork )
|
data/lib/DSON.rb
CHANGED
data/lib/DSON/value.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
+
# -*- encoding : utf-8 -*-
|
2
3
|
require 'DSON/value/hash_value'
|
3
4
|
require 'DSON/value/array_value'
|
4
5
|
require 'DSON/value/string_value'
|
@@ -23,6 +24,68 @@ module DSON
|
|
23
24
|
ObjectValue.new(value)
|
24
25
|
end
|
25
26
|
|
27
|
+
def self.so_parse(dson_string)
|
28
|
+
string_hash, replaced_string = remove_all_strings(dson_string)
|
29
|
+
handle_next(
|
30
|
+
word_array: replaced_string.gsub(/,|\?|!|\./, ' ,').split(' '),
|
31
|
+
string_hash: string_hash
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.handle_next(options)
|
36
|
+
word_array = options[:word_array]
|
37
|
+
|
38
|
+
fail 'An error has occurred, this could be either user error or a bug. Please check your DSON is valid, and if it is, please raise a GitHub issue' if word_array.empty?
|
39
|
+
|
40
|
+
first_word = word_array.shift
|
41
|
+
|
42
|
+
if first_word == 'such'
|
43
|
+
return HashValue.so_parse(
|
44
|
+
word_array: word_array,
|
45
|
+
parent_hash: {},
|
46
|
+
string_hash: options[:string_hash]
|
47
|
+
)
|
48
|
+
end
|
49
|
+
if first_word == 'so'
|
50
|
+
return ArrayValue.so_parse(
|
51
|
+
word_array: word_array,
|
52
|
+
parent_array: [],
|
53
|
+
string_hash: options[:string_hash]
|
54
|
+
)
|
55
|
+
end
|
56
|
+
return TrueValue.so_parse if first_word == 'yes'
|
57
|
+
return FalseValue.so_parse if first_word == 'no'
|
58
|
+
return NilValue.so_parse if first_word == 'empty'
|
59
|
+
|
60
|
+
options[:first_word] = first_word
|
61
|
+
StringValue.so_parse(options)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Class methods can't be accessed from subclasses if protected...
|
65
|
+
# Find better way if possible
|
66
|
+
def self.remove_first_and_last_words(string)
|
67
|
+
non_whitespace_elements = string.split(' ')
|
68
|
+
non_whitespace_elements.pop
|
69
|
+
non_whitespace_elements.shift
|
70
|
+
non_whitespace_elements.join(' ')
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.remove_first_and_last_elements(array)
|
74
|
+
array.pop
|
75
|
+
array.shift
|
76
|
+
end
|
77
|
+
|
78
|
+
protected
|
79
|
+
|
80
|
+
def self.remove_all_strings(dson_string)
|
81
|
+
string_hash = {}
|
82
|
+
replaced_string = dson_string.gsub(/"(.*?)"/).with_index do |match, index|
|
83
|
+
string_hash[index] = match[1..-2]
|
84
|
+
index
|
85
|
+
end
|
86
|
+
[string_hash, replaced_string]
|
87
|
+
end
|
88
|
+
|
26
89
|
def reduce(list, potential_joiners)
|
27
90
|
list.each_with_index.reduce('') do |acc, (element, index)|
|
28
91
|
is_last = (index == list.size - 1)
|
@@ -1,9 +1,27 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
+
require 'DSON/value'
|
3
|
+
|
2
4
|
module DSON
|
3
5
|
module Value
|
4
6
|
class ArrayValue
|
5
7
|
include Value
|
6
8
|
|
9
|
+
def self.so_parse(options)
|
10
|
+
word_array = options[:word_array]
|
11
|
+
parent_array = options[:parent_array]
|
12
|
+
|
13
|
+
if word_array[0] == 'many'
|
14
|
+
word_array.shift
|
15
|
+
return parent_array
|
16
|
+
end
|
17
|
+
word_array.shift unless (word_array[0] =~ /and|also/).nil?
|
18
|
+
|
19
|
+
# the next value will be the value
|
20
|
+
parent_array.push(DSON::Value.handle_next(options))
|
21
|
+
|
22
|
+
so_parse(options)
|
23
|
+
end
|
24
|
+
|
7
25
|
POTENTIAL_JOINERS = [' and' , ' also']
|
8
26
|
|
9
27
|
attr_reader :value
|
@@ -18,6 +36,12 @@ module DSON
|
|
18
36
|
end
|
19
37
|
'so ' + reduce(content, POTENTIAL_JOINERS) + 'many'
|
20
38
|
end
|
39
|
+
|
40
|
+
AND_ALSO_REGEX = / and | also /
|
41
|
+
|
42
|
+
def self.parse_value(value, acc_array)
|
43
|
+
acc_array.push DSON.so_parse(value)
|
44
|
+
end
|
21
45
|
end
|
22
46
|
end
|
23
47
|
end
|
@@ -6,6 +6,31 @@ module DSON
|
|
6
6
|
class HashValue
|
7
7
|
include Value
|
8
8
|
|
9
|
+
def self.so_parse(options)
|
10
|
+
word_array = options[:word_array]
|
11
|
+
parent_hash = options[:parent_hash]
|
12
|
+
|
13
|
+
if word_array[0] == 'wow'
|
14
|
+
word_array.shift
|
15
|
+
return parent_hash
|
16
|
+
end
|
17
|
+
word_array.shift unless (word_array[0] =~ (/\?|\.|,|!/)).nil?
|
18
|
+
|
19
|
+
string_hash = options[:string_hash]
|
20
|
+
|
21
|
+
# The next value will be a key
|
22
|
+
numeric_key = word_array.shift
|
23
|
+
key = string_hash[numeric_key.to_i]
|
24
|
+
|
25
|
+
# remove is
|
26
|
+
word_array.shift
|
27
|
+
|
28
|
+
value = DSON::Value.handle_next(options)
|
29
|
+
parent_hash[key] = value
|
30
|
+
|
31
|
+
so_parse(options)
|
32
|
+
end
|
33
|
+
|
9
34
|
POTENTIAL_PUNCTUATION = %w(, . ! ?)
|
10
35
|
|
11
36
|
attr_reader :value
|
@@ -23,6 +48,12 @@ module DSON
|
|
23
48
|
end
|
24
49
|
'such ' + reduce(strings, POTENTIAL_PUNCTUATION) + 'wow'
|
25
50
|
end
|
51
|
+
|
52
|
+
def self.parse_pair(string, acc_hash)
|
53
|
+
results = string.scan(/"(.*)" is (.*)/)
|
54
|
+
acc_hash[results[0][0]] = DSON::Value.so_parse(results[0][1])
|
55
|
+
acc_hash
|
56
|
+
end
|
26
57
|
end
|
27
58
|
end
|
28
59
|
end
|
data/lib/DSON/value/nil_value.rb
CHANGED
@@ -16,7 +16,10 @@ module DSON
|
|
16
16
|
# Construct a hash of the instance variables
|
17
17
|
object_hash = Hash[
|
18
18
|
value.instance_variables.map do |variable|
|
19
|
-
[
|
19
|
+
[
|
20
|
+
remove_at_from_attribute_name(variable),
|
21
|
+
value.instance_variable_get(variable)
|
22
|
+
]
|
20
23
|
end
|
21
24
|
]
|
22
25
|
|
@@ -25,6 +28,7 @@ module DSON
|
|
25
28
|
end
|
26
29
|
|
27
30
|
private
|
31
|
+
|
28
32
|
def remove_at_from_attribute_name(attribute_name)
|
29
33
|
attribute_name[1..-1]
|
30
34
|
end
|
data/lib/DSON/version.rb
CHANGED
data/spec/lib/example_class.rb
CHANGED
@@ -0,0 +1,292 @@
|
|
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
|
@@ -6,7 +6,7 @@ require_relative 'lib/example_class'
|
|
6
6
|
PUNCTUATION_MATCH = '(,|\.|!|\\?)'
|
7
7
|
AND_MATCH = '(and|also)'
|
8
8
|
|
9
|
-
describe '
|
9
|
+
describe 'simple hashes' do
|
10
10
|
|
11
11
|
it 'should be correct with an empty hash' do
|
12
12
|
dson_hash = Hash.new
|
@@ -342,16 +342,16 @@ describe 'ruby objects' do
|
|
342
342
|
ruby_object = DSONSpec::ExampleClass.new('awesome', 'superb')
|
343
343
|
dson_string = DSON.such_serialize_wow(ruby_object)
|
344
344
|
|
345
|
-
|
345
|
+
name_or_value = '("name" is "awesome"|"value" is "superb")'
|
346
346
|
|
347
347
|
expect(dson_string).to match(
|
348
|
-
/such #{
|
348
|
+
/such #{name_or_value}#{PUNCTUATION_MATCH} #{name_or_value} wow/
|
349
349
|
)
|
350
350
|
end
|
351
351
|
|
352
352
|
end
|
353
353
|
|
354
|
-
# TODO fix when we can do octals generically
|
354
|
+
# TODO: fix when we can do octals generically
|
355
355
|
# describe "DSON numbers" do
|
356
356
|
|
357
357
|
# it "doesn't quote numeric values" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: DSON
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-06-
|
12
|
+
date: 2014-06-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &19948880 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.6'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *19948880
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &19948380 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *19948380
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &19947660 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *19947660
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rubocop
|
49
|
-
requirement: &
|
49
|
+
requirement: &19947060 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *19947060
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: magic_encoding
|
60
|
-
requirement: &
|
60
|
+
requirement: &19946380 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *19946380
|
69
69
|
description:
|
70
70
|
email:
|
71
71
|
- imran.pshakir@gmail.com
|
@@ -90,8 +90,9 @@ files:
|
|
90
90
|
- lib/DSON/value/string_value.rb
|
91
91
|
- lib/DSON/value/true_value.rb
|
92
92
|
- lib/DSON/version.rb
|
93
|
-
- spec/dson_spec.rb
|
94
93
|
- spec/lib/example_class.rb
|
94
|
+
- spec/parsing_spec.rb
|
95
|
+
- spec/serialization_spec.rb
|
95
96
|
homepage: ''
|
96
97
|
licenses:
|
97
98
|
- MIT
|
@@ -118,5 +119,6 @@ signing_key:
|
|
118
119
|
specification_version: 3
|
119
120
|
summary: A pure-ruby DSON Serializer
|
120
121
|
test_files:
|
121
|
-
- spec/dson_spec.rb
|
122
122
|
- spec/lib/example_class.rb
|
123
|
+
- spec/parsing_spec.rb
|
124
|
+
- spec/serialization_spec.rb
|