toml-rb 0.3.3 → 0.3.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 456e1b9091b137468a277e2b17c372d501c99f4c
4
- data.tar.gz: 8bedf195ab7511437086ad6c1edb9c745a272580
3
+ metadata.gz: 681f49b6d33e70fda3a96c8ad18340ae87fe47de
4
+ data.tar.gz: 89de4dfd9c4590ddfcca2f00de5f4a7095163a2c
5
5
  SHA512:
6
- metadata.gz: 53363a94a807d9c5c1ff595b2e2affc7f37bb624b3ff42218953cfb51bf6b3d0c13680af5d1ac9d15c6690ed14339825eb91e657946f4dd75816a6219a2147c8
7
- data.tar.gz: e2992a3d295b23f51c20cc1a915499ea1997f63b15cbd2c8645d1e0d3bd0df4d913b9a4ccd4da5d13915822fdbdda22078941cfe0b7981792be9fc46411e6caf
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
- ("[" indent? (elements)* ","? indent? comment? indent? "]" indent?) { eval(to_str) }
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
- comment | float_array | string_array | array_array | integer_array | datetime_array | bool_array
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 ("," indent? (float | comment))*)
17
+ (float ("," array_comments float)*)
14
18
  end
15
19
 
16
20
  rule string_array
17
- (string ("," indent? (string | comment))*)
21
+ (string ("," array_comments string)*)
18
22
  end
19
23
 
20
24
  rule array_array
21
- (array ("," indent? (array | comment))*)
25
+ (array ("," array_comments array)*)
22
26
  end
23
27
 
24
28
  rule integer_array
25
- (integer ("," indent? (integer | comment))*)
29
+ (integer ("," array_comments integer)*)
26
30
  end
27
31
 
28
32
  rule datetime_array
29
- (datetime ("," indent? (datetime | comment))*)
33
+ (datetime ("," array_comments datetime)*)
30
34
  end
31
35
 
32
36
  rule bool_array
33
- (bool ("," indent? (bool | comment))*)
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; end
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[key]
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'toml-rb'
3
- s.version = '0.3.3'
3
+ s.version = '0.3.4'
4
4
  s.date = Time.now.strftime('%Y-%m-%d')
5
5
  s.summary = 'TOML parser in ruby, for ruby.'
6
6
  s.description = 'A TOML parser using Citrus parsing library. '
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.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-04-17 00:00:00.000000000 Z
12
+ date: 2015-05-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: citrus