Skip to content

Commit

Permalink
#290 Expression builder test
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-krecan committed Oct 18, 2020
1 parent 7100f55 commit 75d68ef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Expand Up @@ -47,6 +47,7 @@
import static net.javacrumbs.jsonunit.core.Option.IGNORING_VALUES;
import static net.javacrumbs.jsonunit.core.Option.TREATING_NULL_AS_ABSENT;
import static net.javacrumbs.jsonunit.core.internal.JsonUtils.jsonSource;
import static net.javacrumbs.jsonunit.test.base.RegexBuilder.regex;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand Down Expand Up @@ -705,7 +706,13 @@ void testAssertPathArray() {
@Test
void testLongRegexp() {
assertThatJson("{\"test\": \"This is some text followed by: ABCD, followed by this\"}")
.isEqualTo("{\"test\": \"${json-unit.regex}\\\\QThis is some text followed by: \\\\E[A-Z]+\\\\Q, followed by this\\\\E\"}");
.isEqualTo("{\"test\": \"${json-unit.regex}^\\\\QThis is some text followed by: \\\\E[A-Z]+\\\\Q, followed by this\\\\E$\"}");
}

@Test
void testLongRegexpBuilder() {
assertThatJson("{\"test\": \"This is some text followed by: ABCD, followed by this\"}")
.isEqualTo("{\"test\": " + regex().str("This is some text followed by: ").exp("[A-Z]+").str(", followed by this") + "}");
}

@Test
Expand Down
@@ -0,0 +1,26 @@
package net.javacrumbs.jsonunit.test.base;

public class RegexBuilder {
private final String expression;

private RegexBuilder(String expression) {
this.expression = expression;
}

static RegexBuilder regex() {
return new RegexBuilder("\"${json-unit.regex}^");
}

RegexBuilder str(String staticString) {
return new RegexBuilder(expression + "\\\\Q" + staticString + "\\\\E");
}

RegexBuilder exp(String regex) {
return new RegexBuilder(expression + regex);
}

public String toString() {
return expression + "$\"";
}

}

0 comments on commit 75d68ef

Please sign in to comment.