Skip to content

Commit

Permalink
Uses %n in tests instead of replacing /r/n with /n
Browse files Browse the repository at this point in the history
  • Loading branch information
rchache committed Jan 17, 2024
1 parent 2297e71 commit 463cffe
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public void formatsSingleFile() {
IntegUtils.run("bad-formatting", ListUtils.of("format", "model/other.smithy"), result -> {
assertThat(result.getExitCode(), equalTo(0));

String model = result.getFile("model/other.smithy").replace("\r\n", "\n");
assertThat(model, equalTo("$version: \"2.0\"\n"
+ "\n"
+ "namespace smithy.example\n"
+ "\n"
+ "string MyString\n"
+ "\n"
+ "string MyString2\n"));
String model = result.getFile("model/other.smithy");
assertThat(model, equalTo(String.format("$version: \"2.0\"%n"
+ "%n"
+ "namespace smithy.example%n"
+ "%n"
+ "string MyString%n"
+ "%n"
+ "string MyString2%n")));
});
}

Expand All @@ -48,24 +48,24 @@ public void formatsDirectory() {
IntegUtils.run("bad-formatting", ListUtils.of("format", "model"), result -> {
assertThat(result.getExitCode(), equalTo(0));

String main = result.getFile("model/main.smithy").replace("\r\n", "\n");
assertThat(main, equalTo("$version: \"2.0\"\n"
+ "\n"
+ "metadata this_is_a_long_string = {\n"
+ " this_is_a_long_string1: \"a\"\n"
+ " this_is_a_long_string2: \"b\"\n"
+ " this_is_a_long_string3: \"c\"\n"
+ " this_is_a_long_string4: \"d\"\n"
+ "}\n"));
String main = result.getFile("model/main.smithy");
assertThat(main, equalTo(String.format("$version: \"2.0\"%n"
+ "%n"
+ "metadata this_is_a_long_string = {%n"
+ " this_is_a_long_string1: \"a\"%n"
+ " this_is_a_long_string2: \"b\"%n"
+ " this_is_a_long_string3: \"c\"%n"
+ " this_is_a_long_string4: \"d\"%n"
+ "}%n")));

String other = result.getFile("model/other.smithy").replace("\r\n", "\n");
assertThat(other, equalTo("$version: \"2.0\"\n"
+ "\n"
+ "namespace smithy.example\n"
+ "\n"
+ "string MyString\n"
+ "\n"
+ "string MyString2\n"));
String other = result.getFile("model/other.smithy");
assertThat(other, equalTo(String.format("$version: \"2.0\"%n"
+ "%n"
+ "namespace smithy.example%n"
+ "%n"
+ "string MyString%n"
+ "%n"
+ "string MyString2%n")));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private boolean writeNewLine() throws IOException {
if (indentString == null) {
return false;
}
writer.write('\n');
writer.write(System.lineSeparator());
for (int i = 0; i < indent; i++) {
writer.write(indentString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,9 @@ public void handlesMultilineDocComments() {
Shape shape = model.expectShape(ShapeId.from("smithy.example#MyStruct$myMember"));
String docs = shape.getTrait(DocumentationTrait.class)
.map(StringTrait::getValue)
.orElse("")
.replace("\r\n", "\n");
.orElse("");

assertThat(docs, equalTo("This is the first line.\nThis is the second line."));
assertThat(docs, equalTo(String.format("This is the first line.%nThis is the second line.")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@ public void loadsContext() {
.build();

String format = new ContextualValidationEventFormatter().format(event);
// Normalize line endings for Windows.
format = format.replace("\r\n", "\n");

assertThat(format, startsWith("ERROR: example.smithy#Foo (foo)"));
assertThat(format, containsString("\n @ "));
assertThat(format, endsWith(
"\n |"
+ "\n 3 | structure Foo {"
+ "\n | ^"
+ "\n = This is the message"
+ "\n"));
assertThat(format, containsString(String.format("%n @ ")));
assertThat(format, endsWith(String.format(
"%n |"
+ "%n 3 | structure Foo {"
+ "%n | ^"
+ "%n = This is the message"
+ "%n")));
}

@Test
Expand All @@ -54,12 +52,11 @@ public void doesNotLoadSourceLocationNone() {
.build();

String format = new ContextualValidationEventFormatter().format(event);
// Normalize line endings for Windows.
format = format.replace("\r\n", "\n");

assertThat(format, equalTo(
assertThat(format, equalTo(String.format(
"ERROR: - (foo)"
+ "\n = This is the message"
+ "\n"));
+ "%n = This is the message"
+ "%n")
));
}
}

0 comments on commit 463cffe

Please sign in to comment.