Skip to content

Commit

Permalink
[yegor256#1610] tests for multiline values and special symbols for Ya…
Browse files Browse the repository at this point in the history
…mlXML
  • Loading branch information
pnatashap committed Feb 16, 2024
1 parent 6f094a9 commit 2bd95ec
Showing 1 changed file with 40 additions and 16 deletions.
56 changes: 40 additions & 16 deletions src/test/java/com/rultor/profiles/YamlXMLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

/**
* Tests for ${@link YamlXML}.
Expand Down Expand Up @@ -76,24 +78,46 @@ void parsesYamlConfigWhenBroken() {

/**
* YamlXML can parse a broken text and throw.
* @param yaml Text to check
*/
@ParameterizedTest
@ValueSource(strings = {
"thre\n\t\\/\u0000",
"first: \"привет \\/\t\r\""
})
void parsesBrokenConfigsAndThrows(final String yaml) {
Assertions.assertThrows(
Profile.ConfigException.class,
() -> new YamlXML(yaml).get()
);
}

/**
* YamlXML can parse a text with spec symbols after |-.
*/
@Test
void parsesGroupContent() {
MatcherAssert.assertThat(
new YamlXML("a: alpha\nb: |-\n echo \"<>some(text);\"").get(),
XhtmlMatchers.hasXPaths(
"/p/entry[@key='a' and .='alpha']",
"/p/entry[@key='b' and .='echo \"<>some(text);\"']"
)
);
}

/**
* YamlXML can parse a multiline text after |-.
*/
@Test
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
void parsesBrokenConfigsAndThrows() {
final String[] yamls = {
"thre\n\t\\/\u0000",
"first: \"привет \\/\t\r\"",
};
for (final String yaml : yamls) {
try {
new YamlXML(yaml).get();
Assertions.fail(
String.format("exception expected for %s", yaml)
);
} catch (final Profile.ConfigException ex) {
continue;
}
}
void parsesMultilineContent() {
MatcherAssert.assertThat(
new YamlXML("a: alpha\nb: |-\n echo \\\n \"some(text);\"").get(),
XhtmlMatchers.hasXPaths(
"/p/entry[@key='a' and .='alpha']",
"/p/entry[@key='b' and .='echo \\\n\"some(text);\"']"
)
);
}

}

0 comments on commit 2bd95ec

Please sign in to comment.