5
5
import static org .hamcrest .CoreMatchers .*;
6
6
import static org .junit .Assert .*;
7
7
import static ru .lanwen .verbalregex .VerbalExpression .regex ;
8
+ import static ru .lanwen .verbalregex .matchers .TestMatchMatcher .matchesTo ;
8
9
import static ru .lanwen .verbalregex .matchers .TestsExactMatcher .matchesExactly ;
9
10
10
11
public class BasicFunctionalityUnitTest {
11
12
@ Test
12
13
public void testSomething () {
13
14
VerbalExpression testRegex = new VerbalExpression .Builder ().something ().build ();
14
15
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" ));
18
19
}
19
20
20
21
@ Test
@@ -24,9 +25,9 @@ public void testAnything() {
24
25
.anything ()
25
26
.build ();
26
27
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 (" " ));
30
31
}
31
32
32
33
@ Test
@@ -63,9 +64,9 @@ public void testStartOfLine() {
63
64
64
65
assertFalse ("Null string" , testRegex .testExact (null ));
65
66
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" ) ));
69
70
}
70
71
71
72
@ Test
@@ -74,17 +75,17 @@ public void testStartOfLineFalse() {
74
75
.startOfLine (false )
75
76
.then ("a" )
76
77
.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" ));
79
80
}
80
81
81
82
@ Test
82
83
public void testRangeWithMultiplyRanges () throws Exception {
83
84
VerbalExpression regex = regex ().range ("a" , "z" , "A" , "Z" ).build ();
84
85
85
86
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" )));
88
89
}
89
90
90
91
@ Test
@@ -94,10 +95,10 @@ public void testEndOfLine() {
94
95
.endOfLine ()
95
96
.build ();
96
97
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" ) ));
101
102
}
102
103
103
104
@@ -107,8 +108,8 @@ public void testEndOfLineIsFalse() {
107
108
.find ("a" )
108
109
.endOfLine (false )
109
110
.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" ));
112
113
}
113
114
114
115
@@ -122,9 +123,9 @@ public void testMaybe() {
122
123
123
124
assertThat ("Regex isn't correct" , testRegex .toString (), equalTo ("^(?:a)(?:b)?" ));
124
125
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" ) ));
128
129
}
129
130
130
131
@ Test
@@ -135,8 +136,8 @@ public void testAnyOf() {
135
136
.anyOf ("xyz" )
136
137
.build ();
137
138
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" ) ));
140
141
}
141
142
142
143
@@ -156,8 +157,8 @@ public void testOr() {
156
157
.or ("def" )
157
158
.build ();
158
159
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" ) ));
161
162
}
162
163
163
164
@ Test
@@ -169,9 +170,9 @@ public void testLineBreak() {
169
170
.then ("def" )
170
171
.build ();
171
172
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" ) ));
175
176
}
176
177
177
178
@ Test
@@ -201,8 +202,8 @@ public void testTab() {
201
202
.then ("abc" )
202
203
.build ();
203
204
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" ) ));
206
207
}
207
208
208
209
@ Test
@@ -212,15 +213,15 @@ public void testWithAnyCase() {
212
213
.then ("a" )
213
214
.build ();
214
215
215
- assertFalse ("not case insensitive" , testRegex . test ( "A" ));
216
+ assertThat ("not case insensitive" , testRegex , not ( matchesTo ( "A" ) ));
216
217
testRegex = new VerbalExpression .Builder ()
217
218
.startOfLine ()
218
219
.then ("a" )
219
220
.withAnyCase ()
220
221
.build ();
221
222
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" ));
224
225
}
225
226
226
227
@ Test
@@ -232,7 +233,7 @@ public void testWithAnyCaseIsFalse() {
232
233
.withAnyCase (false )
233
234
.build ();
234
235
235
- assertThat (testRegex . test ( "A" ), is ( false ));
236
+ assertThat (testRegex , not ( matchesTo ( "A" )));
236
237
}
237
238
238
239
@ Test
@@ -245,7 +246,7 @@ public void testSearchOneLine() {
245
246
.endOfLine ()
246
247
.build ();
247
248
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" ));
249
250
250
251
testRegex = new VerbalExpression .Builder ()
251
252
.startOfLine ()
@@ -256,7 +257,7 @@ public void testSearchOneLine() {
256
257
.searchOneLine (true )
257
258
.build ();
258
259
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" ));
260
261
}
261
262
262
263
@ Test
@@ -309,7 +310,7 @@ public void testCountWithRange() {
309
310
310
311
assertThat ("regex don't match string" , regex .getText (text4c ), equalTo ("ccc" ));
311
312
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 ) ));
313
314
}
314
315
315
316
@ Test
@@ -342,9 +343,9 @@ public void testOrWithCapture() {
342
343
.find ("abc" )
343
344
.or ("def" )
344
345
.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" ) ));
348
349
349
350
assertThat (testRegex .getText ("xxxabcdefzzz" , 1 ), equalTo ("abcdef" ));
350
351
assertThat (testRegex .getText ("xxxdefzzz" , 2 ), equalTo ("null" ));
0 commit comments