Skip to content

Commit

Permalink
Add more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
igormironchik committed Jun 24, 2021
1 parent 6e63041 commit 2417f73
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions tests/auto/api/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,3 +730,76 @@ TEST_CASE( "CommandInGroup5" )
REQUIRE( values.at( 0 ) == SL( "./" ) );
REQUIRE( values.at( 1 ) == SL( "~/Work" ) );
}

TEST_CASE( "CommandInGroup6" )
{
const int argc = 4;
const CHAR * argv[ argc ] = { SL( "program.exe" ),
SL( "extract" ), SL( "file" ), SL( "1.zip" ) };

CmdLine cmd( argc, argv );

cmd.addOnlyOneGroup( "command or option" )
.addCommand( "extract", ValueOptions::NoValue,
true, "Extract file", "Extract file", "", "" )
.addOnlyOneGroup( "file or folder" )
.addCommand( "file", ValueOptions::ManyValues, false, "Extract file",
"Extract file", "", "fn" )
.end()
.addCommand( "folder", ValueOptions::ManyValues, false, "Extract folder",
"Extract folder", "", "dir" )
.end()
.end()
.end()
.addArgWithFlagOnly( 'e', true, false, "Extract file", "Extract file", "", "fn" )
.end()
.addHelp( true, argv[ 0 ], "commands in groups" );

cmd.parse();

REQUIRE( cmd.isDefined( "extract" ) == true );
REQUIRE( cmd.isDefined( "file" ) == true );

REQUIRE( cmd.value( "file" ) == SL( "1.zip" ) );
const auto values = cmd.values( "file" );
REQUIRE( values.size() == 1 );
REQUIRE( values.at( 0 ) == SL( "1.zip" ) );

REQUIRE( cmd.isDefined( "folder" ) == false );
REQUIRE( cmd.isDefined( "-e" ) == false );
}

TEST_CASE( "CommandInGroup7" )
{
const int argc = 2;
const CHAR * argv[ argc ] = { SL( "program.exe" ),
SL( "extract" ) };

CmdLine cmd( argc, argv );

cmd.addOnlyOneGroup( "command or option" )
.addCommand( "extract", ValueOptions::NoValue,
true, "Extract file", "Extract file", "", "" )
.addOnlyOneGroup( "file or folder" )
.addCommand( "file", ValueOptions::ManyValues, false, "Extract file",
"Extract file", "", "fn" )
.end()
.addCommand( "folder", ValueOptions::ManyValues, false, "Extract folder",
"Extract folder", "", "dir" )
.end()
.end()
.end()
.addArgWithFlagOnly( 'e', true, false, "Extract file", "Extract file", "", "fn" )
.end()
.addHelp( true, argv[ 0 ], "commands in groups" );

try {
cmd.parse();
}
catch( const BaseException & )
{
return;
}

REQUIRE( false );
}

0 comments on commit 2417f73

Please sign in to comment.