@@ -122,7 +122,7 @@ public void testUnrecognizedOption() throws Exception
122122 {
123123 assertEquals ("-d" , e .getOption ());
124124 }
125- }
125+ }
126126
127127 public void testMissingArg () throws Exception
128128 {
@@ -259,7 +259,7 @@ public void testShortWithoutEqual() throws Exception
259259 assertEquals ("bar" , cl .getOptionValue ("foo" ));
260260 }
261261
262- public void testLongWithEqual () throws Exception
262+ public void testLongWithEqualDoubleDash () throws Exception
263263 {
264264 String [] args = new String [] { "--foo=bar" };
265265
@@ -330,6 +330,34 @@ public void testUnambiguousPartialLongOption2() throws Exception
330330 assertTrue ("Confirm --version is set" , cl .hasOption ("version" ));
331331 }
332332
333+ public void testUnambiguousPartialLongOption3 () throws Exception
334+ {
335+ String [] args = new String [] { "--ver=1" };
336+
337+ Options options = new Options ();
338+ options .addOption (OptionBuilder .withLongOpt ("verbose" ).hasOptionalArg ().create ());
339+ options .addOption (OptionBuilder .withLongOpt ("help" ).create ());
340+
341+ CommandLine cl = parser .parse (options , args );
342+
343+ assertTrue ("Confirm --verbose is set" , cl .hasOption ("verbose" ));
344+ assertEquals ("1" , cl .getOptionValue ("verbose" ));
345+ }
346+
347+ public void testUnambiguousPartialLongOption4 () throws Exception
348+ {
349+ String [] args = new String [] { "-ver=1" };
350+
351+ Options options = new Options ();
352+ options .addOption (OptionBuilder .withLongOpt ("verbose" ).hasOptionalArg ().create ());
353+ options .addOption (OptionBuilder .withLongOpt ("help" ).create ());
354+
355+ CommandLine cl = parser .parse (options , args );
356+
357+ assertTrue ("Confirm --verbose is set" , cl .hasOption ("verbose" ));
358+ assertEquals ("1" , cl .getOptionValue ("verbose" ));
359+ }
360+
333361 public void testAmbiguousPartialLongOption1 () throws Exception
334362 {
335363 String [] args = new String [] { "--ver" };
@@ -379,8 +407,58 @@ public void testAmbiguousPartialLongOption2() throws Exception
379407
380408 assertTrue ( "Confirm MissingArgumentException caught" , caught );
381409 }
410+
411+ public void testAmbiguousPartialLongOption3 () throws Exception
412+ {
413+ String [] args = new String [] { "--ver=1" };
414+
415+ Options options = new Options ();
416+ options .addOption (OptionBuilder .withLongOpt ("version" ).create ());
417+ options .addOption (OptionBuilder .withLongOpt ("verbose" ).hasOptionalArg ().create ());
418+
419+ boolean caught = false ;
420+
421+ try
422+ {
423+ parser .parse (options , args );
424+ }
425+ catch (AmbiguousOptionException e )
426+ {
427+ caught = true ;
428+ assertEquals ("Partial option" , "--ver" , e .getOption ());
429+ assertNotNull ("Matching options null" , e .getMatchingOptions ());
430+ assertEquals ("Matching options size" , 2 , e .getMatchingOptions ().size ());
431+ }
432+
433+ assertTrue ( "Confirm MissingArgumentException caught" , caught );
434+ }
435+
436+ public void testAmbiguousPartialLongOption4 () throws Exception
437+ {
438+ String [] args = new String [] { "-ver=1" };
439+
440+ Options options = new Options ();
441+ options .addOption (OptionBuilder .withLongOpt ("version" ).create ());
442+ options .addOption (OptionBuilder .withLongOpt ("verbose" ).hasOptionalArg ().create ());
443+
444+ boolean caught = false ;
445+
446+ try
447+ {
448+ parser .parse (options , args );
449+ }
450+ catch (AmbiguousOptionException e )
451+ {
452+ caught = true ;
453+ assertEquals ("Partial option" , "-ver" , e .getOption ());
454+ assertNotNull ("Matching options null" , e .getMatchingOptions ());
455+ assertEquals ("Matching options size" , 2 , e .getMatchingOptions ().size ());
456+ }
457+
458+ assertTrue ( "Confirm MissingArgumentException caught" , caught );
459+ }
382460
383- public void testPartialLongOptionWithShort () throws Exception
461+ public void testPartialLongOptionSingleDash () throws Exception
384462 {
385463 String [] args = new String [] { "-ver" };
386464
0 commit comments