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 public class ComTestTest {
15
16
17
18
20 @Test
21 public void testStringAdd() { Strings list = new Strings(); assertEquals("From: ComTest line: 253", 0, list.size()); list.add("one"); assertEquals("From: ComTest line: 259", 1, list.size()); assertEquals("From: ComTest line: 259", "one", list.get(0)); list.add("two"); assertEquals("From: ComTest line: 260", 2, list.size()); assertEquals("From: ComTest line: 260", "two", list.get(1)); list.add("three"); assertEquals("From: ComTest line: 261", 3, list.size()); assertEquals("From: ComTest line: 261", "three", list.get(2)); ; assertEquals("From: ComTest line: 262", 3, list.size()); ; 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(); } }
38
39
41 @Test
42 public void testStringAdd2() { Strings list = new Strings(); assertEquals("From: ComTest line: 253", 0, list.size()); list.add("one"); assertEquals("From: ComTest line: 272", 1, list.size()); ; }
49
50
52 @Test
53 public void testStringAdd3() { Strings list = new Strings(); assertEquals("From: ComTest line: 253", 0, list.size()); list.add("two"); assertEquals("From: ComTest line: 273", 1, list.size()); ; }
60
61
63 @Test
64 public void testStringAdd4() { Strings list = new Strings(); assertEquals("From: ComTest line: 253", 0, list.size()); list.add("three"); assertEquals("From: ComTest line: 274", 1, list.size()); ; }
71
72
74 @Test
75 public void testStringAdd5() { Strings list = new Strings(); assertEquals("From: ComTest line: 253", 0, list.size()); list.add("four"); assertEquals("From: ComTest line: 278", 1, list.size()); assertTrue("Strings: 279",list.size()>0); list.add("one"); assertEquals("From: ComTest line: 285", 2, list.size()); assertTrue("Strings: 285",list.size()>0); list.add("two"); assertEquals("From: ComTest line: 286", 3, list.size()); assertTrue("Strings: 286",list.size()>0); list.add("three"); assertEquals("From: ComTest line: 287", 4, list.size()); assertTrue("Strings: 287",list.size()>0); if ( 1 > 0 ) { assertEquals("From: ComTest line: 293", "one", list.get(1)); } if ( 2 > 0 ) { assertEquals("From: ComTest line: 294", "two", list.get(2)); } if ( 3 > 0 ) { assertEquals("From: ComTest line: 295", "three", list.get(3)); } try {
90 if ( 4 > 0 ) { assertEquals("From: ComTest line: 296", "four", list.get(4)); } 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)); } }
96
97
99 @Test
100 public void testDouble() { double d1 = 0.1; assertEquals("From: ComTest line: 307", 1.0/10, d1, 0.000001); assertEquals("From: ComTest line: 309", 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: 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 }
115
118 private Strings globalList;
119
120 @Before public void init() { globalList = new Strings();
123 String st[] = { "one", "two", "three" } ;
124 for (String s:st) globalList.add(s);
125 }
126
128
129
131 @Test
132 public void testGlobalList() { assertEquals("From: ComTest line: 336", 3, globalList.size());
134 globalList.add("one");
135 }
137
138
140 @Test
141 public void testGlobalList2() { assertEquals("From: ComTest line: 342", 3, globalList.size());
143 globalList.add("two");
144 }
146
147
149 @Test
150 public void testSplitToSentences417() { 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 }
169
170
172 @Test
173 public void testHandleAnnotationInComments994() { 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 }
180
181
183 @Test
184 public void testIsTableLine1028() { 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 }
194
195
197 @Test
198 public void testHandleSentences1125() { 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\";"); 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\""); assertEquals("From: ComTest line: 1157", "\"a$1\"", t.initCmnds.get(1));
224 assertEquals("From: ComTest line: 1159", 0, t.template.size());
225 }
227
228
230 @Test
231 public void testHandleSentences1164() { String s="1"; assertEquals("From: ComTest line: 1168", "1", s);
233 }
235
236
238 @Test
239 public void testHandleSentences1174() { String s=null; assertEquals("From: ComTest line: 1175", null, s);
241 assertEquals("From: ComTest line: 1176", true, "a".matches("^a$")); }
244
245
247 @Test
248 public void testHandleSentences1180() { String s="$"; assertEquals("From: ComTest line: 1184", "$", s); ;
250 assertEquals("From: ComTest line: 1185", true, "a".matches("^a$")); }
253
254
256 @Test
257 public void testCheckOptionLine1547() { 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 } }