@ -231,6 +231,60 @@ BOOST_AUTO_TEST_CASE(util_ParseParameters)
BOOST_CHECK ( testArgs . GetArgs ( " -ccc " ) . size ( ) = = 2 ) ;
}
static void TestParse ( const std : : string & str , bool expected_bool , int64_t expected_int )
{
TestArgsManager test ;
test . SetupArgs ( { { " -value " , ArgsManager : : ALLOW_ANY } } ) ;
std : : string arg = " -value= " + str ;
const char * argv [ ] = { " ignored " , arg . c_str ( ) } ;
std : : string error ;
BOOST_CHECK ( test . ParseParameters ( 2 , ( char * * ) argv , error ) ) ;
BOOST_CHECK_EQUAL ( test . GetBoolArg ( " -value " , false ) , expected_bool ) ;
BOOST_CHECK_EQUAL ( test . GetBoolArg ( " -value " , true ) , expected_bool ) ;
BOOST_CHECK_EQUAL ( test . GetArg ( " -value " , 99998 ) , expected_int ) ;
BOOST_CHECK_EQUAL ( test . GetArg ( " -value " , 99999 ) , expected_int ) ;
}
// Test bool and int parsing.
BOOST_AUTO_TEST_CASE ( util_ArgParsing )
{
// Some of these cases could be ambiguous or surprising to users, and might
// be worth triggering errors or warnings in the future. But for now basic
// test coverage is useful to avoid breaking backwards compatibility
// unintentionally.
TestParse ( " " , true , 0 ) ;
TestParse ( " " , false , 0 ) ;
TestParse ( " 0 " , false , 0 ) ;
TestParse ( " 0 " , false , 0 ) ;
TestParse ( " 0 " , false , 0 ) ;
TestParse ( " +0 " , false , 0 ) ;
TestParse ( " -0 " , false , 0 ) ;
TestParse ( " 5 " , true , 5 ) ;
TestParse ( " 5 " , true , 5 ) ;
TestParse ( " 5 " , true , 5 ) ;
TestParse ( " +5 " , true , 5 ) ;
TestParse ( " -5 " , true , - 5 ) ;
TestParse ( " 0 5 " , false , 0 ) ;
TestParse ( " 5 0 " , true , 5 ) ;
TestParse ( " 050 " , true , 50 ) ;
TestParse ( " 0. " , false , 0 ) ;
TestParse ( " 5. " , true , 5 ) ;
TestParse ( " 0.0 " , false , 0 ) ;
TestParse ( " 0.5 " , false , 0 ) ;
TestParse ( " 5.0 " , true , 5 ) ;
TestParse ( " 5.5 " , true , 5 ) ;
TestParse ( " x " , false , 0 ) ;
TestParse ( " x0 " , false , 0 ) ;
TestParse ( " x5 " , false , 0 ) ;
TestParse ( " 0x " , false , 0 ) ;
TestParse ( " 5x " , true , 5 ) ;
TestParse ( " 0x5 " , false , 0 ) ;
TestParse ( " false " , false , 0 ) ;
TestParse ( " true " , false , 0 ) ;
TestParse ( " yes " , false , 0 ) ;
TestParse ( " no " , false , 0 ) ;
}
BOOST_AUTO_TEST_CASE ( util_GetBoolArg )
{
TestArgsManager testArgs ;