@@ -231,6 +231,60 @@ BOOST_AUTO_TEST_CASE(util_ParseParameters)
231
231
BOOST_CHECK (testArgs.GetArgs (" -ccc" ).size () == 2 );
232
232
}
233
233
234
+ static void TestParse (const std::string& str, bool expected_bool, int64_t expected_int)
235
+ {
236
+ TestArgsManager test;
237
+ test.SetupArgs ({{" -value" , ArgsManager::ALLOW_ANY}});
238
+ std::string arg = " -value=" + str;
239
+ const char * argv[] = {" ignored" , arg.c_str ()};
240
+ std::string error;
241
+ BOOST_CHECK (test.ParseParameters (2 , (char **)argv, error));
242
+ BOOST_CHECK_EQUAL (test.GetBoolArg (" -value" , false ), expected_bool);
243
+ BOOST_CHECK_EQUAL (test.GetBoolArg (" -value" , true ), expected_bool);
244
+ BOOST_CHECK_EQUAL (test.GetArg (" -value" , 99998 ), expected_int);
245
+ BOOST_CHECK_EQUAL (test.GetArg (" -value" , 99999 ), expected_int);
246
+ }
247
+
248
+ // Test bool and int parsing.
249
+ BOOST_AUTO_TEST_CASE (util_ArgParsing)
250
+ {
251
+ // Some of these cases could be ambiguous or surprising to users, and might
252
+ // be worth triggering errors or warnings in the future. But for now basic
253
+ // test coverage is useful to avoid breaking backwards compatibility
254
+ // unintentionally.
255
+ TestParse (" " , true , 0 );
256
+ TestParse (" " , false , 0 );
257
+ TestParse (" 0" , false , 0 );
258
+ TestParse (" 0 " , false , 0 );
259
+ TestParse (" 0" , false , 0 );
260
+ TestParse (" +0" , false , 0 );
261
+ TestParse (" -0" , false , 0 );
262
+ TestParse (" 5" , true , 5 );
263
+ TestParse (" 5 " , true , 5 );
264
+ TestParse (" 5" , true , 5 );
265
+ TestParse (" +5" , true , 5 );
266
+ TestParse (" -5" , true , -5 );
267
+ TestParse (" 0 5" , false , 0 );
268
+ TestParse (" 5 0" , true , 5 );
269
+ TestParse (" 050" , true , 50 );
270
+ TestParse (" 0." , false , 0 );
271
+ TestParse (" 5." , true , 5 );
272
+ TestParse (" 0.0" , false , 0 );
273
+ TestParse (" 0.5" , false , 0 );
274
+ TestParse (" 5.0" , true , 5 );
275
+ TestParse (" 5.5" , true , 5 );
276
+ TestParse (" x" , false , 0 );
277
+ TestParse (" x0" , false , 0 );
278
+ TestParse (" x5" , false , 0 );
279
+ TestParse (" 0x" , false , 0 );
280
+ TestParse (" 5x" , true , 5 );
281
+ TestParse (" 0x5" , false , 0 );
282
+ TestParse (" false" , false , 0 );
283
+ TestParse (" true" , false , 0 );
284
+ TestParse (" yes" , false , 0 );
285
+ TestParse (" no" , false , 0 );
286
+ }
287
+
234
288
BOOST_AUTO_TEST_CASE (util_GetBoolArg)
235
289
{
236
290
TestArgsManager testArgs;
0 commit comments