You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2009/05/28 15:50:20 UTC

svn commit: r779605 - in /commons/proper/cli/trunk/src/test/org/apache/commons/cli: BasicParserTest.java GnuParserTest.java ParserTestCase.java PosixParserTest.java

Author: ebourg
Date: Thu May 28 13:50:19 2009
New Revision: 779605

URL: http://svn.apache.org/viewvc?rev=779605&view=rev
Log:
More tests for the partial option matching

Modified:
    commons/proper/cli/trunk/src/test/org/apache/commons/cli/BasicParserTest.java
    commons/proper/cli/trunk/src/test/org/apache/commons/cli/GnuParserTest.java
    commons/proper/cli/trunk/src/test/org/apache/commons/cli/ParserTestCase.java
    commons/proper/cli/trunk/src/test/org/apache/commons/cli/PosixParserTest.java

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli/BasicParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli/BasicParserTest.java?rev=779605&r1=779604&r2=779605&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli/BasicParserTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli/BasicParserTest.java Thu May 28 13:50:19 2009
@@ -44,7 +44,7 @@
         // not supported by the BasicParser
     }
 
-    public void testLongWithEqual() throws Exception
+    public void testLongWithEqualDoubleDash() throws Exception
     {
         // not supported by the BasicParser
     }
@@ -64,6 +64,16 @@
         // not supported by the BasicParser
     }
 
+    public void testUnambiguousPartialLongOption3() throws Exception
+    {
+        // not supported by the BasicParser
+    }
+
+    public void testUnambiguousPartialLongOption4() throws Exception
+    {
+        // not supported by the BasicParser
+    }
+
     public void testAmbiguousPartialLongOption1() throws Exception
     {
         // not supported by the BasicParser
@@ -74,7 +84,17 @@
         // not supported by the BasicParser
     }
 
-    public void testPartialLongOptionWithShort() throws Exception
+    public void testAmbiguousPartialLongOption3() throws Exception
+    {
+        // not supported by the BasicParser
+    }
+
+    public void testAmbiguousPartialLongOption4() throws Exception
+    {
+        // not supported by the BasicParser
+    }
+
+    public void testPartialLongOptionSingleDash() throws Exception
     {
         // not supported by the BasicParser
     }

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli/GnuParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli/GnuParserTest.java?rev=779605&r1=779604&r2=779605&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli/GnuParserTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli/GnuParserTest.java Thu May 28 13:50:19 2009
@@ -35,6 +35,16 @@
         // not supported by the GnuParser
     }
 
+    public void testUnambiguousPartialLongOption3() throws Exception
+    {
+        // not supported by the GnuParser
+    }
+
+    public void testUnambiguousPartialLongOption4() throws Exception
+    {
+        // not supported by the GnuParser
+    }
+
     public void testAmbiguousPartialLongOption1() throws Exception
     {
         // not supported by the GnuParser
@@ -45,7 +55,17 @@
         // not supported by the GnuParser
     }
 
-    public void testPartialLongOptionWithShort() throws Exception
+   public void testAmbiguousPartialLongOption3() throws Exception
+    {
+        // not supported by the GnuParser
+    }
+
+    public void testAmbiguousPartialLongOption4() throws Exception
+    {
+        // not supported by the GnuParser
+    }
+
+    public void testPartialLongOptionSingleDash() throws Exception
     {
         // not supported by the GnuParser
     }

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli/ParserTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli/ParserTestCase.java?rev=779605&r1=779604&r2=779605&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli/ParserTestCase.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli/ParserTestCase.java Thu May 28 13:50:19 2009
@@ -122,7 +122,7 @@
         {
             assertEquals("-d", e.getOption());
         }
-    }    
+    }
 
     public void testMissingArg() throws Exception
     {
@@ -259,7 +259,7 @@
         assertEquals("bar", cl.getOptionValue("foo"));
     }
 
-    public void testLongWithEqual() throws Exception
+    public void testLongWithEqualDoubleDash() throws Exception
     {
         String[] args = new String[] { "--foo=bar" };
 
@@ -330,6 +330,34 @@
         assertTrue("Confirm --version is set", cl.hasOption("version"));
     }
 
+    public void testUnambiguousPartialLongOption3() throws Exception
+    {
+        String[] args = new String[] { "--ver=1" };
+        
+        Options options = new Options();
+        options.addOption(OptionBuilder.withLongOpt("verbose").hasOptionalArg().create());
+        options.addOption(OptionBuilder.withLongOpt("help").create());
+        
+        CommandLine cl = parser.parse(options, args);
+        
+        assertTrue("Confirm --verbose is set", cl.hasOption("verbose"));
+        assertEquals("1", cl.getOptionValue("verbose"));
+    }
+
+    public void testUnambiguousPartialLongOption4() throws Exception
+    {
+        String[] args = new String[] { "-ver=1" };
+        
+        Options options = new Options();
+        options.addOption(OptionBuilder.withLongOpt("verbose").hasOptionalArg().create());
+        options.addOption(OptionBuilder.withLongOpt("help").create());
+        
+        CommandLine cl = parser.parse(options, args);
+        
+        assertTrue("Confirm --verbose is set", cl.hasOption("verbose"));
+        assertEquals("1", cl.getOptionValue("verbose"));
+    }
+    
     public void testAmbiguousPartialLongOption1() throws Exception
     {
         String[] args = new String[] { "--ver" };
@@ -379,8 +407,58 @@
         
         assertTrue( "Confirm MissingArgumentException caught", caught );
     }
+
+    public void testAmbiguousPartialLongOption3() throws Exception
+    {
+        String[] args = new String[] { "--ver=1" };
+        
+        Options options = new Options();
+        options.addOption(OptionBuilder.withLongOpt("version").create());
+        options.addOption(OptionBuilder.withLongOpt("verbose").hasOptionalArg().create());
+        
+        boolean caught = false;
+        
+        try 
+        {
+            parser.parse(options, args);
+        }
+        catch (AmbiguousOptionException e) 
+        {
+            caught = true;
+            assertEquals("Partial option", "--ver", e.getOption());
+            assertNotNull("Matching options null", e.getMatchingOptions());
+            assertEquals("Matching options size", 2, e.getMatchingOptions().size());
+        }
+        
+        assertTrue( "Confirm MissingArgumentException caught", caught );
+    }
+
+    public void testAmbiguousPartialLongOption4() throws Exception
+    {
+        String[] args = new String[] { "-ver=1" };
+        
+        Options options = new Options();
+        options.addOption(OptionBuilder.withLongOpt("version").create());
+        options.addOption(OptionBuilder.withLongOpt("verbose").hasOptionalArg().create());
+        
+        boolean caught = false;
+        
+        try 
+        {
+            parser.parse(options, args);
+        }
+        catch (AmbiguousOptionException e) 
+        {
+            caught = true;
+            assertEquals("Partial option", "-ver", e.getOption());
+            assertNotNull("Matching options null", e.getMatchingOptions());
+            assertEquals("Matching options size", 2, e.getMatchingOptions().size());
+        }
+        
+        assertTrue( "Confirm MissingArgumentException caught", caught );
+    }
     
-    public void testPartialLongOptionWithShort() throws Exception
+    public void testPartialLongOptionSingleDash() throws Exception
     {
         String[] args = new String[] { "-ver" };
         

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli/PosixParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli/PosixParserTest.java?rev=779605&r1=779604&r2=779605&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli/PosixParserTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli/PosixParserTest.java Thu May 28 13:50:19 2009
@@ -185,4 +185,14 @@
     {
         // not supported by the PosixParser
     }
+
+    public void testUnambiguousPartialLongOption4() throws Exception
+    {
+        // not supported by the PosixParser
+    }
+
+    public void testAmbiguousPartialLongOption4() throws Exception
+    {
+        // not supported by the PosixParser
+    }
 }