1
+ import org .junit .Test ;
2
+ import org .junit .Before ;
3
+ import org .junit .Ignore ;
4
+ import static org .junit .Assert .*;
5
+
6
+ public class VerbalExpressionUnitTests {
7
+
8
+ @ Test
9
+ public void testSomething () {
10
+ VerbalExpression testRegex = new VerbalExpression ().something ();
11
+ String testString = "" ;
12
+
13
+ assertFalse ("empty string doesn't have something" , testRegex .test (testString ));
14
+ testString = "a" ;
15
+ assertTrue ("a" , testRegex .test (testString ));
16
+ }
17
+
18
+ @ Test
19
+ public void testAnything () {
20
+ VerbalExpression testRegex = new VerbalExpression ()
21
+ .startOfLine ()
22
+ .anything ();
23
+ String testString = "what" ;
24
+ assertTrue (testRegex .test (testString ));
25
+ }
26
+
27
+ @ Ignore ("Test not ready yet" )
28
+ @ Test
29
+ public void testAnythingBut () {
30
+ VerbalExpression testRegex = new VerbalExpression ()
31
+ .startOfLine ()
32
+ .anythingBut ("w" );
33
+ String testString = "what" ;
34
+ assertTrue ("starts with w" ,testRegex .test (testString ));
35
+ }
36
+
37
+ @ Test
38
+ public void testSomethingBut () {
39
+ VerbalExpression testRegex = new VerbalExpression ()
40
+ .somethingBut ("a" );
41
+ String testString = "" ;
42
+ assertFalse ("empty string doesn't have something" , testRegex .test (testString ));
43
+
44
+ testString = "b" ;
45
+ assertTrue ("doesn't start with a" , testRegex .test (testString ));
46
+
47
+ testString = "a" ;
48
+ assertFalse ("starts with a" , testRegex .test (testString ));
49
+ }
50
+
51
+ @ Test
52
+ public void testStartOfLine () {
53
+ VerbalExpression testRegex = new VerbalExpression ()
54
+ .startOfLine ()
55
+ .then ("a" );
56
+ String testString = "a" ;
57
+ assertTrue ("Starts with a" , testRegex .test (testString ));
58
+ testString = "ba" ;
59
+ assertFalse ("Doesn't start with a" , testRegex .test (testString ));
60
+ }
61
+
62
+ @ Test
63
+ public void testEndOfLine () {
64
+ VerbalExpression testRegex = new VerbalExpression ()
65
+ .find ("a" )
66
+ .endOfLine ();
67
+ String testString = "a" ;
68
+
69
+
70
+ assertTrue ("Ends with a" , testRegex .test (testString ));
71
+
72
+ testString = "ab" ;
73
+ assertFalse ("Doesn't end with a" , testRegex .test (testString ));
74
+ }
75
+
76
+ @ Test
77
+ public void testMaybe () {
78
+ VerbalExpression testRegex = new VerbalExpression ()
79
+ .startOfLine ()
80
+ .then ("a" )
81
+ .maybe ("b" );
82
+ String testString = "acb" ;
83
+ assertTrue ("Maybe has a 'b' after an 'a'" , testRegex .test (testString ));
84
+
85
+ testString = "abc" ;
86
+ assertTrue ("Maybe has a 'b' after an 'a'" , testRegex .test (testString ));
87
+ }
88
+
89
+ @ Test
90
+ public void testAnyOf () {
91
+ VerbalExpression testRegex = new VerbalExpression ()
92
+ .startOfLine ()
93
+ .then ("a" )
94
+ .anyOf ("xyz" );
95
+ String testString = "ay" ;
96
+ assertTrue ("Has an x, y, or z after a" , testRegex .test (testString ));
97
+
98
+ testString = "abc" ;
99
+ assertFalse ("Doesn't have an x, y, or z after a" , testRegex .test (testString ));
100
+ }
101
+
102
+ @ Test
103
+ public void testOr () {
104
+ VerbalExpression testRegex = new VerbalExpression ()
105
+ .startOfLine ()
106
+ .then ("abc" )
107
+ .or ("def" );
108
+ String testString = "defzzz" ;
109
+ assertTrue ("Starts with abc or def" , testRegex .test (testString ));
110
+
111
+ testString = "xyzabc" ;
112
+ assertFalse ("Doesn't start with abc or def" , testRegex .test (testString ));
113
+ }
114
+
115
+ @ Test
116
+ public void testLineBreak () {
117
+ VerbalExpression testRegex = new VerbalExpression ()
118
+ .startOfLine ()
119
+ .then ("abc" )
120
+ .lineBreak ()
121
+ .then ("def" );
122
+ String testString = "abc\r \n def" ;
123
+ assertTrue ("abc then line break then def" , testRegex .test (testString ));
124
+
125
+ testString = "abc\n def" ;
126
+ assertTrue ("abc then line break then def" , testRegex .test (testString ));
127
+
128
+ testString = "abc\r \n def" ;
129
+ assertFalse ("abc then line break then space then def" , testRegex .test (testString ));
130
+ }
131
+
132
+ @ Test
133
+ public void testBr () {
134
+ VerbalExpression testRegex = new VerbalExpression ()
135
+ .startOfLine ()
136
+ .then ("abc" )
137
+ .lineBreak ()
138
+ .then ("def" );
139
+ String testString = "abc\r \n def" ;
140
+ assertTrue ("abc then line break then def" , testRegex .test (testString ));
141
+
142
+ testString = "abc\n def" ;
143
+ assertTrue ("abc then line break then def" , testRegex .test (testString ));
144
+
145
+ testString = "abc\r \n def" ;
146
+ assertFalse ("abc then line break then space then def" , testRegex .test (testString ));
147
+ }
148
+
149
+ @ Test
150
+ public void testTab () {
151
+ VerbalExpression testRegex = new VerbalExpression ()
152
+ .startOfLine ()
153
+ .tab ()
154
+ .then ("abc" );
155
+ String testString = "\t abc" ;
156
+ assertTrue ("tab then abc" , testRegex .test (testString ));
157
+
158
+ testString = "abc" ;
159
+ assertFalse ("no tab then abc" , testRegex .test (testString ));
160
+ }
161
+
162
+ @ Test
163
+ public void testWithAnyCase () {
164
+ VerbalExpression testRegex = new VerbalExpression ()
165
+ .startOfLine ()
166
+ .then ("a" );
167
+ String testString = "A" ;
168
+ assertFalse ("not case insensitive" , testRegex .test (testString ));
169
+
170
+ testRegex = new VerbalExpression ()
171
+ .startOfLine ()
172
+ .then ("a" )
173
+ .withAnyCase ();
174
+ testString = "A" ;
175
+ assertTrue ("case insensitive" , testRegex .test (testString ));
176
+
177
+ testString = "a" ;
178
+ assertTrue ("case insensitive" , testRegex .test (testString ));
179
+ }
180
+
181
+ @ Test
182
+ public void testSearchOneLine () {
183
+ VerbalExpression testRegex = new VerbalExpression ()
184
+ .startOfLine ()
185
+ .then ("a" )
186
+ .br ()
187
+ .then ("b" )
188
+ .endOfLine ();
189
+ String testString = "a\n b" ;
190
+ assertTrue ("b is on the second line" , testRegex .test (testString ));
191
+
192
+ testRegex = new VerbalExpression ()
193
+ .startOfLine ()
194
+ .then ("a" )
195
+ .br ()
196
+ .then ("b" )
197
+ .endOfLine ()
198
+ .searchOneLine (true );
199
+ testString = "a\n b" ;
200
+ assertTrue ("b is on the second line but we are only searching the first" , testRegex .test (testString ));
201
+ }
202
+
203
+ /*@Before
204
+ public void setUp(){
205
+ value1=3;
206
+ value2=3;
207
+ }
208
+
209
+ // test method to add two values
210
+ @Ignore ("Test not ready yet")
211
+ @Test
212
+ public void testAdd(){
213
+ double result= value1 + value2;
214
+ assertTrue(result == 6);
215
+ }*/
216
+ }
0 commit comments