mirror of
https://github.com/lightbend/config.git
synced 2025-03-22 15:20:26 +08:00
Indent multi-line values on replacement
Indent multi-line values when they replace a value in a ConfigDocument.
This commit is contained in:
parent
7ec3777c25
commit
a29475ba4a
@ -69,7 +69,15 @@ final class ConfigNodeObject extends ConfigNodeComplexValue {
|
|||||||
}
|
}
|
||||||
} else if (key.equals(desiredPath)) {
|
} else if (key.equals(desiredPath)) {
|
||||||
seenNonMatching = true;
|
seenNonMatching = true;
|
||||||
childrenCopy.set(i, node.replaceValue(value));
|
AbstractConfigNodeValue indentedValue;
|
||||||
|
AbstractConfigNode before = i - 1 > 0 ? childrenCopy.get(i - 1) : null;
|
||||||
|
if (value instanceof ConfigNodeComplexValue &&
|
||||||
|
before instanceof ConfigNodeSingleToken &&
|
||||||
|
Tokens.isIgnoredWhitespace(((ConfigNodeSingleToken) before).token()))
|
||||||
|
indentedValue = ((ConfigNodeComplexValue) value).indentText(before);
|
||||||
|
else
|
||||||
|
indentedValue = value;
|
||||||
|
childrenCopy.set(i, node.replaceValue(indentedValue));
|
||||||
valueCopy = null;
|
valueCopy = null;
|
||||||
} else if (desiredPath.startsWith(key)) {
|
} else if (desiredPath.startsWith(key)) {
|
||||||
seenNonMatching = true;
|
seenNonMatching = true;
|
||||||
|
@ -413,4 +413,17 @@ class ConfigDocumentTest extends TestUtils {
|
|||||||
assertEquals("a { b {\n c: d\n}, e : f }", configDocument.setValue("a.e", "f").render())
|
assertEquals("a { b {\n c: d\n}, e : f }", configDocument.setValue("a.e", "f").render())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
def configDocumentIndentationReplacingWithMultiLineValue {
|
||||||
|
var origText = "a {\n b {\n c : 22\n }\n}"
|
||||||
|
var configDocument = ConfigDocumentFactory.parseString(origText)
|
||||||
|
|
||||||
|
assertEquals("a {\n b {\n c : {\n d:e\n }\n }\n}", configDocument.setValue("a.b.c", "{\n d:e\n}").render())
|
||||||
|
|
||||||
|
origText = "a {\n b {\n f : 10\n c : 22\n }\n}"
|
||||||
|
configDocument = ConfigDocumentFactory.parseString(origText)
|
||||||
|
|
||||||
|
assertEquals("a {\n b {\n f : 10\n c : {\n d:e\n }\n }\n}", configDocument.setValue("a.b.c", "{\n d:e\n}").render())
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user