55import static org .hamcrest .CoreMatchers .*;
66import static org .junit .Assert .*;
77import static ru .lanwen .verbalregex .VerbalExpression .regex ;
8+ import static ru .lanwen .verbalregex .matchers .TestMatchMatcher .matchesTo ;
89import static ru .lanwen .verbalregex .matchers .TestsExactMatcher .matchesExactly ;
910
1011public class BasicFunctionalityUnitTest {
1112 @ Test
1213 public void testSomething () {
1314 VerbalExpression testRegex = new VerbalExpression .Builder ().something ().build ();
1415
15- assertFalse ("Null object doesn't have something" , testRegex . test ( null ));
16- assertFalse ("empty string doesn't have something" , testRegex . test ( "" ));
17- assertTrue ("a" , testRegex . test ("a" ));
16+ assertThat ("Null object doesn't have something" , testRegex , not ( matchesTo ( null ) ));
17+ assertThat ("empty string doesn't have something" , testRegex , not ( matchesTo ( "" ) ));
18+ assertThat ("a" , testRegex , matchesTo ("a" ));
1819 }
1920
2021 @ Test
@@ -24,9 +25,9 @@ public void testAnything() {
2425 .anything ()
2526 .build ();
2627
27- assertTrue (testRegex . test ("what" ));
28- assertFalse (testRegex . test ( "" ));
29- assertTrue (testRegex . test (" " ));
28+ assertThat (testRegex , matchesTo ("what" ));
29+ assertThat (testRegex , not ( matchesTo ( "" ) ));
30+ assertThat (testRegex , matchesTo (" " ));
3031 }
3132
3233 @ Test
@@ -63,9 +64,9 @@ public void testStartOfLine() {
6364
6465 assertFalse ("Null string" , testRegex .testExact (null ));
6566 assertFalse ("empty string doesn't have something" , testRegex .testExact ("" ));
66- assertTrue ("Starts with a" , testRegex . test ("a" ));
67- assertTrue ("Starts with a" , testRegex . test ("ab" ));
68- assertFalse ("Doesn't start with a" , testRegex . test ( "ba" ));
67+ assertThat ("Starts with a" , testRegex , matchesTo ("a" ));
68+ assertThat ("Starts with a" , testRegex , matchesTo ("ab" ));
69+ assertThat ("Doesn't start with a" , testRegex , not ( matchesTo ( "ba" ) ));
6970 }
7071
7172 @ Test
@@ -74,17 +75,17 @@ public void testStartOfLineFalse() {
7475 .startOfLine (false )
7576 .then ("a" )
7677 .build ();
77- assertThat (testRegex . test ("ba" ), is ( true ));
78- assertThat (testRegex . test ("ab" ), is ( true ));
78+ assertThat (testRegex , matchesTo ("ba" ));
79+ assertThat (testRegex , matchesTo ("ab" ));
7980 }
8081
8182 @ Test
8283 public void testRangeWithMultiplyRanges () throws Exception {
8384 VerbalExpression regex = regex ().range ("a" , "z" , "A" , "Z" ).build ();
8485
8586 assertThat ("Regex with multi-range differs from expected" , regex .toString (), equalTo ("[a-zA-Z]" ));
86- assertThat ("Regex don't matches letter" , regex . test ("b" ), is ( true ));
87- assertThat ("Regex matches digit, but should match only letter" , regex . test ( "1" ), is ( false ));
87+ assertThat ("Regex don't matches letter" , regex , matchesTo ("b" ));
88+ assertThat ("Regex matches digit, but should match only letter" , regex , not ( matchesTo ( "1" )));
8889 }
8990
9091 @ Test
@@ -94,10 +95,10 @@ public void testEndOfLine() {
9495 .endOfLine ()
9596 .build ();
9697
97- assertTrue ("Ends with a" , testRegex . test ("bba" ));
98- assertTrue ("Ends with a" , testRegex . test ("a" ));
99- assertFalse ("Ends with a" , testRegex . test ( null ));
100- assertFalse ("Doesn't end with a" , testRegex . test ( "ab" ));
98+ assertThat ("Ends with a" , testRegex , matchesTo ("bba" ));
99+ assertThat ("Ends with a" , testRegex , matchesTo ("a" ));
100+ assertThat ("Ends with a" , testRegex , not ( matchesTo ( null ) ));
101+ assertThat ("Doesn't end with a" , testRegex , not ( matchesTo ( "ab" ) ));
101102 }
102103
103104
@@ -107,8 +108,8 @@ public void testEndOfLineIsFalse() {
107108 .find ("a" )
108109 .endOfLine (false )
109110 .build ();
110- assertThat (testRegex . test ("ba" ), is ( true ));
111- assertThat (testRegex . test ("ab" ), is ( true ));
111+ assertThat (testRegex , matchesTo ("ba" ));
112+ assertThat (testRegex , matchesTo ("ab" ));
112113 }
113114
114115
@@ -122,9 +123,9 @@ public void testMaybe() {
122123
123124 assertThat ("Regex isn't correct" , testRegex .toString (), equalTo ("^(?:a)(?:b)?" ));
124125
125- assertTrue ("Maybe has a 'b' after an 'a'" , testRegex . test ("acb" ));
126- assertTrue ("Maybe has a 'b' after an 'a'" , testRegex . test ("abc" ));
127- assertFalse ("Maybe has a 'b' after an 'a'" , testRegex . test ( "cab" ));
126+ assertThat ("Maybe has a 'b' after an 'a'" , testRegex , matchesTo ("acb" ));
127+ assertThat ("Maybe has a 'b' after an 'a'" , testRegex , matchesTo ("abc" ));
128+ assertThat ("Maybe has a 'b' after an 'a'" , testRegex , not ( matchesTo ( "cab" ) ));
128129 }
129130
130131 @ Test
@@ -135,8 +136,8 @@ public void testAnyOf() {
135136 .anyOf ("xyz" )
136137 .build ();
137138
138- assertTrue ("Has an x, y, or z after a" , testRegex . test ("ay" ));
139- assertFalse ("Doesn't have an x, y, or z after a" , testRegex . test ( "abc" ));
139+ assertThat ("Has an x, y, or z after a" , testRegex , matchesTo ("ay" ));
140+ assertThat ("Doesn't have an x, y, or z after a" , testRegex , not ( matchesTo ( "abc" ) ));
140141 }
141142
142143
@@ -156,8 +157,8 @@ public void testOr() {
156157 .or ("def" )
157158 .build ();
158159
159- assertTrue ("Starts with abc or def" , testRegex . test ("defzzz" ));
160- assertFalse ("Doesn't start with abc or def" , testRegex . test ( "xyzabc" ));
160+ assertThat ("Starts with abc or def" , testRegex , matchesTo ("defzzz" ));
161+ assertThat ("Doesn't start with abc or def" , testRegex , not ( matchesTo ( "xyzabc" ) ));
161162 }
162163
163164 @ Test
@@ -169,9 +170,9 @@ public void testLineBreak() {
169170 .then ("def" )
170171 .build ();
171172
172- assertTrue ("abc then line break then def" , testRegex . test ("abc\r \n def" ));
173- assertTrue ("abc then line break then def" , testRegex . test ("abc\n def" ));
174- assertFalse ("abc then line break then space then def" , testRegex . test ( "abc\r \n def" ));
173+ assertThat ("abc then line break then def" , testRegex , matchesTo ("abc\r \n def" ));
174+ assertThat ("abc then line break then def" , testRegex , matchesTo ("abc\n def" ));
175+ assertThat ("abc then line break then space then def" , testRegex , not ( matchesTo ( "abc\r \n def" ) ));
175176 }
176177
177178 @ Test
@@ -201,8 +202,8 @@ public void testTab() {
201202 .then ("abc" )
202203 .build ();
203204
204- assertTrue ("tab then abc" , testRegex . test ("\t abc" ));
205- assertFalse ("no tab then abc" , testRegex . test ( "abc" ));
205+ assertThat ("tab then abc" , testRegex , matchesTo ("\t abc" ));
206+ assertThat ("no tab then abc" , testRegex , not ( matchesTo ( "abc" ) ));
206207 }
207208
208209 @ Test
@@ -212,15 +213,15 @@ public void testWithAnyCase() {
212213 .then ("a" )
213214 .build ();
214215
215- assertFalse ("not case insensitive" , testRegex . test ( "A" ));
216+ assertThat ("not case insensitive" , testRegex , not ( matchesTo ( "A" ) ));
216217 testRegex = new VerbalExpression .Builder ()
217218 .startOfLine ()
218219 .then ("a" )
219220 .withAnyCase ()
220221 .build ();
221222
222- assertTrue ("case insensitive" , testRegex . test ("A" ));
223- assertTrue ("case insensitive" , testRegex . test ("a" ));
223+ assertThat ("case insensitive" , testRegex , matchesTo ("A" ));
224+ assertThat ("case insensitive" , testRegex , matchesTo ("a" ));
224225 }
225226
226227 @ Test
@@ -232,7 +233,7 @@ public void testWithAnyCaseIsFalse() {
232233 .withAnyCase (false )
233234 .build ();
234235
235- assertThat (testRegex . test ( "A" ), is ( false ));
236+ assertThat (testRegex , not ( matchesTo ( "A" )));
236237 }
237238
238239 @ Test
@@ -245,7 +246,7 @@ public void testSearchOneLine() {
245246 .endOfLine ()
246247 .build ();
247248
248- assertTrue ("b is on the second line" , testRegex . test ("a\n b" ));
249+ assertThat ("b is on the second line" , testRegex , matchesTo ("a\n b" ));
249250
250251 testRegex = new VerbalExpression .Builder ()
251252 .startOfLine ()
@@ -256,7 +257,7 @@ public void testSearchOneLine() {
256257 .searchOneLine (true )
257258 .build ();
258259
259- assertTrue ("b is on the second line but we are only searching the first" , testRegex . test ("a\n b" ));
260+ assertThat ("b is on the second line but we are only searching the first" , testRegex , matchesTo ("a\n b" ));
260261 }
261262
262263 @ Test
@@ -309,7 +310,7 @@ public void testCountWithRange() {
309310
310311 assertThat ("regex don't match string" , regex .getText (text4c ), equalTo ("ccc" ));
311312 assertThat ("regex don't match string" , regex .getText (text2c ), equalTo ("cc" ));
312- assertThat ("regex don't match string" , regex . test ( text1c ), is ( false ));
313+ assertThat ("regex don't match string" , regex , not ( matchesTo ( text1c ) ));
313314 }
314315
315316 @ Test
@@ -342,9 +343,9 @@ public void testOrWithCapture() {
342343 .find ("abc" )
343344 .or ("def" )
344345 .build ();
345- assertTrue ("Starts with abc or def" , testRegex . test ("defzzz" ));
346- assertTrue ("Starts with abc or def" , testRegex . test ("abczzz" ));
347- assertFalse ("Doesn't start with abc or def" , testRegex . testExact ( "xyzabcefg" ));
346+ assertThat ("Starts with abc or def" , testRegex , matchesTo ("defzzz" ));
347+ assertThat ("Starts with abc or def" , testRegex , matchesTo ("abczzz" ));
348+ assertThat ("Doesn't start with abc or def" , testRegex , not ( matchesExactly ( "xyzabcefg" ) ));
348349
349350 assertThat (testRegex .getText ("xxxabcdefzzz" , 1 ), equalTo ("abcdef" ));
350351 assertThat (testRegex .getText ("xxxdefzzz" , 2 ), equalTo ("null" ));
0 commit comments