Add test for empty document insertion

Add a test for inserting a value into an empty ConfigDocument.
This commit is contained in:
Preben Ingvaldsen 2015-04-09 13:54:46 -07:00
parent b60b37bb9c
commit 78c0612190
2 changed files with 10 additions and 2 deletions

View File

@ -194,7 +194,7 @@ final class ConfigNodeObject extends ConfigNodeComplexValue {
} }
// Otherwise, construct the new setting // 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; ((ConfigNodeSingleToken) super.children.get(0)).token() == Tokens.OPEN_CURLY;
ArrayList<AbstractConfigNode> newNodes = new ArrayList<AbstractConfigNode>(); ArrayList<AbstractConfigNode> newNodes = new ArrayList<AbstractConfigNode>();
newNodes.addAll(indentation); newNodes.addAll(indentation);
@ -260,7 +260,7 @@ final class ConfigNodeObject extends ConfigNodeComplexValue {
} }
} }
if (!startsWithBrace) { 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())) Tokens.isNewline(((ConfigNodeSingleToken) childrenCopy.get(childrenCopy.size() - 1)).token()))
childrenCopy.add(childrenCopy.size() - 1, new ConfigNodeField(newNodes)); childrenCopy.add(childrenCopy.size() - 1, new ConfigNodeField(newNodes));
else else

View File

@ -429,4 +429,12 @@ class ConfigDocumentTest extends TestUtils {
assertEquals("a : b\n include \"foo\"\n c : d\n", configDocument.setValue("c", "d").render()) 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)
}
} }