1   package testcomtest;
2   // Generated by ComTest BEGIN
3   import comtest.Strings;
4   import static org.junit.Assert.*;
5   import org.junit.*;
6   import static comtest.ComTest.*;
7   // Generated by ComTest END
8   
9   /**
10   * Test class made by ComTest
11   * @version 2010.03.14 22:38:29 // Generated by ComTest
12   *
13   */
14  @SuppressWarnings({ "PMD" })
15  public class ComTestTest {
16  
17  
18  
19    // Generated by ComTest BEGIN
20    /** testStringAdd */
21    @Test
22    public void testStringAdd() {    // ComTest: 259
23      Strings list = new Strings();  // IS
24      assertEquals("From: ComTest line: 263", 0, list.size());  // IS
25      list.add("one"); assertEquals("From: ComTest line: 269", 1, list.size());  // TS
26      assertEquals("From: ComTest line: 269", "one", list.get(0));  // TS  // TV
27      list.add("two"); assertEquals("From: ComTest line: 270", 2, list.size());  // TS
28      assertEquals("From: ComTest line: 270", "two", list.get(1));  // TS  // TV
29      list.add("three"); assertEquals("From: ComTest line: 271", 3, list.size());  // TS
30      assertEquals("From: ComTest line: 271", "three", list.get(2));  // TS  // TV
31      ; assertEquals("From: ComTest line: 272", 3, list.size());  // TS
32      ;  // TS  // TV
33      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(); } // NC
37    } // Generated by ComTest END
38  
39  
40    // Generated by ComTest BEGIN
41    /** testStringAdd2 */
42    @Test
43    public void testStringAdd2() {    // ComTest: 282
44      Strings list = new Strings();  // IS
45      assertEquals("From: ComTest line: 263", 0, list.size());  // IS
46      list.add("one"); assertEquals("From: ComTest line: 282", 1, list.size());  // TS2
47      ;  // no output no variable $b   // --         // TV
48    } // Generated by ComTest END
49  
50  
51    // Generated by ComTest BEGIN
52    /** testStringAdd3 */
53    @Test
54    public void testStringAdd3() {    // ComTest: 282
55      Strings list = new Strings();  // IS
56      assertEquals("From: ComTest line: 263", 0, list.size());  // IS
57      list.add("two"); assertEquals("From: ComTest line: 283", 1, list.size());  // TS2
58      ;  // no output no variable $b   // --         // TV 
59    } // Generated by ComTest END
60  
61  
62    // Generated by ComTest BEGIN
63    /** testStringAdd4 */
64    @Test
65    public void testStringAdd4() {    // ComTest: 283
66      Strings list = new Strings();  // IS
67      assertEquals("From: ComTest line: 263", 0, list.size());  // IS
68      list.add("three"); assertEquals("From: ComTest line: 284", 1, list.size());  // TS2
69      ;  // no output no variable $b   // --         // TV
70    } // Generated by ComTest END
71  
72  
73    // Generated by ComTest BEGIN
74    /** testStringAdd5 */
75    @Test
76    public void testStringAdd5() {    // ComTest: 284
77      Strings list = new Strings();  // IS
78      assertEquals("From: ComTest line: 263", 0, list.size());  // IS
79      list.add("four"); assertEquals("From: ComTest line: 288", 1, list.size());  // NC 
80      assertTrue("Strings: 289",list.size()>0);  // NC
81      list.add("one"); assertEquals("From: ComTest line: 295", 2, list.size());  // TS3
82      assertTrue("Strings: 295",list.size()>0);  // TS3  // TV
83      list.add("two"); assertEquals("From: ComTest line: 296", 3, list.size());  // TS3
84      assertTrue("Strings: 296",list.size()>0);  // TS3  // TV
85      list.add("three"); assertEquals("From: ComTest line: 297", 4, list.size());  // TS3
86      assertTrue("Strings: 297",list.size()>0);  // TS3  // TV
87      if ( 1 > 0 ) { assertEquals("From: ComTest line: 303", "one", list.get(1)); } // TS4  // TV
88      if ( 2 > 0 ) { assertEquals("From: ComTest line: 304", "two", list.get(2)); } // TS4  // TV
89      if ( 3 > 0 ) { assertEquals("From: ComTest line: 305", "three", list.get(3)); } // TS4  // TV
90      try {
91      if ( 4 > 0 ) { assertEquals("From: ComTest line: 306", "four", list.get(4)); } // TS4 
92      fail("ComTest: 306 Did not throw IndexOutOfBoundsException");
93      } catch(IndexOutOfBoundsException _e_){ _e_.getMessage(); }
94    } // Generated by ComTest END
95  
96  
97    // Generated by ComTest BEGIN
98    /** testDouble */
99    @Test
100   public void testDouble() {    // ComTest: 313
101     double d1 = 0.1;  // IS
102     assertEquals("From: ComTest line: 316", 1.0/10, d1, 0.000001);  // IS
103     assertEquals("From: ComTest line: 318", 0, d1, 0.2);  // IS
104   } // Generated by ComTest END
105 
106 
107   // Generated by ComTest BEGIN
108   /** testRegExp */
109   @Test
110   public void testRegExp() {    // ComTest: 322
111     { 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   } // Generated by ComTest END
114 
115 
116   // Generated by ComTest BEGIN
117   /** testException */
118   @Test
119   public void testException() {    // ComTest: 329
120     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_ + "]");}; } // can be tested by regexp
125     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   } // Generated by ComTest END
134 
135   // Generated by ComTest BEGIN  // ComTest: 336
136  // Test raw mode and introduce an attribute and initializer 
137 
138   private Strings globalList; 
139 
140   /** */ // This is the way to make comments inside comments 
141   @Before public void init() { // Run before ALL tests, not only those below
142     globalList = new Strings(); 
143     String st[] = { "one", "two", "three" } ; 
144     for (String s:st) globalList.add(s); 
145   }
146   // Generated by ComTest END
147 
148 
149   // Generated by ComTest BEGIN
150   /** testGlobalList */
151   @Test
152   public void testGlobalList() {    // ComTest: 350
153     assertEquals("From: ComTest line: 351", 3, globalList.size()); 
154     globalList.add("one"); 
155   } // Generated by ComTest END
156 
157 
158   // Generated by ComTest BEGIN
159   /** testGlobalList2 */
160   @Test
161   public void testGlobalList2() {    // ComTest: 356
162     assertEquals("From: ComTest line: 357", 3, globalList.size()); 
163     globalList.add("two"); 
164   } // Generated by ComTest END
165 
166 
167   // Generated by ComTest BEGIN
168   /** testSplitToSentences433 */
169   @Test
170   public void testSplitToSentences433() {    // ComTest: 433
171     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   } // Generated by ComTest END
188 
189 
190   // Generated by ComTest BEGIN
191   /** testTryToFindMethodName868 */
192   @Test
193   public void testTryToFindMethodName868() {    // ComTest: 868
194     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   } // Generated by ComTest END
212 
213 
214   // Generated by ComTest BEGIN
215   /** testCheckThrows939 */
216   @Test
217   public void testCheckThrows939() {    // ComTest: 939
218     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   } // Generated by ComTest END
228 
229 
230   // Generated by ComTest BEGIN
231   /** testHandleAnnotationInComments1099 */
232   @Test
233   public void testHandleAnnotationInComments1099() {    // ComTest: 1099
234     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   } // Generated by ComTest END
239 
240 
241   // Generated by ComTest BEGIN
242   /** testIsTableLine1133 */
243   @Test
244   public void testIsTableLine1133() {    // ComTest: 1133
245     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   } // Generated by ComTest END
253 
254 
255   // Generated by ComTest BEGIN
256   /** testHandleSentences1230 */
257   @Test
258   public void testHandleSentences1230() {    // ComTest: 1230
259     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\";");  // "cat" =R= "c.*t";
277     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\"");  /// Not a template line  
283     assertEquals("From: ComTest line: 1262", "\"a$1\"", t.initCmnds.get(1)); 
284     assertEquals("From: ComTest line: 1264", 0, t.template.size()); 
285   } // Generated by ComTest END
286 
287 
288   // Generated by ComTest BEGIN
289   /** testHandleSentences1269 */
290   @Test
291   public void testHandleSentences1269() {    // ComTest: 1269
292     String s="1"; assertEquals("From: ComTest line: 1273", "1", s);  
293   } // Generated by ComTest END
294 
295 
296   // Generated by ComTest BEGIN
297   /** testHandleSentences1279 */
298   @Test
299   public void testHandleSentences1279() {    // ComTest: 1279
300     String s=null; assertEquals("From: ComTest line: 1280", null, s); 
301     assertEquals("From: ComTest line: 1281", true, "a".matches("^a$"));  // generate code
302   } // Generated by ComTest END
303 
304 
305   // Generated by ComTest BEGIN
306   /** testHandleSentences1285 */
307   @Test
308   public void testHandleSentences1285() {    // ComTest: 1285
309     String s="$"; assertEquals("From: ComTest line: 1289", "$", s); ;  
310     assertEquals("From: ComTest line: 1290", true, "a".matches("^a$"));  // this generates
311   } // Generated by ComTest END
312 
313 
314   // Generated by ComTest BEGIN
315   /** testCheckOptionLine1658 */
316   @Test
317   public void testCheckOptionLine1658() {    // ComTest: 1658
318     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   } // Generated by ComTest END
332 
333 
334   // Generated by ComTest BEGIN
335   /** testScanLine1945 */
336   @Test
337   public void testScanLine1945() {    // ComTest: 1945
338     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   } // Generated by ComTest END
341 
342 
343   // Generated by ComTest BEGIN
344   /** testScanLineTrim1962 */
345   @Test
346   public void testScanLineTrim1962() {    // ComTest: 1962
347     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   } // Generated by ComTest END
350 
351 
352   // Generated by ComTest BEGIN
353   /** testScanToLine1981 */
354   @Test
355   public void testScanToLine1981() {    // ComTest: 1981
356     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   } // Generated by ComTest END
359 }