emancu / toml-rb

A parser for TOML using Citrus library.
MIT License
105 stars 39 forks source link

Should fail with error when table is used more than once #63

Closed rsim closed 9 years ago

rsim commented 9 years ago

According to the TOML specification you cannot define table more than once. But currently if table is defined several times and if keys in the table do not overlap then no error is raised:

>> TOML.parse "[a]\nb=1\n[a]\nc=2"
=> {"a"=>{"b"=>1, "c"=>2}}

Due to this also in this case the error message contains key b but it would be more correct to fail with an error message about table a:

>> TOML.parse "[a]\nb=1\n[a]\nb=1"
TOML::ValueOverwriteError: Key "b" is defined more than once

When a key was defined with a scalar value but then later used as a table (which is not valid TOML) then wrong error message is raised:

>> TOML.parse "[a]\nb=1\n[a.b]\nc=2"
NoMethodError: undefined method `key?' for 1:Fixnum

In this case TOML::ValueOverwriteError should be raised about the key b.