Skip to content

Commit

Permalink
minor string changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rchache committed Jan 16, 2024
1 parent dc54402 commit 2297e71
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -203,9 +202,7 @@ public void findsDifferencesInListTraitValues() {
.assemble()
.unwrap();
List<ValidationEvent> events = TestHelper.findEvents(ModelDiff.compare(modelA, modelB), "ModifiedTrait");
List<String> messages = events.stream().map(ValidationEvent::getMessage)
.map(message -> message.replaceAll("\r\n", "\n")) // normalize line separators
.collect(Collectors.toList());
List<String> messages = events.stream().map(ValidationEvent::getMessage).collect(Collectors.toList());

assertThat(events, hasSize(4));
assertThat(events.stream().filter(e -> e.getMessage().contains("Removed"))
Expand All @@ -216,10 +213,14 @@ public void findsDifferencesInListTraitValues() {
"Changed trait contents of `smithy.example#aTrait` at path `/foo/1` from `b` to `B`",
"Added trait contents to `smithy.example#aTrait` at path `/foo/3` with value `4`",
"Removed trait contents from `smithy.example#aTrait` at path `/foo/2`. Removed value: `3`",
"Removed trait contents from `smithy.example#aTrait` at path `/foo`. Removed value: \n"
+ "```\n"
+ "[\n \"1\",\n \"2\",\n \"3\"\n]\n"
+ "```"
String.format("Removed trait contents from `smithy.example#aTrait` at path `/foo`. Removed value: %n"
+ "```%n"
+ "[%n"
+ " \"1\",%n"
+ " \"2\",%n"
+ " \"3\"%n"
+ "]%n"
+ "```%n")
));
}

Expand All @@ -234,9 +235,7 @@ public void findsDifferencesInSetTraitValues() {
.assemble()
.unwrap();
List<ValidationEvent> events = TestHelper.findEvents(ModelDiff.compare(modelA, modelB), "ModifiedTrait");
List<String> messages = events.stream().map(ValidationEvent::getMessage)
.map(message -> message.replaceAll("\r\n", "\n")) // normalize line separators
.collect(Collectors.toList());
List<String> messages = events.stream().map(ValidationEvent::getMessage).collect(Collectors.toList());

assertThat(events, hasSize(4));
assertThat(events.stream().filter(e -> e.getMessage().contains("Removed"))
Expand All @@ -247,11 +246,15 @@ public void findsDifferencesInSetTraitValues() {
"Changed trait contents of `smithy.example#aTrait` at path `/foo/1` from `b` to `B`",
"Added trait contents to `smithy.example#aTrait` at path `/foo/3` with value `4`",
"Removed trait contents from `smithy.example#aTrait` at path `/foo/2`. Removed value: `3`",
"Removed trait contents from `smithy.example#aTrait` at path `/foo`. "
+ "Removed value: \n"
+ "```\n"
+ "[\n \"1\",\n \"2\",\n \"3\"\n]\n"
+ "```"
String.format("Removed trait contents from `smithy.example#aTrait` at path `/foo`. "
+ "Removed value: %n"
+ "```%n"
+ "[%n"
+ " \"1\",%n"
+ " \"2\",%n"
+ " \"3\"%n"
+ "]%n"
+ "```%n")
));
}

Expand All @@ -266,9 +269,7 @@ public void findsDifferencesInMapTraitValues() {
.assemble()
.unwrap();
List<ValidationEvent> events = TestHelper.findEvents(ModelDiff.compare(modelA, modelB), "ModifiedTrait");
List<String> messages = events.stream().map(ValidationEvent::getMessage)
.map(message -> message.replaceAll("\r\n", "\n")) // normalize line separators
.collect(Collectors.toList());
List<String> messages = events.stream().map(ValidationEvent::getMessage).collect(Collectors.toList());

assertThat(events, hasSize(4));
assertThat(events.stream().filter(e -> e.getMessage().contains("Removed"))
Expand All @@ -277,11 +278,15 @@ public void findsDifferencesInMapTraitValues() {
.filter(e -> e.getSourceLocation().getFilename().endsWith("b.smithy")).count(), equalTo(2L));
assertThat(messages, containsInAnyOrder(
"Changed trait contents of `smithy.example#aTrait` at path `/foo/bam` from `b` to `B`",
"Removed trait contents from `smithy.example#aTrait` at path `/foo`. "
+ "Removed value: \n"
+ "```\n"
+ "{\n \"baz\": \"1\",\n \"bam\": \"2\",\n \"boo\": \"3\"\n}\n"
+ "```",
String.format("Removed trait contents from `smithy.example#aTrait` at path `/foo`. "
+ "Removed value: %n"
+ "```%n"
+ "{%n"
+ " \"baz\": \"1\",%n"
+ " \"bam\": \"2\",%n"
+ " \"boo\": \"3\"%n"
+ "}%n"
+ "```%n"),
"Added trait contents to `smithy.example#aTrait` at path `/foo/qux` with value `4`",
"Removed trait contents from `smithy.example#aTrait` at path `/foo/boo`. Removed value: `3`"
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ public static String tickedList(Stream<?> values) {
public static String tickedPrettyPrintedNode(Node node) {
String prettyPrinted = Node.prettyPrintJson(node);
if (prettyPrinted.contains(System.lineSeparator()) || prettyPrinted.contains("\n")) {
return System.lineSeparator() + "```" + System.lineSeparator()
+ prettyPrinted + System.lineSeparator()
+ "```";
return String.format("%n```%n%s%n```%n", prettyPrinted);
} else if (prettyPrinted.startsWith("\"") && prettyPrinted.endsWith("\"")) {
// for pure strings, replace the quotes with backticks
return "`" + prettyPrinted.substring(1, prettyPrinted.length() - 1) + "`";
Expand Down

0 comments on commit 2297e71

Please sign in to comment.