Skip to content

Commit

Permalink
Handle a concatenation that doesn't resolve
Browse files Browse the repository at this point in the history
Fixes #140
  • Loading branch information
havocp committed Feb 10, 2014
1 parent f3cb6b1 commit 91e5e81
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,15 @@ AbstractConfigValue resolveSubstitutions(ResolveContext context) throws NotPossi

// now need to concat everything
List<AbstractConfigValue> joined = consolidate(resolved);
if (joined.size() != 1)
// if unresolved is allowed we can just become another
// ConfigConcatenation
if (joined.size() > 1 && context.options().getAllowUnresolved())
return new ConfigConcatenation(this.origin(), joined);
else if (joined.size() != 1)
throw new ConfigException.BugOrBroken(
"Resolved list should always join to exactly one value, not " + joined);
return joined.get(0);
else
return joined.get(0);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ class ConfigTest extends TestUtils {
def allowUnresolvedDoesAllowUnresolved() {
val values = ConfigFactory.parseString("{ foo = 1, bar = 2, m = 3, n = 4}")
assertTrue("config with no substitutions starts as resolved", values.isResolved)
val unresolved = ConfigFactory.parseString("a = ${foo}, b = ${bar}, c { x = ${m}, y = ${n} }, alwaysResolveable=${alwaysValue}, alwaysValue=42")
val unresolved = ConfigFactory.parseString("a = ${foo}, b = ${bar}, c { x = ${m}, y = ${n}, z = foo${m}bar }, alwaysResolveable=${alwaysValue}, alwaysValue=42")
assertFalse("config with substitutions starts as not resolved", unresolved.isResolved)

// resolve() by default throws with unresolveable substs
Expand All @@ -1140,6 +1140,8 @@ class ConfigTest extends TestUtils {
for (k <- Seq("a", "b", "c.x", "c.y")) {
intercept[ConfigException.NotResolved] { allowedUnresolved.getInt(k) }
}
intercept[ConfigException.NotResolved] { allowedUnresolved.getString("c.z") }

// and the partially-resolved thing is not resolved
assertFalse("partially-resolved object is not resolved", allowedUnresolved.isResolved)

Expand All @@ -1150,6 +1152,7 @@ class ConfigTest extends TestUtils {
for (kv <- Seq("a" -> 1, "b" -> 2, "c.x" -> 3, "c.y" -> 4)) {
assertEquals(kv._2, resolved.getInt(kv._1))
}
assertEquals("foo3bar", resolved.getString("c.z"))
assertTrue("fully resolved object is resolved", resolved.isResolved)
}

Expand All @@ -1159,6 +1162,7 @@ class ConfigTest extends TestUtils {
for (kv <- Seq("a" -> 1, "b" -> 2, "c.x" -> 3, "c.y" -> 4)) {
assertEquals(kv._2, resolved.getInt(kv._1))
}
assertEquals("foo3bar", resolved.getString("c.z"))
assertTrue("fully resolved object is resolved", resolved.isResolved)
}
}
Expand Down

0 comments on commit 91e5e81

Please sign in to comment.