Skip to content

Commit

Permalink
#517 checkstyle fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Oct 29, 2022
1 parent b612e8e commit c859248
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .rultor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ env:
MAVEN_OPTS: "-XX:MaxPermSize=256m -Xmx1g"
merge:
script: |-
mvn clean install -Pcheckstyle
mvn clean install -Pcheckstyle,itcases
#decrypt:
# settings.xml: "repo/rcfg/settings.xml.asc"
# pubring.gpg: "repo/rcfg/pubring.gpg.asc"
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/amihaiemil/eoyaml/ReadYamlMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@
*/
final class ReadYamlMapping extends BaseYamlMapping {

private static final Pattern KEY_PATTERN = Pattern.compile("^-?\\s*(?<key>.+):(|\\s.*)$");
/**
* Regex for a key in a mapping.
*/
private static final Pattern KEY_PATTERN = Pattern.compile(
"^-?\\s*(?<key>.+):(|\\s.*)$"
);

/**
* Yaml line just previous to the one where this mapping starts. E.g.
Expand Down
8 changes: 7 additions & 1 deletion src/test/java/com/amihaiemil/eoyaml/ReadYamlMappingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1171,13 +1171,19 @@ public void shouldReadFromAnotherFromYamlMapping()
.equalTo("Some other value."));
}

/**
* Reads mapping key properly if value has colon.
*/
@Test
public void shouldReadKeyProperlyIfValueContainsColon() {
final List<YamlLine> lines = new ArrayList<>();
lines.add(new RtYamlLine("key: value:with-colon", 0));
ReadYamlMapping mapping = new ReadYamlMapping(new AllYamlLines(lines));

MatcherAssert.assertThat(mapping.keys(), Matchers.hasSize(1));
MatcherAssert.assertThat(mapping.keys().iterator().next().asScalar().value(), Matchers.equalTo("key"));
MatcherAssert.assertThat(
mapping.keys().iterator().next().asScalar().value(),
Matchers.equalTo("key")
);
}
}
13 changes: 11 additions & 2 deletions src/test/java/com/amihaiemil/eoyaml/ReadYamlSequenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ public void printsEmptyYaml() throws Exception {
MatcherAssert.assertThat(sequence.toString(), Matchers.isEmptyString());
}

/**
* Reads scalar containing colon properly.
*/
@Test
public void dontReturnMappingForScalarWithColon() {
final List<YamlLine> lines = new ArrayList<>();
Expand All @@ -495,7 +498,13 @@ public void dontReturnMappingForScalarWithColon() {

MatcherAssert.assertThat(sequence.values(), Matchers.hasSize(1));
YamlNode sequenceItem = sequence.values().iterator().next();
MatcherAssert.assertThat(sequenceItem.type(), Matchers.equalTo(Node.SCALAR));
MatcherAssert.assertThat(sequenceItem.asScalar().value(), Matchers.equalTo("scalar:with-colon"));
MatcherAssert.assertThat(
sequenceItem.type(),
Matchers.equalTo(Node.SCALAR)
);
MatcherAssert.assertThat(
sequenceItem.asScalar().value(),
Matchers.equalTo("scalar:with-colon")
);
}
}
10 changes: 8 additions & 2 deletions src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,10 @@ public void supportsSpringPropertyRef() throws IOException {
MatcherAssert.assertThat(pretty, Matchers.equalTo(fileContents));
}

/**
* Unit test for issue 517.
* @throws IOException If something goes wrong.
*/
@Test
public void shouldReadKeysProperly() throws IOException {
final String filename = "issue_517_values_with_colons.yml";
Expand All @@ -1002,7 +1006,8 @@ public void shouldReadKeysProperly() throws IOException {
topLevelMapping.asMapping().value("a_scalar").type(),
Matchers.equalTo(Node.SCALAR));
MatcherAssert.assertThat(
topLevelMapping.asMapping().value("a_scalar").asScalar().value(),
topLevelMapping.asMapping().value("a_scalar")
.asScalar().value(),
Matchers.equalTo("value:with-colon"));

YamlNode topLevelSequence = read.asMapping().value("a_sequence");
Expand All @@ -1011,7 +1016,8 @@ public void shouldReadKeysProperly() throws IOException {
Matchers.equalTo(Node.SEQUENCE));
MatcherAssert.assertThat(topLevelSequence.asSequence().values(),
Matchers.hasSize(1));
YamlNode sequenceItem = topLevelSequence.asSequence().values().iterator().next();
YamlNode sequenceItem = topLevelSequence.asSequence().values()
.iterator().next();
MatcherAssert.assertThat(sequenceItem.type(),
Matchers.equalTo(Node.SCALAR));
MatcherAssert.assertThat(sequenceItem.asScalar().value(),
Expand Down

0 comments on commit c859248

Please sign in to comment.