test/grammar_test.rb in toml-rb-0.3.10 vs test/grammar_test.rb in toml-rb-0.3.11
- old
+ new
@@ -32,12 +32,16 @@
match = TOML::Document.parse('["first key"."second key"]', root: :keygroup)
assert_equal(['first key', 'second key'],
match.value.instance_variable_get('@nested_keys'))
+ match = TOML::Document.parse('[ owner . emancu ]', root: :keygroup)
+ assert_equal(%w(owner emancu),
+ match.value.instance_variable_get('@nested_keys'))
+
assert_raises Citrus::ParseError do
- TOML::Document.parse('[ owner . emancu ]', root: :keygroup)
+ TOML::Document.parse('[ owner emancu ]', root: :keygroup)
end
end
def test_keyvalue
indentation_alternatives_for('key = "value"') do |str|
@@ -187,18 +191,29 @@
multiline_array = "[\n 1 , # useless comment\n # 2,\n 3 #other comment\n]"
match = TOML::Document.parse(multiline_array, root: :array)
assert_equal([1, 3], match.value)
end
+ # Dates are really hard to test from JSON, due the imposibility to represent
+ # datetimes without quotes.
def test_datetime
match = TOML::Document.parse('1986-08-28T15:15:00Z', root: :datetime)
assert_equal(Time.utc(1986, 8, 28, 15, 15), match.value)
match = TOML::Document.parse('1986-08-28T15:15:00-03:00', root: :datetime)
assert_equal(Time.utc(1986, 8, 28, 18, 15), match.value)
match = TOML::Document.parse('1986-08-28T15:15:00.123-03:00', root: :datetime)
assert_equal(Time.utc(1986, 8, 28, 18, 15, 0.123), match.value)
+
+ match = TOML::Document.parse('1986-08-28', root: :datetime)
+ assert_equal(Time.utc(1986, 8, 28, 0, 0, 0), match.value)
+
+ match = TOML::Document.parse('1986-08-28T15:15:00', root: :datetime)
+ assert_equal(Time.utc(1986, 8, 28, 15, 15), match.value)
+
+ match = TOML::Document.parse('1986-08-28T15:15:00.999999', root: :datetime)
+ assert_equal(Time.utc(1986, 8, 28, 15, 15, 0.999999), match.value)
end
def test_inline_table
match = TOML::Document.parse('{ }', root: :inline_table)
assert_equal({}, match.value.value)