mirror of
https://github.com/lightbend/config.git
synced 2025-03-29 21:51:10 +08:00
Merge pull request #260 from typesafehub/newlines-in-description
In render, put comment char in front of every description line
This commit is contained in:
commit
0e722a10cd
@ -211,10 +211,15 @@ final class SimpleConfigList extends AbstractConfigValue implements ConfigList,
|
|||||||
sb.append('\n');
|
sb.append('\n');
|
||||||
for (AbstractConfigValue v : value) {
|
for (AbstractConfigValue v : value) {
|
||||||
if (options.getOriginComments()) {
|
if (options.getOriginComments()) {
|
||||||
indent(sb, indent + 1, options);
|
String[] lines = v.origin().description().split("\n");
|
||||||
sb.append("# ");
|
for (String l : lines) {
|
||||||
sb.append(v.origin().description());
|
indent(sb, indent + 1, options);
|
||||||
sb.append("\n");
|
sb.append('#');
|
||||||
|
if (!l.isEmpty())
|
||||||
|
sb.append(' ');
|
||||||
|
sb.append(l);
|
||||||
|
sb.append("\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (options.getComments()) {
|
if (options.getComments()) {
|
||||||
for (String comment : v.origin().comments()) {
|
for (String comment : v.origin().comments()) {
|
||||||
|
@ -444,10 +444,15 @@ final class SimpleConfigObject extends AbstractConfigObject implements Serializa
|
|||||||
v = value.get(k);
|
v = value.get(k);
|
||||||
|
|
||||||
if (options.getOriginComments()) {
|
if (options.getOriginComments()) {
|
||||||
indent(sb, innerIndent, options);
|
String[] lines = v.origin().description().split("\n");
|
||||||
sb.append("# ");
|
for (String l : lines) {
|
||||||
sb.append(v.origin().description());
|
indent(sb, indent + 1, options);
|
||||||
sb.append("\n");
|
sb.append('#');
|
||||||
|
if (!l.isEmpty())
|
||||||
|
sb.append(' ');
|
||||||
|
sb.append(l);
|
||||||
|
sb.append("\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (options.getComments()) {
|
if (options.getComments()) {
|
||||||
for (String comment : v.origin().comments()) {
|
for (String comment : v.origin().comments()) {
|
||||||
|
@ -938,4 +938,25 @@ class ConfigValueTest extends TestUtils {
|
|||||||
assertEquals(bottom(v), bottom(deserialized))
|
assertEquals(bottom(v), bottom(deserialized))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
def renderWithNewlinesInDescription(): Unit = {
|
||||||
|
val v = ConfigValueFactory.fromAnyRef(89, "this is a description\nwith some\nnewlines")
|
||||||
|
val list = new SimpleConfigList(SimpleConfigOrigin.newSimple("\n5\n6\n7\n"),
|
||||||
|
java.util.Collections.singletonList(v.asInstanceOf[AbstractConfigValue]))
|
||||||
|
val conf = ConfigFactory.empty().withValue("bar", list)
|
||||||
|
val rendered = conf.root.render()
|
||||||
|
def assertHas(s: String): Unit =
|
||||||
|
assertTrue(s"has ${s.replace("\n", "\\n")} in it", rendered.contains(s))
|
||||||
|
assertHas("is a description\n")
|
||||||
|
assertHas("with some\n")
|
||||||
|
assertHas("newlines\n")
|
||||||
|
assertHas("#\n")
|
||||||
|
assertHas("5\n")
|
||||||
|
assertHas("6\n")
|
||||||
|
assertHas("7\n")
|
||||||
|
val parsed = ConfigFactory.parseString(rendered)
|
||||||
|
|
||||||
|
assertEquals(conf, parsed)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user