toml-rb 0.3.4 → 0.3.5
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.
- checksums.yaml +4 -4
- data/lib/toml/grammars/array.citrus +7 -7
- data/lib/toml/grammars/document.citrus +4 -4
- data/lib/toml/inline_table.rb +2 -2
- data/lib/toml/keygroup.rb +9 -2
- data/test/errors_test.rb +20 -0
- data/test/grammar_test.rb +9 -4
- data/toml-rb.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a98aa52600a975ad1758363c0c21585444b67cd
|
4
|
+
data.tar.gz: c9d03ddf95c5a6f8b6775dbc9acdece8d1e96630
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaaa1515c6fe4681cf2c75000b5bfa303b3b4e1fe468647d00f320baf75646f4169d17a5a19711dd3cc828624da972c1796b85b045b957c8894ecda7b035f09e
|
7
|
+
data.tar.gz: d761b9378f9d0e0d0310958f42bf28a9e8a81f3c29b1b0ce1e0e12dfa3ac3cb4d0810c68344d3d7e720f20a662851e7aa8143c50750da0c175088a811b24cf82
|
@@ -2,7 +2,7 @@ grammar TomlArray
|
|
2
2
|
include Primitive
|
3
3
|
|
4
4
|
rule array
|
5
|
-
("[" array_comments (elements)
|
5
|
+
("[" array_comments (elements)? space ","? array_comments "]" indent?) { eval(to_str) }
|
6
6
|
end
|
7
7
|
|
8
8
|
rule array_comments
|
@@ -14,26 +14,26 @@ grammar TomlArray
|
|
14
14
|
end
|
15
15
|
|
16
16
|
rule float_array
|
17
|
-
(float ("," array_comments float)*)
|
17
|
+
(float (space "," array_comments float)*)
|
18
18
|
end
|
19
19
|
|
20
20
|
rule string_array
|
21
|
-
(string ("," array_comments string)*)
|
21
|
+
(string (space "," array_comments string)*)
|
22
22
|
end
|
23
23
|
|
24
24
|
rule array_array
|
25
|
-
(array ("," array_comments array)*)
|
25
|
+
(array (space "," array_comments array)*)
|
26
26
|
end
|
27
27
|
|
28
28
|
rule integer_array
|
29
|
-
(integer ("," array_comments integer)*)
|
29
|
+
(integer (space "," array_comments integer)*)
|
30
30
|
end
|
31
31
|
|
32
32
|
rule datetime_array
|
33
|
-
(datetime ("," array_comments datetime)*)
|
33
|
+
(datetime (space "," array_comments datetime)*)
|
34
34
|
end
|
35
35
|
|
36
36
|
rule bool_array
|
37
|
-
(bool ("," array_comments bool)*)
|
37
|
+
(bool (space "," array_comments bool)*)
|
38
38
|
end
|
39
39
|
end
|
@@ -23,15 +23,15 @@ grammar Document
|
|
23
23
|
end
|
24
24
|
|
25
25
|
rule inline_table_array
|
26
|
-
("["
|
26
|
+
("[" array_comments inline_table_array_elements space ","? array_comments "]" indent?) <InlineTableArray>
|
27
27
|
end
|
28
28
|
|
29
|
-
rule
|
30
|
-
|
29
|
+
rule inline_table_array_elements
|
30
|
+
(inline_table (space "," array_comments inline_table)*)
|
31
31
|
end
|
32
32
|
|
33
33
|
rule toml_values
|
34
|
-
primitive |
|
34
|
+
primitive | inline_table | array | inline_table_array
|
35
35
|
end
|
36
36
|
|
37
37
|
|
data/lib/toml/inline_table.rb
CHANGED
@@ -63,8 +63,8 @@ end
|
|
63
63
|
|
64
64
|
module InlineTableArray
|
65
65
|
def value
|
66
|
-
tables = captures[:
|
66
|
+
tables = captures[:inline_table_array_elements].map { |x| x.captures[:inline_table] }
|
67
67
|
|
68
|
-
TOML::InlineTableArray.new
|
68
|
+
TOML::InlineTableArray.new(tables.flatten.map(&:value)).value
|
69
69
|
end
|
70
70
|
end
|
data/lib/toml/keygroup.rb
CHANGED
@@ -5,11 +5,18 @@ module TOML
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def navigate_keys(hash, symbolize_keys = false)
|
8
|
-
@nested_keys.
|
8
|
+
last_index = @nested_keys.length - 1
|
9
|
+
@nested_keys.each_with_index do |key, i|
|
9
10
|
key = symbolize_keys ? key.to_sym : key
|
10
|
-
|
11
|
+
# do not allow to define more than once just the last key
|
12
|
+
if i == last_index && hash.key?(key)
|
13
|
+
fail ValueOverwriteError.new(key)
|
14
|
+
end
|
15
|
+
hash[key] = {} unless hash.key?(key)
|
11
16
|
element = hash[key]
|
12
17
|
hash = element.is_a?(Array) ? element.last : element
|
18
|
+
# check that key has not been defined before as a scalar value
|
19
|
+
fail ValueOverwriteError.new(key) unless hash.is_a?(Hash)
|
13
20
|
end
|
14
21
|
|
15
22
|
hash
|
data/test/errors_test.rb
CHANGED
@@ -65,4 +65,24 @@ class ErrorsTest < Test::Unit::TestCase
|
|
65
65
|
str = "a = false\na = true"
|
66
66
|
assert_raises(TOML::ValueOverwriteError) { TOML.parse(str) }
|
67
67
|
end
|
68
|
+
|
69
|
+
def test_table_overwrite
|
70
|
+
str = "[a]\nb=1\n[a]\nc=2"
|
71
|
+
e = assert_raises(TOML::ValueOverwriteError) { TOML.parse(str) }
|
72
|
+
assert_equal "Key \"a\" is defined more than once", e.message
|
73
|
+
|
74
|
+
str = "[a]\nb=1\n[a]\nb=1"
|
75
|
+
e = assert_raises(TOML::ValueOverwriteError) { TOML.parse(str) }
|
76
|
+
assert_equal "Key \"a\" is defined more than once", e.message
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_value_overwrite_with_table
|
80
|
+
str = "[a]\nb=1\n[a.b]\nc=2"
|
81
|
+
e = assert_raises(TOML::ValueOverwriteError) { TOML.parse(str) }
|
82
|
+
assert_equal "Key \"b\" is defined more than once", e.message
|
83
|
+
|
84
|
+
str = "[a]\nb=1\n[a.b.c]\nd=3"
|
85
|
+
e = assert_raises(TOML::ValueOverwriteError) { TOML.parse(str) }
|
86
|
+
assert_equal "Key \"b\" is defined more than once", e.message
|
87
|
+
end
|
68
88
|
end
|
data/test/grammar_test.rb
CHANGED
@@ -146,11 +146,16 @@ class GrammarTest < Test::Unit::TestCase
|
|
146
146
|
assert_equal([%w(hey TOML), [2, 4]], match.value)
|
147
147
|
|
148
148
|
match = Document.parse('[ { one = 1 }, { two = 2, three = 3} ]',
|
149
|
-
root: :inline_table_array)
|
150
|
-
|
149
|
+
root: :inline_table_array)
|
151
150
|
assert_equal([{ 'one' => 1 }, { 'two' => 2, 'three' => 3 }], match.value)
|
152
151
|
end
|
153
152
|
|
153
|
+
def test_empty_array
|
154
|
+
# test that [] is parsed as array and not as inline table array
|
155
|
+
match = Document.parse("a = []", root: :keyvalue).value
|
156
|
+
assert_equal [], match.value
|
157
|
+
end
|
158
|
+
|
154
159
|
def test_multiline_array
|
155
160
|
multiline_array = "[ \"hey\",\n \"ho\",\n\t \"lets\", \"go\",\n ]"
|
156
161
|
match = Document.parse(multiline_array, root: :array)
|
@@ -164,11 +169,11 @@ class GrammarTest < Test::Unit::TestCase
|
|
164
169
|
match = Document.parse(multiline_array, root: :array)
|
165
170
|
assert_equal([4], match.value)
|
166
171
|
|
167
|
-
multiline_array = "[\n 1,\n # 2,\n 3,\n]"
|
172
|
+
multiline_array = "[\n 1,\n # 2,\n 3 ,\n]"
|
168
173
|
match = Document.parse(multiline_array, root: :array)
|
169
174
|
assert_equal([1, 3], match.value)
|
170
175
|
|
171
|
-
multiline_array = "[\n 1, # useless comment\n # 2,\n 3 #other comment\n]"
|
176
|
+
multiline_array = "[\n 1 , # useless comment\n # 2,\n 3 #other comment\n]"
|
172
177
|
match = Document.parse(multiline_array, root: :array)
|
173
178
|
assert_equal([1, 3], match.value)
|
174
179
|
end
|
data/toml-rb.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toml-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emiliano Mancuso
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-05-
|
12
|
+
date: 2015-05-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: citrus
|