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 2008.02.03 12:16:08 // Generated by ComTest
12   *
13   */
14  public class ComTestTest {
15  
16  
17  
18    // Generated by ComTest BEGIN
19    /** testStringAdd */
20    @Test
21    public void testStringAdd() {    // ComTest: 249
22      Strings list = new Strings();  // IS
23      assertEquals("From: ComTest line: 253", 0, list.size());  // IS
24      list.add("one"); assertEquals("From: ComTest line: 259", 1, list.size());  // TS
25      assertEquals("From: ComTest line: 259", "one", list.get(0));  // TS  // TV
26      list.add("two"); assertEquals("From: ComTest line: 260", 2, list.size());  // TS
27      assertEquals("From: ComTest line: 260", "two", list.get(1));  // TS  // TV
28      list.add("three"); assertEquals("From: ComTest line: 261", 3, list.size());  // TS
29      assertEquals("From: ComTest line: 261", "three", list.get(2));  // TS  // TV
30      ; assertEquals("From: ComTest line: 262", 3, list.size());  // TS
31      ;  // TS  // TV
32      try {
33      assertEquals("From: ComTest line: 264", "three", list.get(3)); 
34      fail("ComTest: 264 Did not throw IndexOutOfBoundsException");
35      } catch(IndexOutOfBoundsException e){ e.getMessage(); } // NC
36    } // Generated by ComTest END
37  
38  
39    // Generated by ComTest BEGIN
40    /** testStringAdd2 */
41    @Test
42    public void testStringAdd2() {    // ComTest: 272
43      Strings list = new Strings();  // IS
44      assertEquals("From: ComTest line: 253", 0, list.size());  // IS
45      list.add("one"); assertEquals("From: ComTest line: 272", 1, list.size());  // TS2
46      ;  // no output no variable $b   // --         // TV
47    } // Generated by ComTest END
48  
49  
50    // Generated by ComTest BEGIN
51    /** testStringAdd3 */
52    @Test
53    public void testStringAdd3() {    // ComTest: 272
54      Strings list = new Strings();  // IS
55      assertEquals("From: ComTest line: 253", 0, list.size());  // IS
56      list.add("two"); assertEquals("From: ComTest line: 273", 1, list.size());  // TS2
57      ;  // no output no variable $b   // --         // TV 
58    } // Generated by ComTest END
59  
60  
61    // Generated by ComTest BEGIN
62    /** testStringAdd4 */
63    @Test
64    public void testStringAdd4() {    // ComTest: 273
65      Strings list = new Strings();  // IS
66      assertEquals("From: ComTest line: 253", 0, list.size());  // IS
67      list.add("three"); assertEquals("From: ComTest line: 274", 1, list.size());  // TS2
68      ;  // no output no variable $b   // --         // TV
69    } // Generated by ComTest END
70  
71  
72    // Generated by ComTest BEGIN
73    /** testStringAdd5 */
74    @Test
75    public void testStringAdd5() {    // ComTest: 274
76      Strings list = new Strings();  // IS
77      assertEquals("From: ComTest line: 253", 0, list.size());  // IS
78      list.add("four"); assertEquals("From: ComTest line: 278", 1, list.size());  // NC 
79      assertTrue("Strings: 279",list.size()>0);  // NC
80      list.add("one"); assertEquals("From: ComTest line: 285", 2, list.size());  // TS3
81      assertTrue("Strings: 285",list.size()>0);  // TS3  // TV
82      list.add("two"); assertEquals("From: ComTest line: 286", 3, list.size());  // TS3
83      assertTrue("Strings: 286",list.size()>0);  // TS3  // TV
84      list.add("three"); assertEquals("From: ComTest line: 287", 4, list.size());  // TS3
85      assertTrue("Strings: 287",list.size()>0);  // TS3  // TV
86      if ( 1 > 0 ) { assertEquals("From: ComTest line: 293", "one", list.get(1)); } // TS4  // TV
87      if ( 2 > 0 ) { assertEquals("From: ComTest line: 294", "two", list.get(2)); } // TS4  // TV
88      if ( 3 > 0 ) { assertEquals("From: ComTest line: 295", "three", list.get(3)); } // TS4  // TV
89      try {
90      if ( 4 > 0 ) { assertEquals("From: ComTest line: 296", "four", list.get(4)); } // TS4 
91      fail("ComTest: 296 Did not throw IndexOutOfBoundsException");
92      } catch(IndexOutOfBoundsException e){ e.getMessage(); }
93      if ( -1 > 0 ) { assertEquals("From: ComTest line: 297", "four", list.get(-1)); } // TS4 
94    } // Generated by ComTest END
95  
96  
97    // Generated by ComTest BEGIN
98    /** testDouble */
99    @Test
100   public void testDouble() {    // ComTest: 304
101     double d1 = 0.1;  // IS
102     assertEquals("From: ComTest line: 307", 1.0/10, d1, 0.000001);  // IS
103     assertEquals("From: ComTest line: 309", 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: 313
111     { String l="cat",r="c.*t"; if ( !l.matches(r) ) fail("From: ComTest line: 315" + " does not match: ["+ l + "] != [" + r + "]");}
112     { String l="cat",r="c.*"; if ( !l.matches(r) ) fail("From: ComTest line: 316" + " does not match: ["+ l + "] != [" + r + "]");}
113   } // Generated by ComTest END
114 
115   // Generated by ComTest BEGIN  // ComTest: 321
116  // Test raw mode and introduce an attribute and initializer 
117 
118   private Strings globalList; 
119 
120   /** */ // This is the way to make comments inside comments 
121   @Before public void init() { // Run before ALL tests, not only those below
122     globalList = new Strings(); 
123     String st[] = { "one", "two", "three" } ; 
124     for (String s:st) globalList.add(s); 
125   }
126   // Generated by ComTest END
127 
128 
129   // Generated by ComTest BEGIN
130   /** testGlobalList */
131   @Test
132   public void testGlobalList() {    // ComTest: 335
133     assertEquals("From: ComTest line: 336", 3, globalList.size()); 
134     globalList.add("one"); 
135   } // Generated by ComTest END
136 
137 
138   // Generated by ComTest BEGIN
139   /** testGlobalList2 */
140   @Test
141   public void testGlobalList2() {    // ComTest: 341
142     assertEquals("From: ComTest line: 342", 3, globalList.size()); 
143     globalList.add("two"); 
144   } // Generated by ComTest END
145 
146 
147   // Generated by ComTest BEGIN
148   /** testSplitToSentences417 */
149   @Test
150   public void testSplitToSentences417() {    // ComTest: 417
151     Strings sns = splitToSentences("a === 5;"); 
152     assertEquals("From: ComTest line: 419", 2, sns.size()); 
153     assertEquals("From: ComTest line: 420", "a === 5", sns.get(0)); assertEquals("From: ComTest line: 420", "; ", sns.get(1)); 
154     assertEquals("From: ComTest line: 421", "a === 5|; ", sns.toString("|")); 
155     sns = splitToSentences("a === 5; b === 3;"); 
156     assertEquals("From: ComTest line: 424", 4, sns.size()); 
157     assertEquals("From: ComTest line: 425", "a === 5|; | b === 3|; ", sns.toString("|")); 
158     sns = splitToSentences("if ( a < 3 ) { a === 5; } else b === 3;"); 
159     assertEquals("From: ComTest line: 428", 8, sns.size()); 
160     assertEquals("From: ComTest line: 429", "if ( a < 3 ) |{ | a === 5|; |} |else | b === 3|; ", sns.toString("|")); 
161     sns = splitToSentences("if ( a < 3 ) { a === 5; } else { b === 3; }"); 
162     assertEquals("From: ComTest line: 432", 10, sns.size()); 
163     assertEquals("From: ComTest line: 433", "if ( a < 3 ) |{ | a === 5|; |} |else |{ | b === 3|; | }", sns.toString("|")); 
164     sns = splitToSentences("get(request,new String[]{\"str\",\"id\"},13,true) === 123;"); 
165     assertEquals("From: ComTest line: 436", 2, sns.size()); 
166     assertEquals("From: ComTest line: 437", "get(request,new String[]{\"str\",\"id\"},13,true) === 123|; ", sns.toString("|")); 
167   } // Generated by ComTest END
168 
169 
170   // Generated by ComTest BEGIN
171   /** testHandleAnnotationInComments994 */
172   @Test
173   public void testHandleAnnotationInComments994() {    // ComTest: 994
174     TestHelpper t = new TestHelpper(); 
175     assertEquals("From: ComTest line: 996", "a", t.codeHandler.handleAnnotationInComments("a")); 
176     assertEquals("From: ComTest line: 997", "@Test", t.codeHandler.handleAnnotationInComments("* #@Test")); 
177     assertEquals("From: ComTest line: 998", "* #@example", t.codeHandler.handleAnnotationInComments("* #@example")); 
178   } // Generated by ComTest END
179 
180 
181   // Generated by ComTest BEGIN
182   /** testIsTableLine1028 */
183   @Test
184   public void testIsTableLine1028() {    // ComTest: 1028
185     TestHelpper t = new TestHelpper(); 
186     assertEquals("From: ComTest line: 1030", false, t.codeHandler.isTableLine("")); 
187     assertEquals("From: ComTest line: 1031", false, t.codeHandler.isTableLine("a")); 
188     assertEquals("From: ComTest line: 1032", true, t.codeHandler.isTableLine("a|")); 
189     assertEquals("From: ComTest line: 1033", true, t.codeHandler.isTableLine("|a")); 
190     assertEquals("From: ComTest line: 1034", false, t.codeHandler.isTableLine(" a|b ")); 
191     assertEquals("From: ComTest line: 1035", true, t.codeHandler.isTableLine(" a | b ")); 
192   } // Generated by ComTest END
193 
194 
195   // Generated by ComTest BEGIN
196   /** testHandleSentences1125 */
197   @Test
198   public void testHandleSentences1125() {    // ComTest: 1125
199     TestHelpper t = new TestHelpper(); 
200     t.codeHandler.handleSentences("int a = 5;"); 
201     assertEquals("From: ComTest line: 1129", "int a = 5", t.initCmnds.get(1)); 
202     t.initCmnds.clear(); 
203     t.codeHandler.handleSentences("int a = 5; int b = 7;"); 
204     assertEquals("From: ComTest line: 1133", "    ", t.initCmnds.get(0)); 
205     assertEquals("From: ComTest line: 1134", "int a = 5", t.initCmnds.get(1)); 
206     assertEquals("From: ComTest line: 1135", "; ", t.initCmnds.get(2)); 
207     assertEquals("From: ComTest line: 1136", "int b = 7", t.initCmnds.get(3)); 
208     assertEquals("From: ComTest line: 1137", "; ", t.initCmnds.get(4)); 
209     t.initCmnds.clear(); 
210     t.codeHandler.handleSentences("a === 5;"); 
211     assertEquals("From: ComTest line: 1141", "assertEquals(\"From: test line: 1\", 5, a)", t.initCmnds.get(1)); 
212     t.initCmnds.clear(); 
213     t.codeHandler.handleSentences("get(request,new String[]{\"str\",\"id\"},13,true) === 123;"); 
214     assertEquals("From: ComTest line: 1145", "assertEquals(\"From: test line: 1\", 123, get(request,new String[]{\"str\",\"id\"},13,true))", t.initCmnds.get(1)); 
215     t.initCmnds.clear(); 
216     t.codeHandler.handleSentences("\"cat\" =R= \"c.*t\";");  // "cat" =R= "c.*t";
217     assertEquals("From: ComTest line: 1149", "{ String l=\"cat\",r=\"c.*t\"; if ( !l.matches(r) ) fail(\"From: test line: 1\" + \" does not match: [\"+ l + \"] != [\" + r + \"]\");}", t.initCmnds.get(1)); 
218     t.initCmnds.clear(); 
219     t.codeHandler.handleSentences("a ~~~ 6.0;"); 
220     assertEquals("From: ComTest line: 1153", "assertEquals(\"From: test line: 1\", 6.0, a, 0.000001)", t.initCmnds.get(1)); 
221     t.initCmnds.clear(); 
222     t.codeHandler.handleSentences("\"a$1\"");  /// Not a template line  
223     assertEquals("From: ComTest line: 1157", "\"a$1\"", t.initCmnds.get(1)); 
224     assertEquals("From: ComTest line: 1159", 0, t.template.size()); 
225   } // Generated by ComTest END
226 
227 
228   // Generated by ComTest BEGIN
229   /** testHandleSentences1164 */
230   @Test
231   public void testHandleSentences1164() {    // ComTest: 1164
232     String s="1"; assertEquals("From: ComTest line: 1168", "1", s);  
233   } // Generated by ComTest END
234 
235 
236   // Generated by ComTest BEGIN
237   /** testHandleSentences1174 */
238   @Test
239   public void testHandleSentences1174() {    // ComTest: 1174
240     String s=null; assertEquals("From: ComTest line: 1175", null, s); 
241     assertEquals("From: ComTest line: 1176", true, "a".matches("^a$"));  // generate code
242   } // Generated by ComTest END
243 
244 
245   // Generated by ComTest BEGIN
246   /** testHandleSentences1180 */
247   @Test
248   public void testHandleSentences1180() {    // ComTest: 1180
249     String s="$"; assertEquals("From: ComTest line: 1184", "$", s); ;  
250     assertEquals("From: ComTest line: 1185", true, "a".matches("^a$"));  // this generates
251   } // Generated by ComTest END
252 
253 
254   // Generated by ComTest BEGIN
255   /** testCheckOptionLine1547 */
256   @Test
257   public void testCheckOptionLine1547() {    // ComTest: 1547
258     TestHelpper t = new TestHelpper(); 
259     t.scanner.checkOptionLine("    * #import imp1; // ", true); 
260     assertEquals("From: ComTest line: 1550", "import imp1;", t.imports.get(0)); 
261     t.scanner.checkOptionLine("    *  #import imp2; // ", true); 
262     assertEquals("From: ComTest line: 1552", 1, t.imports.size()); 
263     t.scanner.checkOptionLine("    // #import imp2; // ", true); 
264     assertEquals("From: ComTest line: 1554", "import imp2;", t.imports.get(1)); 
265     t.scanner.checkOptionLine("    //#import imp3; // ", true); 
266     assertEquals("From: ComTest line: 1556", "import imp3;", t.imports.get(2)); 
267     t.scanner.checkOptionLine("    *#import imp4; // ", true); 
268     assertEquals("From: ComTest line: 1558", "import imp4;", t.imports.get(3)); 
269     t.scanner.checkOptionLine("    //  #import imp5; // ", true); 
270     assertEquals("From: ComTest line: 1560", 4, t.imports.size()); 
271   } // Generated by ComTest END
272 }