mirror of
https://github.com/lightbend/config.git
synced 2025-02-16 06:10:31 +08:00
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:
parent
1b257fd426
commit
dc567e8489
@ -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;
|
||||
|
@ -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())
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user