jkeyes      2002/11/27 15:24:38

  Modified:    cli/src/test/org/apache/commons/cli ValueTest.java
  Log:
  some more tests
  
  Revision  Changes    Path
  1.7       +105 -4    
jakarta-commons/cli/src/test/org/apache/commons/cli/ValueTest.java
  
  Index: ValueTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/cli/src/test/org/apache/commons/cli/ValueTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ValueTest.java    18 Nov 2002 08:41:26 -0000      1.6
  +++ ValueTest.java    27 Nov 2002 23:24:38 -0000      1.7
  @@ -14,6 +14,7 @@
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   
  +import java.util.Arrays;
   import java.util.Properties;
   
   public class ValueTest extends TestCase
  @@ -73,6 +74,9 @@
           opts.addOption( OptionBuilder.hasOptionalArgs( )
                           .create( 'j' ) );
   
  +        opts.addOption( OptionBuilder.hasArgs( ).withValueSeparator( ',' )
  +                        .create( 'k' ) );
  +
           String[] args = new String[] { "-a",
               "-b", "foo",
               "--c",
  @@ -253,11 +257,14 @@
   
       public void testLongOptionalNArgValues()
       {
  -        String[] args = new String[] { "--hide", "house", "hair", "head"
  +        String[] args = new String[] { 
  +            "--hide", "house", "hair", "head"
           };
  +
  +        CommandLineParser parser = new PosixParser();
  +
           try
           {
  -            CommandLineParser parser = new PosixParser();
               CommandLine cmd = parser.parse(opts,args);
               assertTrue( cmd.hasOption("hide") );
               assertEquals( "house", cmd.getOptionValue("hide") );
  @@ -272,13 +279,15 @@
           }
       }
   
  -    public void testPropertyValues()
  +    public void testPropertyOptionSingularValue()
       {
           Properties properties = new Properties();
           properties.setProperty( "hide", "seek" );
  +
  +        CommandLineParser parser = new PosixParser();
  +        
           try
           {
  -            CommandLineParser parser = new PosixParser();
               CommandLine cmd = parser.parse(opts, null, properties);
               assertTrue( cmd.hasOption("hide") );
               assertEquals( "seek", cmd.getOptionValue("hide") );
  @@ -288,7 +297,99 @@
           {
               fail("Cannot setUp() CommandLine: " + e.toString());
           }
  +    }
  +
  +    public void testPropertyOptionFlags()
  +    {
  +        Properties properties = new Properties();
  +        properties.setProperty( "a", "true" );
  +        properties.setProperty( "c", "yes" );
  +        properties.setProperty( "e", "1" );
  +
  +        CommandLineParser parser = new PosixParser();
  +        
  +        try
  +        {
  +            CommandLine cmd = parser.parse(opts, null, properties);
  +            assertTrue( cmd.hasOption("a") );
  +            assertTrue( cmd.hasOption("c") );
  +            assertTrue( cmd.hasOption("e") );
  +        }
  +        catch (ParseException e)
  +        {
  +            fail("Cannot setUp() CommandLine: " + e.toString());
  +        }
  +
  +        properties = new Properties();
  +        properties.setProperty( "a", "false" );
  +        properties.setProperty( "c", "no" );
  +        properties.setProperty( "e", "0" );
  +        try
  +        {
  +            CommandLine cmd = parser.parse(opts, null, properties);
  +            assertTrue( !cmd.hasOption("a") );
  +            assertTrue( !cmd.hasOption("c") );
  +            assertTrue( !cmd.hasOption("e") );
  +        }
  +        catch (ParseException e)
  +        {
  +            fail("Cannot setUp() CommandLine: " + e.toString());
  +        }
  +
  +        properties = new Properties();
  +        properties.setProperty( "a", "TRUE" );
  +        properties.setProperty( "c", "nO" );
  +        properties.setProperty( "e", "TrUe" );
  +        try
  +        {
  +            CommandLine cmd = parser.parse(opts, null, properties);
  +            assertTrue( cmd.hasOption("a") );
  +            assertTrue( !cmd.hasOption("c") );
  +            assertTrue( cmd.hasOption("e") );
  +        }
  +        catch (ParseException e)
  +        {
  +            fail("Cannot setUp() CommandLine: " + e.toString());
  +        }
  +
  +        properties = new Properties();
  +        properties.setProperty( "a", "just a string" );
  +        properties.setProperty( "e", "" );
  +        try
  +        {
  +            CommandLine cmd = parser.parse(opts, null, properties);
  +            assertTrue( !cmd.hasOption("a") );
  +            assertTrue( !cmd.hasOption("c") );
  +            assertTrue( !cmd.hasOption("e") );
  +        }
  +        catch (ParseException e)
  +        {
  +            fail("Cannot setUp() CommandLine: " + e.toString());
  +        }
  +
       } 
  +
  +    public void testPropertyOptionMultipleValues()
  +    {
  +        Properties properties = new Properties();
  +        properties.setProperty( "k", "one,two" );
  +
  +        CommandLineParser parser = new PosixParser();
  +        
  +        String[] values = new String[] {
  +            "one", "two"
  +        };
  +        try
  +        {
  +            CommandLine cmd = parser.parse(opts, null, properties);
  +            assertTrue( cmd.hasOption("k") );
  +            assertTrue( Arrays.equals( values, cmd.getOptionValues('k') ) );
  +        }
  +        catch (ParseException e)
  +        {
  +            fail("Cannot setUp() CommandLine: " + e.toString());
  +        }
  +    }
   
       public void testPropertyOverrideValues()
       {
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to