Changeset 735 for trunk/quest-core-tasktrees-test/src/test/java/de/ugoe
- Timestamp:
- 08/31/12 15:14:48 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/testutils/TaskTreeChecker.java
r712 r735 10 10 import java.util.HashMap; 11 11 import java.util.Iterator; 12 import java.util.List; 12 13 import java.util.Map; 13 14 import java.util.regex.Matcher; … … 33 34 34 35 /** */ 36 private static Pattern taskPattern = Pattern.compile("([^{}]+)\\{|\\}"); 37 38 /** */ 39 private static Pattern taskDetailsPattern = 40 Pattern.compile("\\s*(\\w*)\\s*(\\w*)\\s*((\\w*)|(\".*\"))?"); 41 42 /** */ 35 43 private boolean doTrace; 36 44 … … 72 80 TaskSpec task = null; 73 81 74 Matcher matcher = Pattern.compile 75 ("(\\s*(\\w+)\\s+(\\w+)\\s+((\\w*\\s)*)(\\{))|((\\}))").matcher(taskTreeSpec); 76 77 do { 78 if (!matcher.find()) { 79 if (!matcher.hitEnd()) { 80 throw new IllegalArgumentException("could not parse task specification"); 81 } 82 else { 83 break; 84 } 85 } 86 87 task = parseTask(matcher); 82 Matcher taskMatcher = taskPattern.matcher(taskTreeSpec); 83 84 while (taskMatcher.find()) { 85 86 task = parseTask(taskMatcher); 87 88 88 if (task != null) { 89 89 assertTaskAndChildrenInMapAndRemove(task, taskMapCopy); 90 90 } 91 91 } 92 while (task != null);93 92 94 93 assertTrue("more tasks in map, than expected", taskMapCopy.isEmpty()); … … 111 110 */ 112 111 private void dumpNodeAsCheckString(ITaskTreeNode node, int[] typeCounters, String indent) { 113 System. err.print(" \"");114 System. err.print(indent);112 System.out.print(" \""); 113 System.out.print(indent); 115 114 116 115 if (node instanceof ISequence) { 117 System. err.print("Sequence sequence");118 System. err.print(typeCounters[0]++);119 System. err.println(" {\" +");116 System.out.print("Sequence sequence"); 117 System.out.print(typeCounters[0]++); 118 System.out.println(" {\" +"); 120 119 } 121 120 else if (node instanceof IIteration) { 122 System. err.print("Iteration iteration");123 System. err.print(typeCounters[1]++);124 System. err.println(" {\" +");121 System.out.print("Iteration iteration"); 122 System.out.print(typeCounters[1]++); 123 System.out.println(" {\" +"); 125 124 } 126 125 else if (node instanceof ISelection) { 127 System. err.print("Selection selection");128 System. err.print(typeCounters[2]++);129 System. err.println(" {\" +");126 System.out.print("Selection selection"); 127 System.out.print(typeCounters[2]++); 128 System.out.println(" {\" +"); 130 129 } 131 130 else if (node instanceof IEventTask) { 132 131 if (((IEventTask) node).getEventType() instanceof TextInput) { 133 System. err.print("TextInputEvent textInput");134 System. err.print(typeCounters[3]++);135 System. err.print(" \"");136 System. err.print(((TextInput) ((IEventTask) node).getEventType()).getEnteredText());137 System. err.print("\"");132 System.out.print("TextInputEvent textInput"); 133 System.out.print(typeCounters[3]++); 134 System.out.print(" \""); 135 System.out.print(((TextInput) ((IEventTask) node).getEventType()).getEnteredText()); 136 System.out.print("\""); 138 137 } 139 138 else { 140 System. err.print("Event ");141 System. err.print(((IEventTask) node).getEventType().getName());142 } 143 System. err.print(" {}\" +");139 System.out.print("Event "); 140 System.out.print(((IEventTask) node).getEventType().getName()); 141 } 142 System.out.print(" {}\" +"); 144 143 } 145 144 else { … … 152 151 153 152 if (!(node instanceof IEventTask)) { 154 System. err.print(" \"");155 System. err.print(indent);156 System. err.print("}\" +");157 } 158 159 System. err.println();153 System.out.print(" \""); 154 System.out.print(indent); 155 System.out.print("}\" +"); 156 } 157 158 System.out.println(); 160 159 } 161 160 … … 228 227 * 229 228 */ 230 private TaskSpec parseTask(Matcher tokenMatcher) { 231 String firstToken = tokenMatcher.group(); 232 233 if ("}".equals(firstToken)) { 234 throw new IllegalArgumentException("found a closing bracket at an unexpected place"); 229 private TaskSpec parseTask(Matcher taskMatcher) { 230 if ("}".equals(taskMatcher.group(1))) { 231 throw new IllegalArgumentException("invalid task specification"); 232 } 233 234 String taskDetails = taskMatcher.group(1); 235 236 Matcher matcher = taskDetailsPattern.matcher(taskDetails); 237 238 if (!matcher.find()) { 239 throw new IllegalArgumentException("could not parse task details"); 235 240 } 236 241 237 242 TaskSpec task = new TaskSpec(); 238 task.type = tokenMatcher.group(2); 239 task.name = tokenMatcher.group(3); 240 task.additionalInfo = tokenMatcher.group(4).trim(); 243 task.type = matcher.group(1); 244 245 task.name = matcher.group(2); 246 if ((matcher.group(4) != null) && (!"".equals(matcher.group(4).trim()))) { 247 task.name += " " + matcher.group(4).trim(); 248 } 249 250 if ((matcher.group(5) != null) && (!"".equals(matcher.group(5).trim()))) { 251 task.additionalInfo = matcher.group(5).trim(); 252 } 241 253 242 254 if ("".equals(task.name)) { … … 244 256 } 245 257 246 if (!tokenMatcher.find()) { 247 throw new IllegalArgumentException("could not parse task specification"); 248 } 249 250 firstToken = tokenMatcher.group(); 251 252 if (!"}".equals(firstToken)) { 253 ArrayList<TaskSpec> children = new ArrayList<TaskSpec>(); 254 255 TaskSpec child = null; 256 257 do { 258 child = parseTask(tokenMatcher); 259 260 if (child != null) { 261 children.add(child); 262 263 if (!tokenMatcher.find()) { 264 throw new IllegalArgumentException("could not parse task specification"); 265 } 266 267 firstToken = tokenMatcher.group(); 268 269 if ("}".equals(firstToken)) { 270 break; 271 } 272 } 273 274 } 275 while (child != null); 276 258 List<TaskSpec> children = new ArrayList<TaskSpec>(); 259 while (taskMatcher.find() && !"}".equals(taskMatcher.group(0))) { 260 children.add(parseTask(taskMatcher)); 261 } 262 263 if (children.size() > 0) { 277 264 task.children = children.toArray(new TaskSpec[children.size()]); 278 265 } … … 322 309 if (("Event".equals(taskSpec.type) && (!(task instanceof IEventTask))) || 323 310 ("TextInputEvent".equals(taskSpec.type) && 324 ( !(task instanceof IEventTask)) &&325 (!(((IEventTask) task).getEventType() instanceof TextInput))) ||311 ((!(task instanceof IEventTask)) || 312 (!(((IEventTask) task).getEventType() instanceof TextInput)))) || 326 313 ("Sequence".equals(taskSpec.type) && (!(task instanceof ISequence))) || 327 314 ("Selection".equals(taskSpec.type) && (!(task instanceof ISelection))) || … … 345 332 if ("TextInputEvent".equals(taskSpec.type)) { 346 333 TextInput eventType = (TextInput) ((IEventTask) task).getEventType(); 347 if (!"".equals(taskSpec.additionalInfo) && 334 if ((taskSpec.additionalInfo != null) && 335 !"".equals(taskSpec.additionalInfo) && 348 336 !(taskSpec.additionalInfo.equals(eventType.getEnteredText()))) 349 337 { … … 424 412 425 413 /** 426 *427 */414 * 415 */ 428 416 private void dumpTask(ITaskTreeNode task, int count, String indent) { 429 417 System.err.print(indent); … … 447 435 } 448 436 } 449 437 450 438 /** 451 439 * TODO comment
Note: See TracChangeset
for help on using the changeset viewer.