mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 06:00:52 +00:00
Fix indent lambda using \n as line break (#16464)
* fix indent lambda using \n as line break * update tests * more fix
This commit is contained in:
parent
71b33db7ee
commit
c74ed98282
@ -109,7 +109,8 @@ public class IndentedLambda implements Mustache.Lambda {
|
||||
|
||||
String prefixedIndention = StringUtils.repeat(new String(Character.toChars(spaceCode)), prefixSpaceCount);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String[] lines = text.split(System.lineSeparator());
|
||||
// use \n instead of System.lineSeparator (e.g. \r\n in Windows) as templates use \n
|
||||
String[] lines = text.split("\n");
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
String line = lines[i];
|
||||
// Mustache will apply correct indentation to the first line of a template (to match declaration location).
|
||||
@ -121,9 +122,9 @@ public class IndentedLambda implements Mustache.Lambda {
|
||||
|
||||
sb.append(line);
|
||||
|
||||
// We've split on the system's line separator. We don't want to add an additional trailing line.
|
||||
// We've split on \n. We don't want to add an additional trailing line.
|
||||
if (i < lines.length - 1) {
|
||||
sb.append(System.lineSeparator());
|
||||
sb.append("\n");
|
||||
}
|
||||
}
|
||||
writer.write(sb.toString());
|
||||
|
@ -6,18 +6,17 @@ import org.testng.annotations.Test;
|
||||
|
||||
public class IndentedLambdaTest extends LambdaTest {
|
||||
|
||||
String lineSeparator = System.lineSeparator();
|
||||
String lineSeparator = "\n";
|
||||
|
||||
@Test
|
||||
public void defaultIndentTest() {
|
||||
// Given
|
||||
Map<String, Object> ctx = context("indented", new IndentedLambda());
|
||||
String lineSeparator = System.lineSeparator();
|
||||
|
||||
// When & Then
|
||||
// IndentedLambda applies indentation from second line on of a template.
|
||||
test("first line" + lineSeparator + " second line",
|
||||
"{{#indented}}first line" + lineSeparator +"second line{{/indented}}", ctx);
|
||||
"{{#indented}}first line" + lineSeparator + "second line{{/indented}}", ctx);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -28,7 +27,7 @@ public class IndentedLambdaTest extends LambdaTest {
|
||||
// When & Then
|
||||
// IndentedLambda applies indentation from second line on of a template.
|
||||
test("first line" + lineSeparator + " second line",
|
||||
"{{#indented}}first line" + lineSeparator +"second line{{/indented}}", ctx);
|
||||
"{{#indented}}first line" + lineSeparator + "second line{{/indented}}", ctx);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user