Track existing groups by their full name.

Fixes #1
This commit is contained in:
moandji.ezana 2014-04-06 21:34:25 +02:00
parent bf08f527a2
commit 0c3448156c
3 changed files with 13 additions and 1 deletions

View file

@ -155,7 +155,6 @@ class TomlParser extends BaseParser<Object> {
@SuppressWarnings("unchecked")
boolean addKeyGroup(String name) {
String[] split = name.split("\\.");
name = split[split.length - 1];
while (getContext().getValueStack().size() > 2) {
drop();

View file

@ -2,6 +2,7 @@ package com.moandjiezana.toml;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.File;
@ -67,6 +68,14 @@ public class RealWorldTest {
assertEquals(asList("]"), theHardBit.getList("multi_line_array", String.class));
}
@Test
public void should_allow_keys_with_same_name_in_different_groups() throws Exception {
Toml toml = new Toml().parse(new File(getClass().getResource("should_allow_keys_with_same_name_in_different_groups.toml").getFile()));
assertTrue(toml.getKeyGroup("siteInfo.local.sh").getBoolean("enable"));
assertFalse(toml.getKeyGroup("siteInfo.localMobile.sh").getBoolean("enable"));
}
@SuppressWarnings("unchecked")
private void printMap(Map<String, Object> map) {
for (Map.Entry<String, Object> entry : map.entrySet()) {

View file

@ -0,0 +1,4 @@
[siteInfo.local.sh]
enable=true
[siteInfo.localMobile.sh]
enable=false