toml-rb 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/toml/grammars/array.citrus +12 -8
- data/lib/toml/keyvalue.rb +9 -2
- data/test/errors_test.rb +10 -0
- data/test/grammar_test.rb +8 -0
- 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: 681f49b6d33e70fda3a96c8ad18340ae87fe47de
|
4
|
+
data.tar.gz: 89de4dfd9c4590ddfcca2f00de5f4a7095163a2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e503fb60c21c93a8c523584370ae4a7593a6b83536ead6c73672fe2639288020e16cf7edf357c4d90569d2e7105533d20ca74307f9c18823239f3f5437ce74ea
|
7
|
+
data.tar.gz: ff4151d6f24b60936a538220bb4eb7ae66f12eb5051a99c21b7c6a2eb5b86ff8a1a65792d9a821e289e5be7489f1d8a1827f857b726d5310b44a89f5339f02dd
|
@@ -2,34 +2,38 @@ grammar TomlArray
|
|
2
2
|
include Primitive
|
3
3
|
|
4
4
|
rule array
|
5
|
-
("["
|
5
|
+
("[" array_comments (elements)* ","? array_comments "]" indent?) { eval(to_str) }
|
6
|
+
end
|
7
|
+
|
8
|
+
rule array_comments
|
9
|
+
(indent? comment* indent?)
|
6
10
|
end
|
7
11
|
|
8
12
|
rule elements
|
9
|
-
|
13
|
+
float_array | string_array | array_array | integer_array | datetime_array | bool_array
|
10
14
|
end
|
11
15
|
|
12
16
|
rule float_array
|
13
|
-
(float (","
|
17
|
+
(float ("," array_comments float)*)
|
14
18
|
end
|
15
19
|
|
16
20
|
rule string_array
|
17
|
-
(string (","
|
21
|
+
(string ("," array_comments string)*)
|
18
22
|
end
|
19
23
|
|
20
24
|
rule array_array
|
21
|
-
(array (","
|
25
|
+
(array ("," array_comments array)*)
|
22
26
|
end
|
23
27
|
|
24
28
|
rule integer_array
|
25
|
-
(integer (","
|
29
|
+
(integer ("," array_comments integer)*)
|
26
30
|
end
|
27
31
|
|
28
32
|
rule datetime_array
|
29
|
-
(datetime (","
|
33
|
+
(datetime ("," array_comments datetime)*)
|
30
34
|
end
|
31
35
|
|
32
36
|
rule bool_array
|
33
|
-
(bool (","
|
37
|
+
(bool ("," array_comments bool)*)
|
34
38
|
end
|
35
39
|
end
|
data/lib/toml/keyvalue.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
module TOML
|
2
|
-
class ValueOverwriteError < StandardError
|
2
|
+
class ValueOverwriteError < StandardError
|
3
|
+
attr_accessor :key
|
4
|
+
|
5
|
+
def initialize(key)
|
6
|
+
self.key = key
|
7
|
+
super "Key #{key.inspect} is defined more than once"
|
8
|
+
end
|
9
|
+
end
|
3
10
|
|
4
11
|
class Keyvalue
|
5
12
|
attr_reader :value, :symbolize_keys
|
@@ -10,7 +17,7 @@ module TOML
|
|
10
17
|
|
11
18
|
def assign(hash, symbolize_keys = false)
|
12
19
|
@symbolize_keys = symbolize_keys
|
13
|
-
fail ValueOverwriteError if hash
|
20
|
+
fail ValueOverwriteError.new(key) if hash.key?(key)
|
14
21
|
hash[key] = visit_value @value
|
15
22
|
end
|
16
23
|
|
data/test/errors_test.rb
CHANGED
@@ -55,4 +55,14 @@ class ErrorsTest < Test::Unit::TestCase
|
|
55
55
|
str = 'number = 3.14 pi <--again forgot the #'
|
56
56
|
assert_raises(TOML::ParseError) { TOML.parse(str) }
|
57
57
|
end
|
58
|
+
|
59
|
+
def test_value_overwrite
|
60
|
+
str = "a = 1\na = 2"
|
61
|
+
e = assert_raises(TOML::ValueOverwriteError) { TOML.parse(str) }
|
62
|
+
assert_equal "Key \"a\" is defined more than once", e.message
|
63
|
+
assert_equal "a", e.key
|
64
|
+
|
65
|
+
str = "a = false\na = true"
|
66
|
+
assert_raises(TOML::ValueOverwriteError) { TOML.parse(str) }
|
67
|
+
end
|
58
68
|
end
|
data/test/grammar_test.rb
CHANGED
@@ -163,6 +163,14 @@ class GrammarTest < Test::Unit::TestCase
|
|
163
163
|
multiline_array = "[\n# comment\n#, more comments\n4]"
|
164
164
|
match = Document.parse(multiline_array, root: :array)
|
165
165
|
assert_equal([4], match.value)
|
166
|
+
|
167
|
+
multiline_array = "[\n 1,\n # 2,\n 3,\n]"
|
168
|
+
match = Document.parse(multiline_array, root: :array)
|
169
|
+
assert_equal([1, 3], match.value)
|
170
|
+
|
171
|
+
multiline_array = "[\n 1, # useless comment\n # 2,\n 3 #other comment\n]"
|
172
|
+
match = Document.parse(multiline_array, root: :array)
|
173
|
+
assert_equal([1, 3], match.value)
|
166
174
|
end
|
167
175
|
|
168
176
|
def test_datetime
|
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.4
|
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-
|
12
|
+
date: 2015-05-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: citrus
|