commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jke...@apache.org
Subject cvs commit: jakarta-commons/cli/src/test/org/apache/commons/cli ApplicationTest.java OptionBuilderTest.java ParseTest.java ValuesTest.java
Date Sat, 03 Aug 2002 23:45:10 GMT
jkeyes      2002/08/03 16:45:09

  Modified:    cli/src/java/org/apache/commons/cli CommandLine.java
                        GnuParser.java Option.java OptionBuilder.java
                        PosixParser.java
               cli/src/test/org/apache/commons/cli ApplicationTest.java
                        OptionBuilderTest.java ParseTest.java
                        ValuesTest.java
  Log:
  its now possible to specify the number of argument values an option can have, refactored
parsers argument value handling, refactored argument handling in Option, added getOptions
method on CommandLine to return an array of the processed Options
  
  Revision  Changes    Path
  1.5       +20 -1     jakarta-commons/cli/src/java/org/apache/commons/cli/CommandLine.java
  
  Index: CommandLine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/CommandLine.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CommandLine.java	31 Jul 2002 22:24:29 -0000	1.4
  +++ CommandLine.java	3 Aug 2002 23:45:09 -0000	1.5
  @@ -61,6 +61,7 @@
   
   package org.apache.commons.cli;
   
  +import java.util.Collection;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.List;
  @@ -88,9 +89,12 @@
       /** the unrecognised options/arguments */
       private List args    = new LinkedList();
   
  -    /** the recognised options/arguments */
  +    /** the recognised options */
       private Map  options = new HashMap();
   
  +    /** the processed options */
  +    private Option[] optionsArray;
  +
       /**
        * <p>Creates a command line.</p>
        */
  @@ -206,6 +210,21 @@
        */
       public Iterator iterator( ) {
           return options.values().iterator();
  +    }
  +
  +    /**
  +     * <p>Returns an array of the processed {@link Option}s.</p>
  +     *
  +     * @return an array of the processed {@link Option}s.
  +     */
  +    public Option[] getOptions( ) {
  +        Collection processed = options.values();
  +
  +        // reinitialise array
  +        optionsArray = new Option[ processed.size() ];
  +
  +        // return the array
  +        return (Option[]) processed.toArray( optionsArray );
       }
   
   }
  
  
  
  1.3       +17 -18    jakarta-commons/cli/src/java/org/apache/commons/cli/GnuParser.java
  
  Index: GnuParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/GnuParser.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GnuParser.java	4 Jul 2002 22:32:12 -0000	1.2
  +++ GnuParser.java	3 Aug 2002 23:45:09 -0000	1.3
  @@ -126,7 +126,6 @@
   
           while ( iter.hasNext() ) {
               token = (String) iter.next();
  -
               if ( token.equals("--") ) {
                   eatTheRest = true;
               }
  @@ -181,20 +180,28 @@
        * @param opt the specified option
        * @param iter the iterator over the command line tokens
        */
  -    public void processMultipleArgs( Option opt, ListIterator iter ) {
  +    public void processArgs( Option opt, ListIterator iter ) 
  +    throws ParseException 
  +    {
  +        if( !iter.hasNext() ) {
  +            throw new MissingArgumentException( "no argument for:" + opt.getOpt() );
  +        }
           // loop until an option is found
           while( iter.hasNext() ) {
               String var = (String)iter.next();
   
               // its an option
  -            if( var.startsWith( "-" ) ) {
  +            if( !var.equals( "-" ) && var.startsWith( "-" ) ) {
                   // set the iterator pointer back a position
                   iter.previous();
                   break;
               }
               // its a value
               else {
  -                opt.addValue( var );
  +                if( !opt.addValue( var ) ) {
  +                    iter.previous();
  +                    break;
  +                }
               }
           }
       }
  @@ -216,6 +223,7 @@
           if( specialOption != null && opt == null) {
               opt = specialOption;
               value = arg.substring( 2 );
  +            opt.addValue( value );
           }
   
           // if there is no option throw an UnrecognisedOptionException
  @@ -236,17 +244,8 @@
           }
   
           // if the option takes an argument value
  -        if ( opt.hasArg() ) {
  -            try {
  -                value = (value != null) ? value : (String)iter.next(); 
  -            }
  -            catch( java.util.NoSuchElementException exp ) {
  -                throw new MissingArgumentException( "no argument for:" + arg );
  -            }
  -            opt.addValue( value );
  -            if  (opt.hasMultipleArgs() ) {
  -                processMultipleArgs( opt, iter );
  -            }
  +        if ( opt.hasArg() ) { 
  +            processArgs( opt, iter );
           }
   
           // set the option on the command line
  
  
  
  1.7       +66 -10    jakarta-commons/cli/src/java/org/apache/commons/cli/Option.java
  
  Index: Option.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/Option.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Option.java	31 Jul 2002 22:24:29 -0000	1.6
  +++ Option.java	3 Aug 2002 23:45:09 -0000	1.7
  @@ -106,8 +106,15 @@
       /** required specifies whether this option is required to be present */
       private boolean    required     = false;
   
  -    /** multipleArgs specifies whether this option has multiple argument values */
  -    private boolean    multipleArgs = false;   
  +    /** 
  +     * numberOfArgs specifies the number of argument values this option 
  +     * can have 
  +     */
  +    private int    numberOfArgs = UNINITIALIZED;   
  +
  +    /** number of arguments constants */
  +    public final static int UNINITIALIZED = -1;
  +    public final static int UNLIMITED_VALUES = -2;
   
       /** the type of this Option */
       private Object     type         = null;   
  @@ -115,6 +122,8 @@
       /** ?? **/
       private ArrayList  values       = new ArrayList();
       
  +    /** option char (only valid for single character options) */
  +    private char id;
   
       private void validateOption( String opt ) 
       throws IllegalArgumentException
  @@ -127,6 +136,7 @@
                   throw new IllegalArgumentException( "illegal option value '" 
                                                       + opt.charAt( 0 ) + "'" );
               }
  +            id = opt.charAt( 0 );
           }
           else {
               char[] chars = opt.toCharArray();
  @@ -153,6 +163,24 @@
           }
           return true;
       }
  +
  +    public int getId( ) {
  +        return id;
  +    }
  +
  +    /**
  +     * Creates an Option using the specified parameters.
  +     *
  +     * @param opt short representation of the option
  +     * @param hasArg specifies whether the Option takes an argument or not
  +     * @param description describes the function of the option
  +     */
  +    public Option(String opt, String description) 
  +    throws IllegalArgumentException
  +    {
  +        this(opt, null, false, description);
  +    }
  +
       /**
        * Creates an Option using the specified parameters.
        *
  @@ -181,6 +209,10 @@
   
           this.opt          = opt;
           this.longOpt      = longOpt;
  +
  +        if( hasArg ) {
  +            this.numberOfArgs = 1;
  +        }
           this.hasArg       = hasArg;
           this.description  = description;
       }
  @@ -236,7 +268,7 @@
        * @return boolean flag indicating if an argument is required
        */
       public boolean hasArg() {
  -        return this.hasArg;
  +        return this.numberOfArgs > 0 || numberOfArgs == UNLIMITED_VALUES;
       }
       
       /** <p>Retrieve the self-documenting description of this Option</p>
  @@ -259,16 +291,28 @@
            this.required = required;
        }
   
  -     /** <p>Query to see if this Option can take multiple values</p>
  +     /** <p>Query to see if this Option can take many values</p>
         *
         * @return boolean flag indicating if multiple values are allowed
         */
  -     public boolean hasMultipleArgs() {
  -         return this.multipleArgs;
  +     public boolean hasArgs() {
  +         return ( this.numberOfArgs > 1 || this.numberOfArgs == UNLIMITED_VALUES );
        }
   
  -     public void setMultipleArgs( boolean multipleArgs ) {
  -         this.multipleArgs = multipleArgs;
  +     /** <p>Sets the number of argument values this Option can take.</p>
  +      *
  +      * @param num the number of argument values
  +      */
  +     public void setArgs( int num ) {
  +         this.numberOfArgs = num;
  +     }
  +
  +     /** <p>Returns the number of argument values this Option can take.</p>
  +      *
  +      * @return num the number of argument values
  +      */
  +     public int getArgs( ) {
  +         return this.numberOfArgs;
        }
   
       /** <p>Dump state, suitable for debugging.</p>
  @@ -308,8 +352,20 @@
        * 
        * @param value is a/the value of this Option
        */
  -    public void addValue( String value ) {
  -        this.values.add( value );
  +    public boolean addValue( String value ) {
  +        switch( numberOfArgs ) {
  +            case UNINITIALIZED:
  +                return false;
  +            case UNLIMITED_VALUES:
  +                this.values.add( value );
  +                return true;
  +            default:
  +                if( values.size() > numberOfArgs-1 ) {
  +                    return false;
  +                }
  +                this.values.add( value );
  +                return true;
  +        }
       }
   
       /**
  
  
  
  1.3       +25 -16    jakarta-commons/cli/src/java/org/apache/commons/cli/OptionBuilder.java
  
  Index: OptionBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/OptionBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- OptionBuilder.java	30 Jul 2002 23:06:21 -0000	1.2
  +++ OptionBuilder.java	3 Aug 2002 23:45:09 -0000	1.3
  @@ -76,12 +76,10 @@
       private static String longopt;
       /** option description */
       private static String description;
  -    /** has an argument? */
  -    private static boolean arg;
       /** is required? */
       private static boolean required;
  -    /** has multiple arguments */
  -    private static boolean multipleArgs;
  +    /** the number of arguments */
  +    private static int numberOfArgs = Option.UNINITIALIZED;
       /** option type */
       private static Object type;
   
  @@ -99,9 +97,8 @@
           description = null;
           longopt = null;
           type = null;
  -        arg = false;
           required = false;
  -        multipleArgs = false;
  +        numberOfArgs = Option.UNINITIALIZED;
       }
   
       /**
  @@ -121,7 +118,7 @@
        * @return the OptionBuilder instance
        */
       public static OptionBuilder hasArg( ) {
  -        instance.arg = true;
  +        instance.numberOfArgs = 1;
           return instance;
       }
   
  @@ -133,7 +130,7 @@
        * @return the OptionBuilder instance
        */
       public static OptionBuilder hasArg( boolean hasArg ) {
  -        instance.arg = hasArg;
  +        instance.numberOfArgs = ( hasArg == true ) ? 1 : Option.UNINITIALIZED;
           return instance;
       }
   
  @@ -160,12 +157,24 @@
       }
   
       /**
  -     * <p>The next Option created can have multiple argument values.</p>
  +     * <p>The next Option created can have unlimited argument values.</p>
        *
        * @return the OptionBuilder instance
        */
  -    public static OptionBuilder hasMultipleArgs( ) {
  -        instance.multipleArgs = true;
  +    public static OptionBuilder hasArgs( ) {
  +        instance.numberOfArgs = Option.UNLIMITED_VALUES;
  +        return instance;
  +    }
  +
  +    /**
  +     * <p>The next Option created can have <code>num</code> 
  +     * argument values.</p>
  +     *
  +     * @param num the number of args that the option can have
  +     * @return the OptionBuilder instance
  +     */
  +    public static OptionBuilder hasArgs( int num ) {
  +        instance.numberOfArgs = num;
           return instance;
       }
   
  @@ -221,12 +230,12 @@
       throws IllegalArgumentException
       {
           // create the option
  -        Option option = new Option( opt, arg, description );
  +        Option option = new Option( opt, description );
   
           // set the option properties
           option.setLongOpt( longopt );
           option.setRequired( required );
  -        option.setMultipleArgs( multipleArgs );
  +        option.setArgs( numberOfArgs );
           option.setType( type );
   
           // reset the OptionBuilder properties
  
  
  
  1.4       +16 -16    jakarta-commons/cli/src/java/org/apache/commons/cli/PosixParser.java
  
  Index: PosixParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/PosixParser.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PosixParser.java	4 Jul 2002 22:32:12 -0000	1.3
  +++ PosixParser.java	3 Aug 2002 23:45:09 -0000	1.4
  @@ -128,6 +128,7 @@
           
           // process each command line token
           while ( iter.hasNext() ) {
  +
               // get the next command line token
               token = (String) iter.next();
               
  @@ -183,10 +184,6 @@
                                   // add the argument value
                                   opt.addValue( token.substring(i+1) );
   
  -                                // if the option takes multiple values
  -                                if  (opt.hasMultipleArgs() ) {
  -                                    processMultipleArgs( opt, iter );
  -                                }
                                   // set the option 
                                   cmd.setOpt( opt );
   
  @@ -260,12 +257,7 @@
   
           // if the option takes an argument value
           if ( opt.hasArg() ) {
  -            if  (opt.hasMultipleArgs() ) {
  -                processMultipleArgs( opt, iter );
  -            }
  -            else {
  -                opt.addValue( (String)iter.next() );
  -            }
  +            processArgs( opt, iter );
           }
   
           // set the option on the command line
  @@ -279,20 +271,28 @@
        * @param opt the specified option
        * @param iter the iterator over the command line tokens
        */
  -    public void processMultipleArgs( Option opt, ListIterator iter ) {
  +    public void processArgs( Option opt, ListIterator iter ) 
  +    throws ParseException 
  +    {
  +        if( !iter.hasNext() ) {
  +            throw new MissingArgumentException( "no argument for:" + opt.getOpt() );
  +        }
           // loop until an option is found
           while( iter.hasNext() ) {
               String var = (String)iter.next();
   
               // its an option
  -            if( var.startsWith( "-" ) ) {
  +            if( !var.equals( "-" ) && var.startsWith( "-" ) ) {
                   // set the iterator pointer back a position
                   iter.previous();
                   break;
               }
               // its a value
               else {
  -                opt.addValue( var );
  +                if( !opt.addValue( var ) ) {
  +                    iter.previous();
  +                    break;
  +                }
               }
           }
       }
  
  
  
  1.6       +1 -1      jakarta-commons/cli/src/test/org/apache/commons/cli/ApplicationTest.java
  
  Index: ApplicationTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/test/org/apache/commons/cli/ApplicationTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ApplicationTest.java	30 Jul 2002 23:06:21 -0000	1.5
  +++ ApplicationTest.java	3 Aug 2002 23:45:09 -0000	1.6
  @@ -50,7 +50,7 @@
           options.addOption( "buildfile", true, "use given buildfile" );
           options.addOption( OptionBuilder.withDescription( "use value for given property"
)
                                           .hasArg()
  -                                        .hasMultipleArgs()
  +                                        .hasArgs()
                                           .create( 'D' ) );
                              //, null, true, , false, true );
           options.addOption( "find", true, "search for buildfile towards the root of the
filesystem and use it" );
  
  
  
  1.2       +12 -5     jakarta-commons/cli/src/test/org/apache/commons/cli/OptionBuilderTest.java
  
  Index: OptionBuilderTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/test/org/apache/commons/cli/OptionBuilderTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- OptionBuilderTest.java	29 Jul 2002 22:12:37 -0000	1.1
  +++ OptionBuilderTest.java	3 Aug 2002 23:45:09 -0000	1.2
  @@ -24,7 +24,7 @@
           Option simple = OptionBuilder.withLongOpt( "simple option")
                                        .hasArg( )
                                        .isRequired( )
  -                                     .hasMultipleArgs( )
  +                                     .hasArgs( )
                                        .withType( new Float( 10 ) )
                                        .withDescription( "this is a simple option" )
                                        .create( 's' );
  @@ -35,14 +35,14 @@
           assertEquals( simple.getType().getClass(), Float.class );
           assertTrue( simple.hasArg() );
           assertTrue( simple.isRequired() );
  -        assertTrue( simple.hasMultipleArgs() );
  +        assertTrue( simple.hasArgs() );
       }
   
       public void testTwoCompleteOptions( ) {
           Option simple = OptionBuilder.withLongOpt( "simple option")
                                        .hasArg( )
                                        .isRequired( )
  -                                     .hasMultipleArgs( )
  +                                     .hasArgs( )
                                        .withType( new Float( 10 ) )
                                        .withDescription( "this is a simple option" )
                                        .create( 's' );
  @@ -53,7 +53,7 @@
           assertEquals( simple.getType().getClass(), Float.class );
           assertTrue( simple.hasArg() );
           assertTrue( simple.isRequired() );
  -        assertTrue( simple.hasMultipleArgs() );
  +        assertTrue( simple.hasArgs() );
   
           simple = OptionBuilder.withLongOpt( "dimple option")
                                 .hasArg( )
  @@ -66,7 +66,7 @@
           assertNull( simple.getType() );
           assertTrue( simple.hasArg() );
           assertTrue( !simple.isRequired() );
  -        assertTrue( !simple.hasMultipleArgs() );
  +        assertTrue( !simple.hasArgs() );
       }
   
       public void testBaseOptionCharOpt() {
  @@ -108,6 +108,13 @@
           catch( IllegalArgumentException arg ) {
               fail( "IllegalArgumentException caught" );
           }
  +    }
  +
  +    public void testOptionArgNumbers() {
  +        Option opt = OptionBuilder.withDescription( "option description" )
  +                                  .hasArgs( 2 )
  +                                  .create( 'o' );
  +        assertEquals( 2, opt.getArgs() );
       }
   
       public void testIllegalOptions() {
  
  
  
  1.4       +0 -3      jakarta-commons/cli/src/test/org/apache/commons/cli/ParseTest.java
  
  Index: ParseTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/test/org/apache/commons/cli/ParseTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ParseTest.java	4 Jul 2002 22:32:12 -0000	1.3
  +++ ParseTest.java	3 Aug 2002 23:45:09 -0000	1.4
  @@ -31,9 +31,6 @@
   
       public void setUp()
       {
  -        System.setProperty( "org.apache.commons.cli.parser",
  -                            "org.apache.commons.cli.PosixParser");
  -
           _options = new Options()
               .addOption("a",
                          "enable-a",
  
  
  
  1.5       +66 -36    jakarta-commons/cli/src/test/org/apache/commons/cli/ValuesTest.java
  
  Index: ValuesTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/test/org/apache/commons/cli/ValuesTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ValuesTest.java	30 Jul 2002 23:06:21 -0000	1.4
  +++ ValuesTest.java	3 Aug 2002 23:45:09 -0000	1.5
  @@ -10,35 +10,30 @@
   
   package org.apache.commons.cli;
   
  +import java.util.Arrays;
  +
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   
   public class ValuesTest extends TestCase
   {
  +    /** CommandLine instance */
  +    private CommandLine _cmdline = null;
   
       public static Test suite() { 
  -        return new TestSuite(ValuesTest.class); 
  -        /*
  -        TestSuite suite = new TestSuite();
  -
  -        suite.addTest( new ValueTest("testLongNoArg") );
  -
  -        return suite;
  -        */
  +        return new TestSuite( ValuesTest.class );
       }
   
  -    private CommandLine _cl = null;
  -
  -
  -    public ValuesTest(String name)
  +    public ValuesTest( String name )
       {
  -        super(name);
  +        super( name );
       }
   
       public void setUp()
       {
           Options opts = new Options();
  +
           opts.addOption("a",
                          false,
                          "toggle -a");
  @@ -58,8 +53,7 @@
                          "set -d");
           
           opts.addOption( OptionBuilder.withLongOpt( "e" )
  -                                     .hasArg()
  -                                     .hasMultipleArgs()
  +                                     .hasArgs()
                                        .withDescription( "set -e ")
                                        .create( 'e' ) );
   
  @@ -67,20 +61,37 @@
                          "f",
                          false,
                          "jk");
  -
  +        
  +        opts.addOption( OptionBuilder.withLongOpt( "g" )
  +                        .hasArgs( 2 )
  +                        .withDescription( "set -g")
  +                        .create( 'g' ) );
  +
  +        opts.addOption( OptionBuilder.withLongOpt( "h" )
  +                        .hasArgs( 2 )
  +                        .withDescription( "set -h")
  +                        .create( 'h' ) );
  +
  +        opts.addOption( OptionBuilder.withLongOpt( "i" )
  +                        .withDescription( "set -i")
  +                        .create( 'i' ) );
  +        
           String[] args = new String[] { "-a",
                                          "-b", "foo",
                                          "--c",
                                          "--d", "bar",
                                          "-e", "one", "two",
                                          "-f",
  -                                       "arg1", "arg2" };
  +                                       "arg1", "arg2",
  +                                       "-g", "val1", "val2" , "arg3",
  +                                       "-h", "val1", "-i",
  +                                       "-h", "val2" };
   
           CommandLineParser parser = CommandLineParserFactory.newParser();
   
           try
           {
  -            _cl = parser.parse(opts,args);
  +            _cmdline = parser.parse(opts,args);
           }
           catch (ParseException e)
           {
  @@ -95,37 +106,56 @@
   
       public void testShortArgs()
       {
  -        assertTrue( _cl.hasOption("a") );
  -        assertTrue( _cl.hasOption("c") );
  +        assertTrue( _cmdline.hasOption("a") );
  +        assertTrue( _cmdline.hasOption("c") );
   
  -        assertNull( _cl.getOptionValues("a") );
  -        assertNull( _cl.getOptionValues("c") );
  +        assertNull( _cmdline.getOptionValues("a") );
  +        assertNull( _cmdline.getOptionValues("c") );
       }
   
       public void testShortArgsWithValue()
       {
  -        assertTrue( _cl.hasOption("b") );
  -        assertTrue( _cl.getOptionValue("b").equals("foo"));
  -        assertTrue( _cl.getOptionValues("b").length == 1);
  -
  -        assertTrue( _cl.hasOption("d") );
  -        assertTrue( _cl.getOptionValue("d").equals("bar"));
  -        assertTrue( _cl.getOptionValues("d").length == 1);
  +        assertTrue( _cmdline.hasOption("b") );
  +        assertTrue( _cmdline.getOptionValue("b").equals("foo"));
  +        assertTrue( _cmdline.getOptionValues("b").length == 1);
  +
  +        assertTrue( _cmdline.hasOption("d") );
  +        assertTrue( _cmdline.getOptionValue("d").equals("bar"));
  +        assertTrue( _cmdline.getOptionValues("d").length == 1);
       }
   
       public void testMultipleArgValues()
       {
  -        String[] result = _cl.getOptionValues("e");
  +        String[] result = _cmdline.getOptionValues("e");
           String[] values = new String[] { "one", "two" };
  -        assertTrue( _cl.hasOption("e") );
  -        assertTrue( _cl.getOptionValues("e").length == 2);
  -        assertTrue( java.util.Arrays.equals( values, _cl.getOptionValues("e") ) );
  +        assertTrue( _cmdline.hasOption("e") );
  +        assertTrue( _cmdline.getOptionValues("e").length == 2);
  +        assertTrue( Arrays.equals( values, _cmdline.getOptionValues("e") ) );
  +    }
  +
  +    public void testTwoArgValues()
  +    {
  +        String[] result = _cmdline.getOptionValues("g");
  +        String[] values = new String[] { "val1", "val2" };
  +        assertTrue( _cmdline.hasOption("g") );
  +        assertTrue( _cmdline.getOptionValues("g").length == 2);
  +        assertTrue( Arrays.equals( values, _cmdline.getOptionValues("g") ) );
  +    }
  +
  +    public void testComplexValues()
  +    {
  +        String[] result = _cmdline.getOptionValues("h");
  +        String[] values = new String[] { "val1", "val2" };
  +        assertTrue( _cmdline.hasOption("i") );
  +        assertTrue( _cmdline.hasOption("h") );
  +        assertTrue( _cmdline.getOptionValues("h").length == 2);
  +        assertTrue( Arrays.equals( values, _cmdline.getOptionValues("h") ) );
       }
   
       public void testExtraArgs()
       {
  -        String[] args = new String[] { "arg1", "arg2" };
  -        assertTrue( _cl.getArgs().length == 2);
  -        assertTrue( java.util.Arrays.equals( args, _cl.getArgs() ) );
  +        String[] args = new String[] { "arg1", "arg2", "arg3" };
  +        assertTrue( _cmdline.getArgs().length == 3 );
  +        assertTrue( Arrays.equals( args, _cmdline.getArgs() ) );
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message