Modified: 
commons/proper/cli/trunk/src/test/org/apache/commons/cli2/PrecedenceTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/PrecedenceTest.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- 
commons/proper/cli/trunk/src/test/org/apache/commons/cli2/PrecedenceTest.java 
(original)
+++ 
commons/proper/cli/trunk/src/test/org/apache/commons/cli2/PrecedenceTest.java 
Fri Mar 21 20:08:23 2008
@@ -1 +1,413 @@
-/** * Licensed to the Apache Software Foundation (ASF) under one or more * 
contributor license agreements.  See the NOTICE file distributed with * this 
work for additional information regarding copyright ownership. * The ASF 
licenses this file to You under the Apache License, Version 2.0 * (the 
"License"); you may not use this file except in compliance with * the License.  
You may obtain a copy of the License at * *     
http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable 
law or agreed to in writing, software * distributed under the License is 
distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express or implied. * See the License for the specific language 
governing permissions and * limitations under the License. */package 
org.apache.commons.cli2;import java.util.Arrays;import java.util.List;import 
java.util.Set;import junit.framework.TestCase;import 
org.apache.commons.cli2.builder.ArgumentBuilder;import org.apach
 e.commons.cli2.builder.DefaultOptionBuilder;import 
org.apache.commons.cli2.builder.GroupBuilder;import 
org.apache.commons.cli2.commandline.Parser;/** * @author Rob Oxspring */public 
class PrecedenceTest extends TestCase {    private final String[] args = new 
String[] { "-file" };    public void testSimple() throws OptionException {      
  final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();        
final Group options =            new GroupBuilder()                
.withOption(oBuilder.withShortName("file").create())                .create();  
      final CommandLine cl = buildCommandLine(options, args);        
assertEquals(new String[] { "-file" }, cl);    }    public void testArgument() 
throws OptionException {        final DefaultOptionBuilder oBuilder = new 
DefaultOptionBuilder();        final ArgumentBuilder aBuilder = new 
ArgumentBuilder();        final Group options =            new GroupBuilder()   
             .withOption(                    oBuilder     
                    .withShortName("f")                        
.withArgument(aBuilder.create())                        .create())              
  .create();        final CommandLine cl = buildCommandLine(options, args);     
   assertEquals(new String[] { "-f" }, cl);    }    public void testBurst() 
throws OptionException {        final DefaultOptionBuilder oBuilder = new 
DefaultOptionBuilder();        final GroupBuilder gBuilder = new 
GroupBuilder();        final Group options =            gBuilder                
.withOption(oBuilder.withShortName("f").create())                
.withOption(oBuilder.withShortName("i").create())                
.withOption(oBuilder.withShortName("l").create())                
.withOption(oBuilder.withShortName("e").create())                .create();     
   final CommandLine cl = buildCommandLine(options, args);        
assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);    }    public void 
testChildren() throws OptionException {        final
  DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();        final 
GroupBuilder gBuilder = new GroupBuilder();        final Group children =       
     gBuilder                .withOption(oBuilder.withShortName("i").create())  
              .withOption(oBuilder.withShortName("l").create())                
.withOption(oBuilder.withShortName("e").create())                .create();     
   final Group options =            gBuilder                .withOption(        
            oBuilder                        .withShortName("f")                 
       .withChildren(children)                        .create())                
.create();        final CommandLine cl = buildCommandLine(options, args);       
 assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);    }    public void 
XtestSimpleVsArgument() throws OptionException {        final 
DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();        final 
GroupBuilder gBuilder = new GroupBuilder();        final Argu
 mentBuilder aBuilder = new ArgumentBuilder();        final Group options =     
       gBuilder                
.withOption(oBuilder.withShortName("file").create())                
.withOption(                    oBuilder                        
.withShortName("f")                        .withArgument(aBuilder.create())     
                   .create())                .create();        final 
CommandLine cl = buildCommandLine(options, args);        assertEquals(new 
String[] { "-f" }, cl);    }    public void XtestSimpleVsBurst() throws 
OptionException {        final DefaultOptionBuilder oBuilder = new 
DefaultOptionBuilder();        final GroupBuilder gBuilder = new 
GroupBuilder();        final Group options =            gBuilder                
.withOption(oBuilder.withShortName("file").create())                
.withOption(oBuilder.withShortName("f").create())                
.withOption(oBuilder.withShortName("i").create())                
.withOption(oBuilder.withShortName("l").cr
 eate())                .withOption(oBuilder.withShortName("e").create())       
         .create();        final CommandLine cl = buildCommandLine(options, 
args);        assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);    }   
 public void XtestSimpleVsChildren() throws OptionException {        final 
DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();        final 
GroupBuilder gBuilder = new GroupBuilder();        final Group children =       
     gBuilder                .withOption(                    
oBuilder.withShortName("i").withLongName("ci").create())                
.withOption(                    
oBuilder.withShortName("l").withLongName("cl").create())                
.withOption(                    
oBuilder.withShortName("e").withLongName("ce").create())                
.create();        final Group options =            gBuilder                
.withOption(oBuilder.withShortName("file").create())                
.withOption(                    oBuilder  
                       .withShortName("f")                        
.withChildren(children)                        .create())                
.create();        final CommandLine cl = buildCommandLine(options, args);       
 assertEquals(            new String[] { "-f", "-i", "--ci", "-l", "--cl", 
"-e", "--ce" },            cl);    }    public void testArgumentVsBurst() 
throws OptionException {        final DefaultOptionBuilder oBuilder = new 
DefaultOptionBuilder();        final GroupBuilder gBuilder = new 
GroupBuilder();        final ArgumentBuilder aBuilder = new ArgumentBuilder();  
      final Group options =            gBuilder                .withOption(     
               oBuilder                        .withShortName("f")              
          .withArgument(aBuilder.create())                        .create())    
            .withOption(oBuilder.withShortName("i").create())                
.withOption(oBuilder.withShortName("l").create())                
.withOption(oBuilder.
 withShortName("e").create())                .create();        final 
CommandLine cl = buildCommandLine(options, args);        assertEquals(new 
String[] { "-f" }, cl);    }    public void testArgumentVsChildren() throws 
OptionException {        final DefaultOptionBuilder oBuilder = new 
DefaultOptionBuilder();        final GroupBuilder gBuilder = new 
GroupBuilder();        final ArgumentBuilder aBuilder = new ArgumentBuilder();  
      final Group children =            gBuilder                
.withOption(oBuilder.withShortName("i").create())                
.withOption(oBuilder.withShortName("l").create())                
.withOption(oBuilder.withShortName("e").create())                .create();     
   final Group options =            gBuilder                .withOption(        
            oBuilder                        .withShortName("f")                 
       .withChildren(children)                        
.withArgument(aBuilder.create())                        .create())     
            .create();        final CommandLine cl = buildCommandLine(options, 
args);        assertEquals(new String[] { "-f" }, cl);    }    public void 
testBurstVsChildren() throws OptionException {        final 
DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();        final 
GroupBuilder gBuilder = new GroupBuilder();        final Group children =       
     gBuilder                .withOption(                    
oBuilder.withShortName("i").withLongName("ci").create())                
.withOption(                    
oBuilder.withShortName("l").withLongName("cl").create())                
.withOption(                    
oBuilder.withShortName("e").withLongName("ce").create())                
.create();        final Group options =            gBuilder                
.withOption(                    oBuilder                        
.withShortName("f")                        .withChildren(children)              
          .create())                .withOption(               
      oBuilder.withShortName("i").withLongName("bi").create())                
.withOption(                    
oBuilder.withShortName("l").withLongName("bl").create())                
.withOption(                    
oBuilder.withShortName("e").withLongName("be").create())                
.create();        final CommandLine cl = buildCommandLine(options, args);       
 assertEquals(            new String[] { "-f", "-i", "--ci", "-l", "--cl", 
"-e", "--ce" },            cl);    }    public void 
XtestSimpleVsArgumentVsBurst() throws OptionException {        final 
DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();        final 
GroupBuilder gBuilder = new GroupBuilder();        final ArgumentBuilder 
aBuilder = new ArgumentBuilder();        final Group options =            
gBuilder                .withOption(oBuilder.withShortName("file").create())    
            .withOption(                    oBuilder                        
.withShortName("f")                        .withArgu
 ment(aBuilder.create())                        .create())                
.withOption(oBuilder.withShortName("i").create())                
.withOption(oBuilder.withShortName("l").create())                
.withOption(oBuilder.withShortName("e").create())                .create();     
   final CommandLine cl = buildCommandLine(options, args);        
assertEquals(new String[] { "-f" }, cl);    }    public void 
XtestSimpleVsArgumentVsChildren() throws OptionException {        final 
DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();        final 
GroupBuilder gBuilder = new GroupBuilder();        final ArgumentBuilder 
aBuilder = new ArgumentBuilder();        final Group children =            
gBuilder                .withOption(                    
oBuilder.withShortName("i").withLongName("ci").create())                
.withOption(                    
oBuilder.withShortName("l").withLongName("cl").create())                
.withOption(                    oBuilder.withShortName
 ("e").withLongName("ce").create())                .create();        final 
Group options =            gBuilder                
.withOption(oBuilder.withShortName("file").create())                
.withOption(                    oBuilder                        
.withShortName("f")                        .withChildren(children)              
          .withArgument(aBuilder.create())                        .create())    
            .create();        final CommandLine cl = buildCommandLine(options, 
args);        assertEquals(new String[] { "-f" }, cl);    }    public void 
XtestSimpleVsBurstVsChildren() throws OptionException {        final 
DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();        final 
GroupBuilder gBuilder = new GroupBuilder();        final Group children =       
     gBuilder                .withOption(                    
oBuilder.withShortName("i").withLongName("ci").create())                
.withOption(                    oBuilder.withShortName("l").wit
 hLongName("cl").create())                .withOption(                    
oBuilder.withShortName("e").withLongName("ce").create())                
.create();        final Group options =            gBuilder                
.withOption(oBuilder.withShortName("file").create())                
.withOption(                    oBuilder                        
.withShortName("f")                        .withChildren(children)              
          .create())                
.withOption(oBuilder.withShortName("i").create())                
.withOption(oBuilder.withShortName("l").create())                
.withOption(oBuilder.withShortName("e").create())                .create();     
   final CommandLine cl = buildCommandLine(options, args);        
assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);    }    public void 
testArgumentVsBurstVsChildren() throws OptionException {        final 
DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();        final 
GroupBuilder gBuilder =
  new GroupBuilder();        final ArgumentBuilder aBuilder = new 
ArgumentBuilder();        final Group children =            gBuilder            
    .withOption(                    
oBuilder.withShortName("i").withLongName("ci").create())                
.withOption(                    
oBuilder.withShortName("l").withLongName("cl").create())                
.withOption(                    
oBuilder.withShortName("e").withLongName("ce").create())                
.create();        final Group options =            gBuilder                
.withOption(                    oBuilder                        
.withShortName("f")                        .withChildren(children)              
          .withArgument(aBuilder.create())                        .create())    
            .withOption(oBuilder.withShortName("i").create())                
.withOption(oBuilder.withShortName("l").create())                
.withOption(oBuilder.withShortName("e").create())                .create();     
   fina
 l CommandLine cl = buildCommandLine(options, args);        assertEquals(new 
String[] { "-f" }, cl);    }    public void 
XtestSimpleVsArgumentVsBurstVsChildren()        throws OptionException {        
final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();        final 
GroupBuilder gBuilder = new GroupBuilder();        final ArgumentBuilder 
aBuilder = new ArgumentBuilder();        final Group children =            
gBuilder                .withOption(                    
oBuilder.withShortName("i").withLongName("ci").create())                
.withOption(                    
oBuilder.withShortName("l").withLongName("cl").create())                
.withOption(                    
oBuilder.withShortName("e").withLongName("ce").create())                
.create();        final Group options =            gBuilder                
.withOption(oBuilder.withShortName("file").create())                
.withOption(                    oBuilder                        
.withShortName("f")
                         .withChildren(children)                        
.withArgument(aBuilder.create())                        .create())              
  .withOption(oBuilder.withShortName("i").create())                
.withOption(oBuilder.withShortName("l").create())                
.withOption(oBuilder.withShortName("e").create())                .create();     
   final CommandLine cl = buildCommandLine(options, args);        
assertEquals(new String[] { "-f" }, cl);    }    public CommandLine 
buildCommandLine(final Group group, final String[] arguments)        throws 
OptionException {        Parser p = new Parser();        p.setGroup(group);     
   return p.parse(arguments);    }    public void assertEquals(final String 
options[], final CommandLine line) {        final List expected = 
Arrays.asList(options);        final Set actual = line.getOptionTriggers();     
   assertTrue(expected.containsAll(actual));        
assertTrue(actual.containsAll(expected));    }}
\ No newline at end of file
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.cli2;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.commandline.Parser;
+
+/**
+ * @author Rob Oxspring
+ */
+public class PrecedenceTest extends TestCase {
+    private final String[] args = new String[] { "-file" };
+
+    public void testSimple() throws OptionException {
+        final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
+
+        final Group options =
+            new GroupBuilder()
+                .withOption(oBuilder.withShortName("file").create())
+                .create();
+
+        final CommandLine cl = buildCommandLine(options, args);
+        assertEquals(new String[] { "-file" }, cl);
+    }
+
+    public void testArgument() throws OptionException {
+        final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
+        final ArgumentBuilder aBuilder = new ArgumentBuilder();
+
+        final Group options =
+            new GroupBuilder()
+                .withOption(
+                    oBuilder
+                        .withShortName("f")
+                        .withArgument(aBuilder.create())
+                        .create())
+                .create();
+
+        final CommandLine cl = buildCommandLine(options, args);
+        assertEquals(new String[] { "-f" }, cl);
+    }
+
+    public void testBurst() throws OptionException {
+        final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
+        final GroupBuilder gBuilder = new GroupBuilder();
+        final Group options =
+            gBuilder
+                .withOption(oBuilder.withShortName("f").create())
+                .withOption(oBuilder.withShortName("i").create())
+                .withOption(oBuilder.withShortName("l").create())
+                .withOption(oBuilder.withShortName("e").create())
+                .create();
+
+        final CommandLine cl = buildCommandLine(options, args);
+        assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);
+    }
+
+    public void testChildren() throws OptionException {
+        final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
+        final GroupBuilder gBuilder = new GroupBuilder();
+
+        final Group children =
+            gBuilder
+                .withOption(oBuilder.withShortName("i").create())
+                .withOption(oBuilder.withShortName("l").create())
+                .withOption(oBuilder.withShortName("e").create())
+                .create();
+        final Group options =
+            gBuilder
+                .withOption(
+                    oBuilder
+                        .withShortName("f")
+                        .withChildren(children)
+                        .create())
+                .create();
+
+        final CommandLine cl = buildCommandLine(options, args);
+        assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);
+    }
+
+    public void XtestSimpleVsArgument() throws OptionException {
+        final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
+        final GroupBuilder gBuilder = new GroupBuilder();
+        final ArgumentBuilder aBuilder = new ArgumentBuilder();
+
+        final Group options =
+            gBuilder
+                .withOption(oBuilder.withShortName("file").create())
+                .withOption(
+                    oBuilder
+                        .withShortName("f")
+                        .withArgument(aBuilder.create())
+                        .create())
+                .create();
+
+        final CommandLine cl = buildCommandLine(options, args);
+        assertEquals(new String[] { "-f" }, cl);
+    }
+
+    public void XtestSimpleVsBurst() throws OptionException {
+        final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
+        final GroupBuilder gBuilder = new GroupBuilder();
+        final Group options =
+            gBuilder
+                .withOption(oBuilder.withShortName("file").create())
+                .withOption(oBuilder.withShortName("f").create())
+                .withOption(oBuilder.withShortName("i").create())
+                .withOption(oBuilder.withShortName("l").create())
+                .withOption(oBuilder.withShortName("e").create())
+                .create();
+
+        final CommandLine cl = buildCommandLine(options, args);
+        assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);
+    }
+
+    public void XtestSimpleVsChildren() throws OptionException {
+        final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
+        final GroupBuilder gBuilder = new GroupBuilder();
+
+        final Group children =
+            gBuilder
+                .withOption(
+                    oBuilder.withShortName("i").withLongName("ci").create())
+                .withOption(
+                    oBuilder.withShortName("l").withLongName("cl").create())
+                .withOption(
+                    oBuilder.withShortName("e").withLongName("ce").create())
+                .create();
+
+        final Group options =
+            gBuilder
+                .withOption(oBuilder.withShortName("file").create())
+                .withOption(
+                    oBuilder
+                        .withShortName("f")
+                        .withChildren(children)
+                        .create())
+                .create();
+
+        final CommandLine cl = buildCommandLine(options, args);
+        assertEquals(
+            new String[] { "-f", "-i", "--ci", "-l", "--cl", "-e", "--ce" },
+            cl);
+    }
+
+    public void testArgumentVsBurst() throws OptionException {
+        final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
+        final GroupBuilder gBuilder = new GroupBuilder();
+        final ArgumentBuilder aBuilder = new ArgumentBuilder();
+
+        final Group options =
+            gBuilder
+                .withOption(
+                    oBuilder
+                        .withShortName("f")
+                        .withArgument(aBuilder.create())
+                        .create())
+                .withOption(oBuilder.withShortName("i").create())
+                .withOption(oBuilder.withShortName("l").create())
+                .withOption(oBuilder.withShortName("e").create())
+                .create();
+
+        final CommandLine cl = buildCommandLine(options, args);
+        assertEquals(new String[] { "-f" }, cl);
+    }
+
+    public void testArgumentVsChildren() throws OptionException {
+        final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
+        final GroupBuilder gBuilder = new GroupBuilder();
+        final ArgumentBuilder aBuilder = new ArgumentBuilder();
+
+        final Group children =
+            gBuilder
+                .withOption(oBuilder.withShortName("i").create())
+                .withOption(oBuilder.withShortName("l").create())
+                .withOption(oBuilder.withShortName("e").create())
+                .create();
+        final Group options =
+            gBuilder
+                .withOption(
+                    oBuilder
+                        .withShortName("f")
+                        .withChildren(children)
+                        .withArgument(aBuilder.create())
+                        .create())
+                .create();
+
+        final CommandLine cl = buildCommandLine(options, args);
+        assertEquals(new String[] { "-f" }, cl);
+    }
+
+    public void testBurstVsChildren() throws OptionException {
+        final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
+        final GroupBuilder gBuilder = new GroupBuilder();
+
+        final Group children =
+            gBuilder
+                .withOption(
+                    oBuilder.withShortName("i").withLongName("ci").create())
+                .withOption(
+                    oBuilder.withShortName("l").withLongName("cl").create())
+                .withOption(
+                    oBuilder.withShortName("e").withLongName("ce").create())
+                .create();
+
+        final Group options =
+            gBuilder
+                .withOption(
+                    oBuilder
+                        .withShortName("f")
+                        .withChildren(children)
+                        .create())
+                .withOption(
+                    oBuilder.withShortName("i").withLongName("bi").create())
+                .withOption(
+                    oBuilder.withShortName("l").withLongName("bl").create())
+                .withOption(
+                    oBuilder.withShortName("e").withLongName("be").create())
+                .create();
+
+        final CommandLine cl = buildCommandLine(options, args);
+        assertEquals(
+            new String[] { "-f", "-i", "--ci", "-l", "--cl", "-e", "--ce" },
+            cl);
+    }
+
+    public void XtestSimpleVsArgumentVsBurst() throws OptionException {
+        final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
+        final GroupBuilder gBuilder = new GroupBuilder();
+        final ArgumentBuilder aBuilder = new ArgumentBuilder();
+
+        final Group options =
+            gBuilder
+                .withOption(oBuilder.withShortName("file").create())
+                .withOption(
+                    oBuilder
+                        .withShortName("f")
+                        .withArgument(aBuilder.create())
+                        .create())
+                .withOption(oBuilder.withShortName("i").create())
+                .withOption(oBuilder.withShortName("l").create())
+                .withOption(oBuilder.withShortName("e").create())
+                .create();
+
+        final CommandLine cl = buildCommandLine(options, args);
+        assertEquals(new String[] { "-f" }, cl);
+    }
+
+    public void XtestSimpleVsArgumentVsChildren() throws OptionException {
+        final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
+        final GroupBuilder gBuilder = new GroupBuilder();
+        final ArgumentBuilder aBuilder = new ArgumentBuilder();
+
+        final Group children =
+            gBuilder
+                .withOption(
+                    oBuilder.withShortName("i").withLongName("ci").create())
+                .withOption(
+                    oBuilder.withShortName("l").withLongName("cl").create())
+                .withOption(
+                    oBuilder.withShortName("e").withLongName("ce").create())
+                .create();
+
+        final Group options =
+            gBuilder
+                .withOption(oBuilder.withShortName("file").create())
+                .withOption(
+                    oBuilder
+                        .withShortName("f")
+                        .withChildren(children)
+                        .withArgument(aBuilder.create())
+                        .create())
+                .create();
+
+        final CommandLine cl = buildCommandLine(options, args);
+        assertEquals(new String[] { "-f" }, cl);
+    }
+
+    public void XtestSimpleVsBurstVsChildren() throws OptionException {
+        final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
+        final GroupBuilder gBuilder = new GroupBuilder();
+
+        final Group children =
+            gBuilder
+                .withOption(
+                    oBuilder.withShortName("i").withLongName("ci").create())
+                .withOption(
+                    oBuilder.withShortName("l").withLongName("cl").create())
+                .withOption(
+                    oBuilder.withShortName("e").withLongName("ce").create())
+                .create();
+
+        final Group options =
+            gBuilder
+                .withOption(oBuilder.withShortName("file").create())
+                .withOption(
+                    oBuilder
+                        .withShortName("f")
+                        .withChildren(children)
+                        .create())
+                .withOption(oBuilder.withShortName("i").create())
+                .withOption(oBuilder.withShortName("l").create())
+                .withOption(oBuilder.withShortName("e").create())
+                .create();
+
+        final CommandLine cl = buildCommandLine(options, args);
+        assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);
+    }
+
+    public void testArgumentVsBurstVsChildren() throws OptionException {
+        final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
+        final GroupBuilder gBuilder = new GroupBuilder();
+        final ArgumentBuilder aBuilder = new ArgumentBuilder();
+
+        final Group children =
+            gBuilder
+                .withOption(
+                    oBuilder.withShortName("i").withLongName("ci").create())
+                .withOption(
+                    oBuilder.withShortName("l").withLongName("cl").create())
+                .withOption(
+                    oBuilder.withShortName("e").withLongName("ce").create())
+                .create();
+
+        final Group options =
+            gBuilder
+                .withOption(
+                    oBuilder
+                        .withShortName("f")
+                        .withChildren(children)
+                        .withArgument(aBuilder.create())
+                        .create())
+                .withOption(oBuilder.withShortName("i").create())
+                .withOption(oBuilder.withShortName("l").create())
+                .withOption(oBuilder.withShortName("e").create())
+                .create();
+
+        final CommandLine cl = buildCommandLine(options, args);
+        assertEquals(new String[] { "-f" }, cl);
+    }
+
+    public void XtestSimpleVsArgumentVsBurstVsChildren()
+        throws OptionException {
+        final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
+        final GroupBuilder gBuilder = new GroupBuilder();
+        final ArgumentBuilder aBuilder = new ArgumentBuilder();
+
+        final Group children =
+            gBuilder
+                .withOption(
+                    oBuilder.withShortName("i").withLongName("ci").create())
+                .withOption(
+                    oBuilder.withShortName("l").withLongName("cl").create())
+                .withOption(
+                    oBuilder.withShortName("e").withLongName("ce").create())
+                .create();
+
+        final Group options =
+            gBuilder
+                .withOption(oBuilder.withShortName("file").create())
+                .withOption(
+                    oBuilder
+                        .withShortName("f")
+                        .withChildren(children)
+                        .withArgument(aBuilder.create())
+                        .create())
+                .withOption(oBuilder.withShortName("i").create())
+                .withOption(oBuilder.withShortName("l").create())
+                .withOption(oBuilder.withShortName("e").create())
+                .create();
+
+        final CommandLine cl = buildCommandLine(options, args);
+        assertEquals(new String[] { "-f" }, cl);
+    }
+
+    public CommandLine buildCommandLine(final Group group, final String[] 
arguments)
+        throws OptionException {
+        Parser p = new Parser();
+        p.setGroup(group);
+        return p.parse(arguments);
+    }
+
+    public void assertEquals(final String options[], final CommandLine line) {
+        final List expected = Arrays.asList(options);
+        final Set actual = line.getOptionTriggers();
+
+        assertTrue(expected.containsAll(actual));
+        assertTrue(actual.containsAll(expected));
+    }
+
+}

Modified: 
commons/proper/cli/trunk/src/test/org/apache/commons/cli2/WriteableCommandLineTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/WriteableCommandLineTestCase.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- 
commons/proper/cli/trunk/src/test/org/apache/commons/cli2/WriteableCommandLineTestCase.java
 (original)
+++ 
commons/proper/cli/trunk/src/test/org/apache/commons/cli2/WriteableCommandLineTestCase.java
 Fri Mar 21 20:08:23 2008
@@ -1 +1,92 @@
-/** * Licensed to the Apache Software Foundation (ASF) under one or more * 
contributor license agreements.  See the NOTICE file distributed with * this 
work for additional information regarding copyright ownership. * The ASF 
licenses this file to You under the Apache License, Version 2.0 * (the 
"License"); you may not use this file except in compliance with * the License.  
You may obtain a copy of the License at * *     
http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable 
law or agreed to in writing, software * distributed under the License is 
distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express or implied. * See the License for the specific language 
governing permissions and * limitations under the License. */package 
org.apache.commons.cli2;import org.apache.commons.cli2.option.ArgumentTest;/** 
* @author Rob Oxspring */public abstract class WriteableCommandLineTestCase 
extends CommandLineTestCase {    private W
 riteableCommandLine writeable; protected abstract WriteableCommandLine 
createWriteableCommandLine();   /* (non-Javadoc)         * @see 
org.apache.commons.cli2.CommandLineTest#createCommandLine()      */     
protected final CommandLine createCommandLine() {               final 
WriteableCommandLine cl = createWriteableCommandLine();           
cl.addOption(present);          cl.addProperty("present","present property");   
        cl.addSwitch(bool,true);                cl.addValue(present,"present 
value");           cl.addOption(multiple);         cl.addValue(multiple,"value 
1");                cl.addValue(multiple,"value 2");                
cl.addValue(multiple,"value 3");                return cl;      }       /*      
 * @see CommandLineTest#setUp()  */     public void setUp() throws Exception {  
        super.setUp();          writeable = createWriteableCommandLine();       
}       public final void testAddOption() {             
assertFalse(writeable.hasOption(present));              
writeable.addOption(present);           
assertTrue(writeable.hasOption(present));       }       public final void 
testAddValue() {              assertFalse(writeable.hasOption(present));        
      assertTrue(writeable.getValues(pre
 sent).isEmpty());              writeable.addValue(present,"value");            
assertContentsEqual(list("value"),writeable.getValues(present));                
// most options shouldn't appear due to adding values           
assertFalse(writeable.hasOption(present));              final Argument arg = 
ArgumentTest.buildHostArgument();          
assertFalse(writeable.hasOption(arg));          
assertTrue(writeable.getValues(arg).isEmpty());         
writeable.addValue(arg,"value");                
assertContentsEqual(list("value"),writeable.getValues(arg));            // 
Arguments should force the option present            
assertTrue(writeable.hasOption(arg));   }       public final void 
testAddSwitch() {             assertFalse(writeable.hasOption(present));        
      assertNull(writeable.getSwitch(present));               
writeable.addSwitch(present,true);              
assertEquals(Boolean.TRUE,writeable.getSwitch(present));                
assertTrue(writeable.hasOption(present));       }       public final void 
testAddProperty() {           assertNull(writeable.getProperty("present"));     
      writeable.addProperty("present","present value");               
assertEquals("present value",writeable.ge
 tProperty("present")); }       public final void testLooksLikeOption() {       
        //TODO Implement looksLikeOption().     }}
\ No newline at end of file
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.cli2;
+
+import org.apache.commons.cli2.option.ArgumentTest;
+
+/**
+ * @author Rob Oxspring
+ */
+public abstract class WriteableCommandLineTestCase extends CommandLineTestCase 
{
+       
+       private WriteableCommandLine writeable;
+       
+       protected abstract WriteableCommandLine createWriteableCommandLine();
+       
+       /* (non-Javadoc)
+        * @see org.apache.commons.cli2.CommandLineTest#createCommandLine()
+        */
+       protected final CommandLine createCommandLine() {
+               final WriteableCommandLine cl = createWriteableCommandLine();
+               cl.addOption(present);
+               cl.addProperty("present","present property");
+               cl.addSwitch(bool,true);
+               cl.addValue(present,"present value");
+               cl.addOption(multiple);
+               cl.addValue(multiple,"value 1");
+               cl.addValue(multiple,"value 2");
+               cl.addValue(multiple,"value 3");
+               return cl;
+       }
+       
+       /*
+        * @see CommandLineTest#setUp()
+        */
+       public void setUp() throws Exception {
+               super.setUp();
+               writeable = createWriteableCommandLine();
+       }
+       public final void testAddOption() {
+               assertFalse(writeable.hasOption(present));
+               writeable.addOption(present);
+               assertTrue(writeable.hasOption(present));
+       }
+       public final void testAddValue() {
+               assertFalse(writeable.hasOption(present));
+               assertTrue(writeable.getValues(present).isEmpty());
+               writeable.addValue(present,"value");
+               assertContentsEqual(list("value"),writeable.getValues(present));
+               
+               // most options shouldn't appear due to adding values
+               assertFalse(writeable.hasOption(present));
+               
+               final Argument arg = ArgumentTest.buildHostArgument();
+               
+               assertFalse(writeable.hasOption(arg));
+               assertTrue(writeable.getValues(arg).isEmpty());
+               writeable.addValue(arg,"value");
+               assertContentsEqual(list("value"),writeable.getValues(arg));
+               
+               // Arguments should force the option present
+               assertTrue(writeable.hasOption(arg));
+       }
+       public final void testAddSwitch() {
+               assertFalse(writeable.hasOption(present));
+               assertNull(writeable.getSwitch(present));
+               writeable.addSwitch(present,true);
+               assertEquals(Boolean.TRUE,writeable.getSwitch(present));
+               assertTrue(writeable.hasOption(present));
+       }
+       public final void testAddProperty() {
+               assertNull(writeable.getProperty("present"));
+               writeable.addProperty("present","present value");
+               assertEquals("present value",writeable.getProperty("present"));
+       }
+       public final void testLooksLikeOption() {
+               //TODO Implement looksLikeOption().
+       }
+}

Modified: 
commons/proper/cli/trunk/src/test/org/apache/commons/cli2/application/AntTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/application/AntTest.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- 
commons/proper/cli/trunk/src/test/org/apache/commons/cli2/application/AntTest.java
 (original)
+++ 
commons/proper/cli/trunk/src/test/org/apache/commons/cli2/application/AntTest.java
 Fri Mar 21 20:08:23 2008
@@ -1 +1,198 @@
-/** * Licensed to the Apache Software Foundation (ASF) under one or more * 
contributor license agreements.  See the NOTICE file distributed with * this 
work for additional information regarding copyright ownership. * The ASF 
licenses this file to You under the Apache License, Version 2.0 * (the 
"License"); you may not use this file except in compliance with * the License.  
You may obtain a copy of the License at * *     
http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable 
law or agreed to in writing, software * distributed under the License is 
distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express or implied. * See the License for the specific language 
governing permissions and * limitations under the License. */package 
org.apache.commons.cli2.application;import java.util.ArrayList;import 
java.util.List;import junit.framework.TestCase;import 
org.apache.commons.cli2.CommandLine;import org.apache.commons.cli2.Gro
 up;import org.apache.commons.cli2.OptionException;import 
org.apache.commons.cli2.builder.ArgumentBuilder;import 
org.apache.commons.cli2.builder.DefaultOptionBuilder;import 
org.apache.commons.cli2.builder.GroupBuilder;import 
org.apache.commons.cli2.commandline.Parser;import 
org.apache.commons.cli2.option.PropertyOption;//TODO Build up AntTest like 
CpTestpublic class AntTest extends TestCase {    public void testAnt() throws 
OptionException {        final DefaultOptionBuilder obuilder = new 
DefaultOptionBuilder();        final ArgumentBuilder abuilder = new 
ArgumentBuilder();        final GroupBuilder gbuilder = new GroupBuilder();     
   final Group options =            gbuilder                .withName("ant")    
            .withOption(                    obuilder                        
.withShortName("help")                        .withDescription("print this 
message")                        .create())                .withOption(         
           obuilder                 
        .withShortName("projecthelp")                        
.withDescription("print project help information")                        
.create())                .withOption(                    obuilder              
          .withShortName("version")                        
.withDescription("print the version information and exit")                      
  .create())                .withOption(                    obuilder            
            .withShortName("diagnostics")                        
.withDescription("print information that might be helpful to diagnose or report 
problems.")                        .create())                .withOption(       
             obuilder                        .withShortName("quiet")            
            .withShortName("q")                        .withDescription("be 
extra quiet")                        .create())                .withOption(     
               obuilder                        .withShortName("verbose")        
               
  .withShortName("v")                        .withDescription("be extra 
verbose")                        .create())                .withOption(         
           obuilder                        .withShortName("debug")              
          .withDescription("print debugging information")                       
 .create())                .withOption(                    obuilder             
           .withShortName("emacs")                        
.withDescription("produce logging information without adornments")              
          .create())                .withOption(                    obuilder    
                    .withShortName("logfile")                        
.withShortName("l")                        .withDescription("use given file for 
log")                        .withArgument(                            abuilder 
                               .withName("file")                                
.withMinimum(1)                                .withMaximum(1)         
                        .create())                        .create())            
    .withOption(                    obuilder                        
.withShortName("logger")                        .withDescription("the class 
which is to perform logging")                        .withArgument(             
               abuilder                                .withName("classname")   
                             .withMinimum(1)                                
.withMaximum(1)                                .create())                       
 .create())                .withOption(                    obuilder             
           .withShortName("listener")                        
.withDescription("add an instance of class as a project listener")              
          .withArgument(                            abuilder                    
            .withName("classname")                                
.withMinimum(1)                                .withMaximum(1)                  
   
            .create())                        .create())                
.withOption(                    obuilder                        
.withShortName("buildfile")                        .withShortName("file")       
                 .withShortName("f")                        
.withDescription("use given buildfile")                        .withArgument(   
                         abuilder                                
.withName("file")                                .withMinimum(1)                
                .withMaximum(1)                                .create())       
                 .create())                .withOption(PropertyOption.INSTANCE) 
               .withOption(                    obuilder                        
.withShortName("propertyfile")                        .withDescription("load 
all properties from file with -D properties taking precedence")                 
       .withArgument(                            abuilder                       
         .wit
 hName("name")                                .withMinimum(1)                   
             .withMaximum(1)                                .create())          
              .create())                .withOption(                    
obuilder                        .withShortName("inputhandler")                  
      .withDescription("the class which will handle input requests")            
            .withArgument(                            abuilder                  
              .withName("class")                                .withMinimum(1) 
                               .withMaximum(1)                                
.create())                        .create())                .withOption(        
            obuilder                        .withShortName("find")              
          .withDescription("search for buildfile towards the root of the 
filesystem and use it")                        .withArgument(                   
         abuilder                              
   .withName("file")                                .withMinimum(1)             
                   .withMaximum(1)                                .create())    
                    .create())                
.withOption(abuilder.withName("target").create())                .create();     
   Parser parser = new Parser();        parser.setGroup(options);        
CommandLine line =            parser.parse(                new String[] {       
             "-buildfile",                    "mybuild.xml",                    
"-Dproperty=value",                    "-Dproperty1=value1",                    
"-projecthelp",                    "compile",                    "docs" });     
   // check properties        assertEquals(2, line.getProperties().size());     
   assertEquals("value", line.getProperty("property"));        
assertEquals("value1", line.getProperty("property1"));        // check single 
values        assertEquals("mybuild.xml", line.getValue("-buildfile"));        
assertTrue(
 line.hasOption("-projecthelp"));        assertFalse(line.hasOption("-help"));  
      assertTrue(line.hasOption("target"));        final List targets = new 
ArrayList();        targets.add("compile");        targets.add("docs");        
assertEquals(targets, line.getValues("target"));    }}
\ No newline at end of file
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.cli2.application;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Group;
+import org.apache.commons.cli2.OptionException;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.commandline.Parser;
+import org.apache.commons.cli2.option.PropertyOption;
+
+//TODO Build up AntTest like CpTest
+public class AntTest extends TestCase {
+    public void testAnt() throws OptionException {
+        final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
+        final ArgumentBuilder abuilder = new ArgumentBuilder();
+        final GroupBuilder gbuilder = new GroupBuilder();
+
+        final Group options =
+            gbuilder
+                .withName("ant")
+                .withOption(
+                    obuilder
+                        .withShortName("help")
+                        .withDescription("print this message")
+                        .create())
+                .withOption(
+                    obuilder
+                        .withShortName("projecthelp")
+                        .withDescription("print project help information")
+                        .create())
+                .withOption(
+                    obuilder
+                        .withShortName("version")
+                        .withDescription("print the version information and 
exit")
+                        .create())
+                .withOption(
+                    obuilder
+                        .withShortName("diagnostics")
+                        .withDescription("print information that might be 
helpful to diagnose or report problems.")
+                        .create())
+                .withOption(
+                    obuilder
+                        .withShortName("quiet")
+                        .withShortName("q")
+                        .withDescription("be extra quiet")
+                        .create())
+                .withOption(
+                    obuilder
+                        .withShortName("verbose")
+                        .withShortName("v")
+                        .withDescription("be extra verbose")
+                        .create())
+                .withOption(
+                    obuilder
+                        .withShortName("debug")
+                        .withDescription("print debugging information")
+                        .create())
+                .withOption(
+                    obuilder
+                        .withShortName("emacs")
+                        .withDescription("produce logging information without 
adornments")
+                        .create())
+                .withOption(
+                    obuilder
+                        .withShortName("logfile")
+                        .withShortName("l")
+                        .withDescription("use given file for log")
+                        .withArgument(
+                            abuilder
+                                .withName("file")
+                                .withMinimum(1)
+                                .withMaximum(1)
+                                .create())
+                        .create())
+                .withOption(
+                    obuilder
+                        .withShortName("logger")
+                        .withDescription("the class which is to perform 
logging")
+                        .withArgument(
+                            abuilder
+                                .withName("classname")
+                                .withMinimum(1)
+                                .withMaximum(1)
+                                .create())
+                        .create())
+                .withOption(
+                    obuilder
+                        .withShortName("listener")
+                        .withDescription("add an instance of class as a 
project listener")
+                        .withArgument(
+                            abuilder
+                                .withName("classname")
+                                .withMinimum(1)
+                                .withMaximum(1)
+                                .create())
+                        .create())
+                .withOption(
+                    obuilder
+                        .withShortName("buildfile")
+                        .withShortName("file")
+                        .withShortName("f")
+                        .withDescription("use given buildfile")
+                        .withArgument(
+                            abuilder
+                                .withName("file")
+                                .withMinimum(1)
+                                .withMaximum(1)
+                                .create())
+                        .create())
+                .withOption(PropertyOption.INSTANCE)
+                .withOption(
+                    obuilder
+                        .withShortName("propertyfile")
+                        .withDescription("load all properties from file with 
-D properties taking precedence")
+                        .withArgument(
+                            abuilder
+                                .withName("name")
+                                .withMinimum(1)
+                                .withMaximum(1)
+                                .create())
+                        .create())
+                .withOption(
+                    obuilder
+                        .withShortName("inputhandler")
+                        .withDescription("the class which will handle input 
requests")
+                        .withArgument(
+                            abuilder
+                                .withName("class")
+                                .withMinimum(1)
+                                .withMaximum(1)
+                                .create())
+                        .create())
+                .withOption(
+                    obuilder
+                        .withShortName("find")
+                        .withDescription("search for buildfile towards the 
root of the filesystem and use it")
+                        .withArgument(
+                            abuilder
+                                .withName("file")
+                                .withMinimum(1)
+                                .withMaximum(1)
+                                .create())
+                        .create())
+                .withOption(abuilder.withName("target").create())
+                .create();
+
+        Parser parser = new Parser();
+        parser.setGroup(options);
+        CommandLine line =
+            parser.parse(
+                new String[] {
+                    "-buildfile",
+                    "mybuild.xml",
+                    "-Dproperty=value",
+                    "-Dproperty1=value1",
+                    "-projecthelp",
+                    "compile",
+                    "docs" });
+
+        // check properties
+        assertEquals(2, line.getProperties().size());
+        assertEquals("value", line.getProperty("property"));
+        assertEquals("value1", line.getProperty("property1"));
+
+        // check single values
+        assertEquals("mybuild.xml", line.getValue("-buildfile"));
+        assertTrue(line.hasOption("-projecthelp"));
+        assertFalse(line.hasOption("-help"));
+
+        assertTrue(line.hasOption("target"));
+        final List targets = new ArrayList();
+        targets.add("compile");
+        targets.add("docs");
+        assertEquals(targets, line.getValues("target"));
+    }
+}


Reply via email to