1 package testcomtest;
2 import comtest.Strings;
4 import static org.junit.Assert.*;
5 import org.junit.*;
6 import static comtest.ComTest.*;
7
9
14 @SuppressWarnings({ "PMD" })
15 public class ComTestTest {
16
17
18
19
21 @Test
22 public void testStringAdd() { Strings list = new Strings(); assertEquals("From: ComTest line: 263", 0, list.size()); list.add("one"); assertEquals("From: ComTest line: 269", 1, list.size()); assertEquals("From: ComTest line: 269", "one", list.get(0)); list.add("two"); assertEquals("From: ComTest line: 270", 2, list.size()); assertEquals("From: ComTest line: 270", "two", list.get(1)); list.add("three"); assertEquals("From: ComTest line: 271", 3, list.size()); assertEquals("From: ComTest line: 271", "three", list.get(2)); ; assertEquals("From: ComTest line: 272", 3, list.size()); ; try {
34 assertEquals("From: ComTest line: 274", "three", list.get(3));
35 fail("ComTest: 274 Did not throw IndexOutOfBoundsException");
36 } catch(IndexOutOfBoundsException _e_){ _e_.getMessage(); } }
39
40
42 @Test
43 public void testStringAdd2() { Strings list = new Strings(); assertEquals("From: ComTest line: 263", 0, list.size()); list.add("one"); assertEquals("From: ComTest line: 282", 1, list.size()); ; }
50
51
53 @Test
54 public void testStringAdd3() { Strings list = new Strings(); assertEquals("From: ComTest line: 263", 0, list.size()); list.add("two"); assertEquals("From: ComTest line: 283", 1, list.size()); ; }
61
62
64 @Test
65 public void testStringAdd4() { Strings list = new Strings(); assertEquals("From: ComTest line: 263", 0, list.size()); list.add("three"); assertEquals("From: ComTest line: 284", 1, list.size()); ; }
72
73
75 @Test
76 public void testStringAdd5() { Strings list = new Strings(); assertEquals("From: ComTest line: 263", 0, list.size()); list.add("four"); assertEquals("From: ComTest line: 288", 1, list.size()); assertTrue("Strings: 289",list.size()>0); list.add("one"); assertEquals("From: ComTest line: 295", 2, list.size()); assertTrue("Strings: 295",list.size()>0); list.add("two"); assertEquals("From: ComTest line: 296", 3, list.size()); assertTrue("Strings: 296",list.size()>0); list.add("three"); assertEquals("From: ComTest line: 297", 4, list.size()); assertTrue("Strings: 297",list.size()>0); if ( 1 > 0 ) { assertEquals("From: ComTest line: 303", "one", list.get(1)); } if ( 2 > 0 ) { assertEquals("From: ComTest line: 304", "two", list.get(2)); } if ( 3 > 0 ) { assertEquals("From: ComTest line: 305", "three", list.get(3)); } try {
91 if ( 4 > 0 ) { assertEquals("From: ComTest line: 306", "four", list.get(4)); } fail("ComTest: 306 Did not throw IndexOutOfBoundsException");
93 } catch(IndexOutOfBoundsException _e_){ _e_.getMessage(); }
94 }
96
97
99 @Test
100 public void testDouble() { double d1 = 0.1; assertEquals("From: ComTest line: 316", 1.0/10, d1, 0.000001); assertEquals("From: ComTest line: 318", 0, d1, 0.2); }
106
107
109 @Test
110 public void testRegExp() { { String _l_="cat",_r_="c.*t"; if ( !_l_.matches(_r_) ) fail("From: ComTest line: 324" + " does not match: ["+ _l_ + "] != [" + _r_ + "]");}
112 { String _l_="cat",_r_="c.*"; if ( !_l_.matches(_r_) ) fail("From: ComTest line: 325" + " does not match: ["+ _l_ + "] != [" + _r_ + "]");}
113 }
115
116
118 @Test
119 public void testException() { int []a = { 0,1} ;
121 try {
122 assertEquals("From: ComTest line: 331", 2, a[2]);
123 fail("ComTest: 331 Did not throw (IndexOutOfBoundsException ex)");
124 } catch(IndexOutOfBoundsException ex) { { String _l_=ex.getMessage(),_r_=".*2.*"; if ( !_l_.matches(_r_) ) fail("From: test line: 1" + " does not match: ["+ _l_ + "] != [" + _r_ + "]");}; } try {
126 assertEquals("From: ComTest line: 332", 2, a[2]);
127 fail("ComTest: 332 Did not throw (IndexOutOfBoundsException ex)");
128 } catch(IndexOutOfBoundsException ex) { assertEquals("From: test line: 1", "2", ex.getMessage()); }
129 try {
130 assertEquals("From: ComTest line: 333", 3, a[3]);
131 fail("ComTest: 333 Did not throw IndexOutOfBoundsException");
132 } catch(IndexOutOfBoundsException _e_){ _e_.getMessage(); }
133 }
135
138 private Strings globalList;
139
140 @Before public void init() { globalList = new Strings();
143 String st[] = { "one", "two", "three" } ;
144 for (String s:st) globalList.add(s);
145 }
146
148
149
151 @Test
152 public void testGlobalList() { assertEquals("From: ComTest line: 351", 3, globalList.size());
154 globalList.add("one");
155 }
157
158
160 @Test
161 public void testGlobalList2() { assertEquals("From: ComTest line: 357", 3, globalList.size());
163 globalList.add("two");
164 }
166
167
169 @Test
170 public void testSplitToSentences433() { Strings sns = splitToSentences("a === 5;");
172 assertEquals("From: ComTest line: 435", 2, sns.size());
173 assertEquals("From: ComTest line: 436", "a === 5", sns.get(0)); assertEquals("From: ComTest line: 436", "; ", sns.get(1));
174 assertEquals("From: ComTest line: 437", "a === 5|; ", sns.toString("|"));
175 sns = splitToSentences("a === 5; b === 3;");
176 assertEquals("From: ComTest line: 440", 4, sns.size());
177 assertEquals("From: ComTest line: 441", "a === 5|; | b === 3|; ", sns.toString("|"));
178 sns = splitToSentences("if ( a < 3 ) { a === 5; } else b === 3;");
179 assertEquals("From: ComTest line: 444", 8, sns.size());
180 assertEquals("From: ComTest line: 445", "if ( a < 3 ) |{ | a === 5|; |} |else | b === 3|; ", sns.toString("|"));
181 sns = splitToSentences("if ( a < 3 ) { a === 5; } else { b === 3; }");
182 assertEquals("From: ComTest line: 448", 10, sns.size());
183 assertEquals("From: ComTest line: 449", "if ( a < 3 ) |{ | a === 5|; |} |else |{ | b === 3|; | }", sns.toString("|"));
184 sns = splitToSentences("get(request,new String[]{\"str\",\"id\"},13,true) === 123;");
185 assertEquals("From: ComTest line: 452", 2, sns.size());
186 assertEquals("From: ComTest line: 453", "get(request,new String[]{\"str\",\"id\"},13,true) === 123|; ", sns.toString("|"));
187 }
189
190
192 @Test
193 public void testTryToFindMethodName868() { TestHelpper t = new TestHelpper();
195 Strings s1 = new Strings();
196 s1.add("*" + "/");
197 s1.add("public int function()");
198 assertEquals("From: ComTest line: 873", "testFunction1", t.codeHandler.tryToFindMethodName(s1,0));
199 s1 = new Strings();
200 s1.add("*" + "/");
201 s1.add("@" + "example public int AnotherFunction (int n, double d) // comment ");
202 assertEquals("From: ComTest line: 877", "testAnotherFunction1", t.codeHandler.tryToFindMethodName(s1,0));
203 s1 = new Strings();
204 s1.add("*" + "/");
205 s1.add("public ClassName (int n)");
206 assertEquals("From: ComTest line: 881", "testClassName1", t.codeHandler.tryToFindMethodName(s1,0));
207 s1 = new Strings();
208 s1.add("*" + "/");
209 s1.add("public AnotherClassName()");
210 assertEquals("From: ComTest line: 885", "testAnotherClassName1", t.codeHandler.tryToFindMethodName(s1,0));
211 }
213
214
216 @Test
217 public void testCheckThrows939() { TestHelpper t = new TestHelpper("test");
219 t.scan("a = 5; #THROWS IndexOutOfBoundsException");
220 assertEquals("From: ComTest line: 943", " try {", t.out[1]);
221 assertEquals("From: ComTest line: 944", " a = 5; ", t.out[2]);
222 { String _l_=t.out[3],_r_=" fail\\(.* Did not throw IndexOutOfBoundsException\"\\);"; if ( !_l_.matches(_r_) ) fail("From: ComTest line: 945" + " does not match: ["+ _l_ + "] != [" + _r_ + "]");};
223 assertEquals("From: ComTest line: 946", " } catch(IndexOutOfBoundsException _e_){ _e_.getMessage(); }", t.out[4]);
224 t.scan("a = 5; #THROWS (IndexOutOfBoundsException ex) { ex.getMessage() =R= \".*Index.*\"; }");
225 { String _l_=t.out[3],_r_=" fail\\(.* Did not throw \\(IndexOutOfBoundsException ex\\)\"\\);"; if ( !_l_.matches(_r_) ) fail("From: ComTest line: 949" + " does not match: ["+ _l_ + "] != [" + _r_ + "]");};
226 { String _l_=t.out[4],_r_=" \\} catch\\(IndexOutOfBoundsException ex\\) \\{ \\{.*matches.*\\}; \\}"; if ( !_l_.matches(_r_) ) fail("From: ComTest line: 950" + " does not match: ["+ _l_ + "] != [" + _r_ + "]");};
227 }
229
230
232 @Test
233 public void testHandleAnnotationInComments1099() { TestHelpper t = new TestHelpper();
235 assertEquals("From: ComTest line: 1101", "a", t.codeHandler.handleAnnotationInComments("a"));
236 assertEquals("From: ComTest line: 1102", "@Test", t.codeHandler.handleAnnotationInComments("* #@Test"));
237 assertEquals("From: ComTest line: 1103", "* #@example", t.codeHandler.handleAnnotationInComments("* #@example"));
238 }
240
241
243 @Test
244 public void testIsTableLine1133() { TestHelpper t = new TestHelpper();
246 assertEquals("From: ComTest line: 1135", false, t.codeHandler.isTableLine(""));
247 assertEquals("From: ComTest line: 1136", false, t.codeHandler.isTableLine("a"));
248 assertEquals("From: ComTest line: 1137", true, t.codeHandler.isTableLine("a|"));
249 assertEquals("From: ComTest line: 1138", true, t.codeHandler.isTableLine("|a"));
250 assertEquals("From: ComTest line: 1139", false, t.codeHandler.isTableLine(" a|b "));
251 assertEquals("From: ComTest line: 1140", true, t.codeHandler.isTableLine(" a | b "));
252 }
254
255
257 @Test
258 public void testHandleSentences1230() { TestHelpper t = new TestHelpper();
260 t.codeHandler.handleSentences("int a = 5;");
261 assertEquals("From: ComTest line: 1234", "int a = 5", t.initCmnds.get(1));
262 t.initCmnds.clear();
263 t.codeHandler.handleSentences("int a = 5; int b = 7;");
264 assertEquals("From: ComTest line: 1238", " ", t.initCmnds.get(0));
265 assertEquals("From: ComTest line: 1239", "int a = 5", t.initCmnds.get(1));
266 assertEquals("From: ComTest line: 1240", "; ", t.initCmnds.get(2));
267 assertEquals("From: ComTest line: 1241", "int b = 7", t.initCmnds.get(3));
268 assertEquals("From: ComTest line: 1242", "; ", t.initCmnds.get(4));
269 t.initCmnds.clear();
270 t.codeHandler.handleSentences("a === 5;");
271 assertEquals("From: ComTest line: 1246", "assertEquals(\"From: test line: 1\", 5, a)", t.initCmnds.get(1));
272 t.initCmnds.clear();
273 t.codeHandler.handleSentences("get(request,new String[]{\"str\",\"id\"},13,true) === 123;");
274 assertEquals("From: ComTest line: 1250", "assertEquals(\"From: test line: 1\", 123, get(request,new String[]{\"str\",\"id\"},13,true))", t.initCmnds.get(1));
275 t.initCmnds.clear();
276 t.codeHandler.handleSentences("\"cat\" =R= \"c.*t\";"); assertEquals("From: ComTest line: 1254", "{ String _l_=\"cat\",_r_=\"c.*t\"; if ( !_l_.matches(_r_) ) fail(\"From: test line: 1\" + \" does not match: [\"+ _l_ + \"] != [\" + _r_ + \"]\");}", t.initCmnds.get(1));
278 t.initCmnds.clear();
279 t.codeHandler.handleSentences("a ~~~ 6.0;");
280 assertEquals("From: ComTest line: 1258", "assertEquals(\"From: test line: 1\", 6.0, a, 0.000001)", t.initCmnds.get(1));
281 t.initCmnds.clear();
282 t.codeHandler.handleSentences("\"a$1\""); assertEquals("From: ComTest line: 1262", "\"a$1\"", t.initCmnds.get(1));
284 assertEquals("From: ComTest line: 1264", 0, t.template.size());
285 }
287
288
290 @Test
291 public void testHandleSentences1269() { String s="1"; assertEquals("From: ComTest line: 1273", "1", s);
293 }
295
296
298 @Test
299 public void testHandleSentences1279() { String s=null; assertEquals("From: ComTest line: 1280", null, s);
301 assertEquals("From: ComTest line: 1281", true, "a".matches("^a$")); }
304
305
307 @Test
308 public void testHandleSentences1285() { String s="$"; assertEquals("From: ComTest line: 1289", "$", s); ;
310 assertEquals("From: ComTest line: 1290", true, "a".matches("^a$")); }
313
314
316 @Test
317 public void testCheckOptionLine1658() { TestHelpper t = new TestHelpper();
319 t.scanner.checkOptionLine(" * #import imp1; // ", true);
320 assertEquals("From: ComTest line: 1661", "import imp1;", t.imports.get(0));
321 t.scanner.checkOptionLine(" * #import imp2; // ", true);
322 assertEquals("From: ComTest line: 1663", 1, t.imports.size());
323 t.scanner.checkOptionLine(" // #import imp2; // ", true);
324 assertEquals("From: ComTest line: 1665", "import imp2;", t.imports.get(1));
325 t.scanner.checkOptionLine(" //#import imp3; // ", true);
326 assertEquals("From: ComTest line: 1667", "import imp3;", t.imports.get(2));
327 t.scanner.checkOptionLine(" *#import imp4; // ", true);
328 assertEquals("From: ComTest line: 1669", "import imp4;", t.imports.get(3));
329 t.scanner.checkOptionLine(" // #import imp5; // ", true);
330 assertEquals("From: ComTest line: 1671", 4, t.imports.size());
331 }
333
334
336 @Test
337 public void testScanLine1945() { String out[] = TestHelpper.scanLine("a === 5");
339 { String _l_=out[1].trim(),_r_="assertEquals\\(\".*\", 5, a\\);"; if ( !_l_.matches(_r_) ) fail("From: ComTest line: 1947" + " does not match: ["+ _l_ + "] != [" + _r_ + "]");}
340 }
342
343
345 @Test
346 public void testScanLineTrim1962() { String out[] = TestHelpper.scanLineTrim("a === 5");
348 { String _l_=out[1].trim(),_r_="assertEquals\\(\".*\", 5, a\\);"; if ( !_l_.matches(_r_) ) fail("From: ComTest line: 1964" + " does not match: ["+ _l_ + "] != [" + _r_ + "]");}
349 }
351
352
354 @Test
355 public void testScanToLine1981() { String out = TestHelpper.scanToLine("(Exception ex) { ex.getMessage() =R= \".*ex.*\"; }");
357 { String _l_=out,_r_="\\(Exception ex\\) \\{.*ex.getMessage.* if.*matches.*fail.*\\}"; if ( !_l_.matches(_r_) ) fail("From: ComTest line: 1983" + " does not match: ["+ _l_ + "] != [" + _r_ + "]");};
358 } }