Changeset 735


Ignore:
Timestamp:
08/31/12 15:14:48 (12 years ago)
Author:
pharms
Message:
  • extended and corrected task tree matching
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  
    1010import java.util.HashMap; 
    1111import java.util.Iterator; 
     12import java.util.List; 
    1213import java.util.Map; 
    1314import java.util.regex.Matcher; 
     
    3334     
    3435    /** */ 
     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    /** */ 
    3543    private boolean doTrace; 
    3644 
     
    7280        TaskSpec task = null; 
    7381 
    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             
    8888            if (task != null) { 
    8989                assertTaskAndChildrenInMapAndRemove(task, taskMapCopy); 
    9090            } 
    9191        } 
    92         while (task != null); 
    9392 
    9493        assertTrue("more tasks in map, than expected", taskMapCopy.isEmpty()); 
     
    111110     */ 
    112111    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); 
    115114 
    116115        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(" {\" +"); 
    120119        } 
    121120        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(" {\" +"); 
    125124        } 
    126125        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(" {\" +"); 
    130129        } 
    131130        else if (node instanceof IEventTask) { 
    132131            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("\""); 
    138137            } 
    139138            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(" {}\" +"); 
    144143        } 
    145144        else { 
     
    152151 
    153152        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(); 
    160159    } 
    161160 
     
    228227     *  
    229228     */ 
    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"); 
    235240        } 
    236241 
    237242        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        } 
    241253 
    242254        if ("".equals(task.name)) { 
     
    244256        } 
    245257 
    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) { 
    277264            task.children = children.toArray(new TaskSpec[children.size()]); 
    278265        } 
     
    322309        if (("Event".equals(taskSpec.type) && (!(task instanceof IEventTask))) || 
    323310            ("TextInputEvent".equals(taskSpec.type) && 
    324              (!(task instanceof IEventTask)) && 
    325              (!(((IEventTask) task).getEventType() instanceof TextInput))) || 
     311             ((!(task instanceof IEventTask)) || 
     312              (!(((IEventTask) task).getEventType() instanceof TextInput)))) || 
    326313            ("Sequence".equals(taskSpec.type) && (!(task instanceof ISequence))) || 
    327314            ("Selection".equals(taskSpec.type) && (!(task instanceof ISelection))) || 
     
    345332        if ("TextInputEvent".equals(taskSpec.type)) { 
    346333            TextInput eventType = (TextInput) ((IEventTask) task).getEventType(); 
    347             if (!"".equals(taskSpec.additionalInfo) && 
     334            if ((taskSpec.additionalInfo != null) && 
     335                !"".equals(taskSpec.additionalInfo) && 
    348336                !(taskSpec.additionalInfo.equals(eventType.getEnteredText()))) 
    349337            { 
     
    424412 
    425413    /** 
    426    * 
    427    */ 
     414     * 
     415     */ 
    428416    private void dumpTask(ITaskTreeNode task, int count, String indent) { 
    429417        System.err.print(indent); 
     
    447435        } 
    448436    } 
    449  
     437     
    450438    /** 
    451439     * TODO comment 
Note: See TracChangeset for help on using the changeset viewer.