@@ -315,6 +315,58 @@ static Stream<Arguments> parseWithBooleanOptionData() {
315315 Arguments .of ("mycommand -o" , "" , 'o' , Boolean .class , "true" ));
316316 }
317317
318+ @ ParameterizedTest
319+ @ MethodSource ("parseWithBooleanOptionAndArgumentData" )
320+ void testParseWithBooleanOptionAndArgument (String input , String expectedValue , int expectedArguments ,
321+ String expectedArgumentValue ) {
322+ // given
323+ Command command = createCommand ("mycommand" , "My test command" );
324+ command .getOptions ().add (CommandOption .with ().longName ("option" ).type (boolean .class ).build ());
325+ commandRegistry .registerCommand (command );
326+ // when
327+ ParsedInput parsedInput = parser .parse (input );
328+
329+ // then
330+ assertEquals ("mycommand" , parsedInput .commandName ());
331+ assertEquals (1 , parsedInput .options ().size ());
332+ assertEquals (expectedValue , parsedInput .options ().get (0 ).value ());
333+ assertEquals (expectedArguments , parsedInput .arguments ().size ());
334+ if (expectedArguments > 0 ) {
335+ assertEquals (expectedArgumentValue , parsedInput .arguments ().get (0 ).value ());
336+ }
337+ }
338+
339+ static Stream <Arguments > parseWithBooleanOptionAndArgumentData () {
340+ return Stream .of (Arguments .of ("mycommand --option=false" , "false" , 0 , null ),
341+ Arguments .of ("mycommand --option=true" , "true" , 0 , null ),
342+ Arguments .of ("mycommand --option false" , "false" , 0 , null ),
343+ Arguments .of ("mycommand --option true" , "true" , 0 , null ),
344+ Arguments .of ("mycommand --option" , "true" , 0 , null ),
345+
346+ Arguments .of ("mycommand --option=false argument" , "false" , 1 , "argument" ),
347+ Arguments .of ("mycommand --option=true argument" , "true" , 1 , "argument" ),
348+ Arguments .of ("mycommand --option false argument" , "false" , 1 , "argument" ),
349+ Arguments .of ("mycommand --option true argument" , "true" , 1 , "argument" ),
350+ Arguments .of ("mycommand --option argument" , "true" , 1 , "argument" ),
351+
352+ Arguments .of ("mycommand argument --option=false" , "false" , 1 , "argument" ),
353+ Arguments .of ("mycommand argument --option=true" , "true" , 1 , "argument" ),
354+ Arguments .of ("mycommand argument --option false" , "false" , 1 , "argument" ),
355+ Arguments .of ("mycommand argument --option true" , "true" , 1 , "argument" ),
356+ Arguments .of ("mycommand argument --option" , "true" , 1 , "argument" ),
357+
358+ Arguments .of ("mycommand --option=false true" , "false" , 1 , "true" ),
359+ Arguments .of ("mycommand --option=true true" , "true" , 1 , "true" ),
360+ Arguments .of ("mycommand --option false false" , "false" , 1 , "false" ),
361+ Arguments .of ("mycommand --option true false" , "true" , 1 , "false" ),
362+
363+ Arguments .of ("mycommand false --option=false" , "false" , 1 , "false" ),
364+ Arguments .of ("mycommand false --option=true" , "true" , 1 , "false" ),
365+ Arguments .of ("mycommand true --option false" , "false" , 1 , "true" ),
366+ Arguments .of ("mycommand true --option true" , "true" , 1 , "true" ),
367+ Arguments .of ("mycommand true --option" , "true" , 1 , "true" ));
368+ }
369+
318370 @ ParameterizedTest
319371 @ ValueSource (strings = { "mycommand --help" , "mycommand -h" })
320372 void testParseWithHelpOption (String input ) {
0 commit comments