File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
tests/test-base/src/main/java/net/javacrumbs/jsonunit/test/base Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 47
47
import static net .javacrumbs .jsonunit .core .Option .IGNORING_VALUES ;
48
48
import static net .javacrumbs .jsonunit .core .Option .TREATING_NULL_AS_ABSENT ;
49
49
import static net .javacrumbs .jsonunit .core .internal .JsonUtils .jsonSource ;
50
+ import static net .javacrumbs .jsonunit .test .base .RegexBuilder .regex ;
50
51
import static org .assertj .core .api .Assertions .assertThat ;
51
52
import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
52
53
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
@@ -705,7 +706,13 @@ void testAssertPathArray() {
705
706
@ Test
706
707
void testLongRegexp () {
707
708
assertThatJson ("{\" test\" : \" This is some text followed by: ABCD, followed by this\" }" )
708
- .isEqualTo ("{\" test\" : \" ${json-unit.regex}\\ \\ QThis is some text followed by: \\ \\ E[A-Z]+\\ \\ Q, followed by this\\ \\ E\" }" );
709
+ .isEqualTo ("{\" test\" : \" ${json-unit.regex}^\\ \\ QThis is some text followed by: \\ \\ E[A-Z]+\\ \\ Q, followed by this\\ \\ E$\" }" );
710
+ }
711
+
712
+ @ Test
713
+ void testLongRegexpBuilder () {
714
+ assertThatJson ("{\" test\" : \" This is some text followed by: ABCD, followed by this\" }" )
715
+ .isEqualTo ("{\" test\" : " + regex ().str ("This is some text followed by: " ).exp ("[A-Z]+" ).str (", followed by this" ) + "}" );
709
716
}
710
717
711
718
@ Test
Original file line number Diff line number Diff line change
1
+ package net .javacrumbs .jsonunit .test .base ;
2
+
3
+ public class RegexBuilder {
4
+ private final String expression ;
5
+
6
+ private RegexBuilder (String expression ) {
7
+ this .expression = expression ;
8
+ }
9
+
10
+ static RegexBuilder regex () {
11
+ return new RegexBuilder ("\" ${json-unit.regex}^" );
12
+ }
13
+
14
+ RegexBuilder str (String staticString ) {
15
+ return new RegexBuilder (expression + "\\ \\ Q" + staticString + "\\ \\ E" );
16
+ }
17
+
18
+ RegexBuilder exp (String regex ) {
19
+ return new RegexBuilder (expression + regex );
20
+ }
21
+
22
+ public String toString () {
23
+ return expression + "$\" " ;
24
+ }
25
+
26
+ }
You can’t perform that action at this time.
0 commit comments