diff --git a/config/src/test/resources/test09.conf b/config/src/test/resources/test09.conf new file mode 100644 index 00000000..89e8af5f --- /dev/null +++ b/config/src/test/resources/test09.conf @@ -0,0 +1,17 @@ +// This file is testing ConfigDelayedMergeObject and ConfigDelayedMerge + +x={ q : 10 } +y=5 + +a=1 +a.q.r.s=${b} +a=${y} +a=${x} +a={ c : 3 } + +b=${x} +b=${y} + +// nesting ConfigDelayed inside another one +c=${x} +c={ d : 600, e : ${a}, f : ${b} } diff --git a/config/src/test/resources/test10.conf b/config/src/test/resources/test10.conf new file mode 100644 index 00000000..4d0bb955 --- /dev/null +++ b/config/src/test/resources/test10.conf @@ -0,0 +1,5 @@ +// this checks relativizing ConfigDelayedMerge, ConfigDelayedMergeObject + +foo { + include "test09.conf" +} diff --git a/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala b/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala index 7c866f6b..1478729b 100644 --- a/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala +++ b/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala @@ -936,10 +936,44 @@ class ConfigTest extends TestUtils { assertEquals("This is to test classpath searches.", fromURL.getString("test-lib.description")) } + @Test + def test09DelayedMerge() { + val conf = ConfigFactory.parseResources(classOf[ConfigTest], "/test09.conf") + assertEquals(classOf[ConfigDelayedMergeObject].getSimpleName, + conf.root.get("a").getClass.getSimpleName) + assertEquals(classOf[ConfigDelayedMerge].getSimpleName, + conf.root.get("b").getClass.getSimpleName) + + // a.c should work without resolving because no more merging is needed to compute it + assertEquals(3, conf.getInt("a.c")) + + intercept[ConfigException.NotResolved] { + conf.getInt("a.q") + } + + // be sure resolving doesn't throw + val resolved = conf.resolve() + assertEquals(3, resolved.getInt("a.c")) + assertEquals(5, resolved.getInt("b")) + assertEquals(10, resolved.getInt("a.q")) + } + + @Test + def test10DelayedMergeRelativizing() { + val conf = ConfigFactory.parseResources(classOf[ConfigTest], "/test10.conf") + val resolved = conf.resolve() + assertEquals(3, resolved.getInt("foo.a.c")) + assertEquals(5, resolved.getInt("foo.b")) + assertEquals(10, resolved.getInt("foo.a.q")) + } + @Test def renderRoundTrip() { - for (i <- 1 to 6) { - val conf = ConfigFactory.parseResourcesAnySyntax(classOf[ConfigTest], "test0" + i) + for (i <- 1 to 10) { + val numString = i.toString + val name = "/test" + { if (numString.size == 1) "0" else "" } + numString + val conf = ConfigFactory.parseResourcesAnySyntax(classOf[ConfigTest], name, + ConfigParseOptions.defaults().setAllowMissing(false)) val unresolvedRender = conf.root.render() val resolved = conf.resolve() val resolvedRender = resolved.root.render()