From 0c3448156c93d4c814c3106f5a251d565b68367b Mon Sep 17 00:00:00 2001 From: "moandji.ezana" Date: Sun, 6 Apr 2014 21:34:25 +0200 Subject: [PATCH] Track existing groups by their full name. Fixes #1 --- src/main/java/com/moandjiezana/toml/TomlParser.java | 1 - src/test/java/com/moandjiezana/toml/RealWorldTest.java | 9 +++++++++ ...ld_allow_keys_with_same_name_in_different_groups.toml | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/com/moandjiezana/toml/should_allow_keys_with_same_name_in_different_groups.toml diff --git a/src/main/java/com/moandjiezana/toml/TomlParser.java b/src/main/java/com/moandjiezana/toml/TomlParser.java index 1d6e672..ce4e5ee 100644 --- a/src/main/java/com/moandjiezana/toml/TomlParser.java +++ b/src/main/java/com/moandjiezana/toml/TomlParser.java @@ -155,7 +155,6 @@ class TomlParser extends BaseParser { @SuppressWarnings("unchecked") boolean addKeyGroup(String name) { String[] split = name.split("\\."); - name = split[split.length - 1]; while (getContext().getValueStack().size() > 2) { drop(); diff --git a/src/test/java/com/moandjiezana/toml/RealWorldTest.java b/src/test/java/com/moandjiezana/toml/RealWorldTest.java index 086c519..f0b5c90 100644 --- a/src/test/java/com/moandjiezana/toml/RealWorldTest.java +++ b/src/test/java/com/moandjiezana/toml/RealWorldTest.java @@ -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 map) { for (Map.Entry entry : map.entrySet()) { diff --git a/src/test/resources/com/moandjiezana/toml/should_allow_keys_with_same_name_in_different_groups.toml b/src/test/resources/com/moandjiezana/toml/should_allow_keys_with_same_name_in_different_groups.toml new file mode 100644 index 0000000..471c639 --- /dev/null +++ b/src/test/resources/com/moandjiezana/toml/should_allow_keys_with_same_name_in_different_groups.toml @@ -0,0 +1,4 @@ +[siteInfo.local.sh] +enable=true +[siteInfo.localMobile.sh] +enable=false