Skip to content

Commit

Permalink
Standardized line separators.
Browse files Browse the repository at this point in the history
  • Loading branch information
rchache committed Jan 17, 2024
1 parent 2297e71 commit 8cf5028
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 90 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 @@ -42,21 +42,21 @@ public static Collection<Object[]> data() {
{new NullNode(SourceLocation.none()), "null"},
{new ArrayNode(
Arrays.asList(Node.from(1), Node.from(2)),
SourceLocation.none()), String.format("[\n 1,\n 2\n]")},
SourceLocation.none()), String.format("[%n 1,%n 2%n]")},
{Node.objectNode()
.withMember("foo", Node.from("foo"))
.withMember("baz", Node.from(1))
.withMember("bar", Node.objectNode()
.withMember("qux", Node.arrayNode()
.withValue(Node.from("ipsum")))),
String.format("{\n"
+ " \"foo\": \"foo\",\n"
+ " \"baz\": 1,\n"
+ " \"bar\": {\n"
+ " \"qux\": [\n"
+ " \"ipsum\"\n"
+ " ]\n"
+ " }\n"
String.format("{%n"
+ " \"foo\": \"foo\",%n"
+ " \"baz\": 1,%n"
+ " \"bar\": {%n"
+ " \"qux\": [%n"
+ " \"ipsum\"%n"
+ " ]%n"
+ " }%n"
+ "}")
},
{Node.objectNode()
Expand All @@ -66,17 +66,17 @@ public static Collection<Object[]> data() {
.withMember("bam", Node.arrayNode()
.withValue(Node.objectNode()
.withMember("abc", Node.from(123)))),
String.format("{\n"
+ " \"foo\": {\n"
+ " \"bar\": [\n"
+ " \"baz\"\n"
+ " ]\n"
+ " },\n"
+ " \"bam\": [\n"
+ " {\n"
+ " \"abc\": 123\n"
+ " }\n"
+ " ]\n"
String.format("{%n"
+ " \"foo\": {%n"
+ " \"bar\": [%n"
+ " \"baz\"%n"
+ " ]%n"
+ " },%n"
+ " \"bam\": [%n"
+ " {%n"
+ " \"abc\": 123%n"
+ " }%n"
+ " ]%n"
+ "}")
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ public void serializesNodes() {
Node node = Node.parse("{\"foo\": \"bar\", \"baz\": true, \"bam\": false, \"boo\": 10}");

assertThat(Node.printJson(node), equalTo("{\"foo\":\"bar\",\"baz\":true,\"bam\":false,\"boo\":10}"));
assertThat(Node.prettyPrintJson(node), equalTo("{\n"
+ " \"foo\": \"bar\",\n"
+ " \"baz\": true,\n"
+ " \"bam\": false,\n"
+ " \"boo\": 10\n"
assertThat(Node.prettyPrintJson(node), equalTo("{%n"
+ " \"foo\": \"bar\",%n"
+ " \"baz\": true,%n"
+ " \"bam\": false,%n"
+ " \"boo\": 10%n"
+ "}"));
assertThat(Node.prettyPrintJson(node, "\t"), equalTo("{\n"
+ "\t\"foo\": \"bar\",\n"
+ "\t\"baz\": true,\n"
+ "\t\"bam\": false,\n"
+ "\t\"boo\": 10\n"
assertThat(Node.prettyPrintJson(node, "\t"), equalTo("{%n"
+ "\t\"foo\": \"bar\",%n"
+ "\t\"baz\": true,%n"
+ "\t\"bam\": false,%n"
+ "\t\"boo\": 10%n"
+ "}"));
}

Expand All @@ -45,24 +45,24 @@ public void serializesComplexNodes() {
assertThat(Node.printJson(node), equalTo(
"[{\"foo\":\"\uD83D\uDCA9\",\"baz\":true,\"bam\":false,"
+ "\"boo\":10},10,true,false,{},[],\"\",\" \",null,-1,-1.0]"));
assertThat(Node.prettyPrintJson(node), equalTo(
"[\n"
+ " {\n"
+ " \"foo\": \"\uD83D\uDCA9\",\n"
+ " \"baz\": true,\n"
+ " \"bam\": false,\n"
+ " \"boo\": 10\n"
+ " },\n"
+ " 10,\n"
+ " true,\n"
+ " false,\n"
+ " {},\n" // optimized empty object
+ " [],\n" // optimized empty array
+ " \"\",\n"
+ " \" \",\n"
+ " null,\n"
+ " -1,\n"
+ " -1.0\n"
+ "]"));
assertThat(Node.prettyPrintJson(node), equalTo(String.format(
"[%n"
+ " {%n"
+ " \"foo\": \"\uD83D\uDCA9\",%n"
+ " \"baz\": true,%n"
+ " \"bam\": false,%n"
+ " \"boo\": 10%n"
+ " },%n"
+ " 10,%n"
+ " true,%n"
+ " false,%n"
+ " {},%n" // optimized empty object
+ " [],%n" // optimized empty array
+ " \"\",%n"
+ " \" \",%n"
+ " null,%n"
+ " -1,%n"
+ " -1.0%n"
+ "]")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void deepSortsNodesWithComparator() {
@Test
public void prettyPrintsJson() {
assertThat(Node.prettyPrintJson(Node.parse("{\"foo\": true}")),
equalTo(String.format("{\n \"foo\": true\n}")));
equalTo(String.format("{%n \"foo\": true%n}")));
}

@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 8cf5028

Please sign in to comment.