Look at includes when finding indentation

Modify the indentation calculation algorithm to also look at the
indentation before include nodes.
This commit is contained in:
Preben Ingvaldsen 2015-04-01 10:57:49 -07:00
parent 1b257fd426
commit dc567e8489
2 changed files with 11 additions and 2 deletions

View File

@ -131,7 +131,8 @@ final class ConfigNodeObject extends ConfigNodeComplexValue {
} else {
if (children.get(i) instanceof ConfigNodeSingleToken &&
Tokens.isIgnoredWhitespace(((ConfigNodeSingleToken) children.get(i)).token()) &&
i + 1 < children.size() && children.get(i+1) instanceof ConfigNodeField) {
i + 1 < children.size() && (children.get(i+1) instanceof ConfigNodeField ||
children.get(i+1) instanceof ConfigNodeInclude)) {
// Return the indentation of the first setting on its own line
indentation.add(children.get(i));
return indentation;

View File

@ -432,7 +432,15 @@ class ConfigDocumentTest extends TestUtils {
val configDocument = ConfigDocumentFactory.parseString(origText)
assertEquals("a {\n b {\n c : 22\n d : {\n include \"foo\"\n e:f\n }\n }\n}",
configDocument.setValue("a.b.d", "{\n include \"foo\"\n e:f\n}").render())
configDocument.setValue("a.b.d", "{\n include \"foo\"\n e:f\n}").render())
}
@Test
def configDocumentIndentationBadedOnIncludeNode {
val origText = "a : b\n include \"foo\"\n"
val configDocument = ConfigDocumentFactory.parseString(origText)
assertEquals("a : b\n include \"foo\"\n c : d\n", configDocument.setValue("c", "d").render())
}
}