mirror of
https://github.com/lightbend/config.git
synced 2025-03-16 20:30:25 +08:00
Add test for empty document insertion
Add a test for inserting a value into an empty ConfigDocument.
This commit is contained in:
parent
b60b37bb9c
commit
78c0612190
@ -194,7 +194,7 @@ final class ConfigNodeObject extends ConfigNodeComplexValue {
|
||||
}
|
||||
|
||||
// Otherwise, construct the new setting
|
||||
boolean startsWithBrace = super.children.get(0) instanceof ConfigNodeSingleToken &&
|
||||
boolean startsWithBrace = !super.children.isEmpty() && super.children.get(0) instanceof ConfigNodeSingleToken &&
|
||||
((ConfigNodeSingleToken) super.children.get(0)).token() == Tokens.OPEN_CURLY;
|
||||
ArrayList<AbstractConfigNode> newNodes = new ArrayList<AbstractConfigNode>();
|
||||
newNodes.addAll(indentation);
|
||||
@ -260,7 +260,7 @@ final class ConfigNodeObject extends ConfigNodeComplexValue {
|
||||
}
|
||||
}
|
||||
if (!startsWithBrace) {
|
||||
if (childrenCopy.get(childrenCopy.size() - 1) instanceof ConfigNodeSingleToken &&
|
||||
if (!childrenCopy.isEmpty() && childrenCopy.get(childrenCopy.size() - 1) instanceof ConfigNodeSingleToken &&
|
||||
Tokens.isNewline(((ConfigNodeSingleToken) childrenCopy.get(childrenCopy.size() - 1)).token()))
|
||||
childrenCopy.add(childrenCopy.size() - 1, new ConfigNodeField(newNodes));
|
||||
else
|
||||
|
@ -429,4 +429,12 @@ class ConfigDocumentTest extends TestUtils {
|
||||
assertEquals("a : b\n include \"foo\"\n c : d\n", configDocument.setValue("c", "d").render())
|
||||
}
|
||||
|
||||
@Test
|
||||
def configDocumentEmptyTest {
|
||||
val origText = ""
|
||||
val configDocument = ConfigDocumentFactory.parseString(origText)
|
||||
|
||||
assertEquals(" a : 1", configDocument.setValue("a", "1").render)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user