Skip to content

Commit 4f872b2

Browse files
committed
Add additional tests for GetBoolArg()
This is meant to be an intermediate commit to prove that the next does not introduce any changes in the semantics of boolean option parsing.
1 parent ac898b6 commit 4f872b2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/test/util_tests.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,32 @@ BOOST_AUTO_TEST_CASE(util_ParseParameters)
223223
BOOST_CHECK(testArgs.GetArgs("-ccc").size() == 2);
224224
}
225225

226+
BOOST_AUTO_TEST_CASE(util_GetBoolArg)
227+
{
228+
TestArgsManager testArgs;
229+
const char *argv_test[] = {
230+
"ignored", "-a", "-nob", "-c=0", "-d=1", "-e=false", "-f=true"};
231+
testArgs.ParseParameters(7, (char**)argv_test);
232+
233+
// Each letter should be set.
234+
for (char opt : "abcdef")
235+
BOOST_CHECK(testArgs.IsArgSet({'-', opt}) || !opt);
236+
237+
// Nothing else should be in the map
238+
BOOST_CHECK(testArgs.GetMapArgs().size() == 6 &&
239+
testArgs.GetMapMultiArgs().size() == 6);
240+
241+
// The -no prefix should get stripped on the way in.
242+
BOOST_CHECK(!testArgs.IsArgSet("-nob"));
243+
244+
// Check expected values.
245+
BOOST_CHECK(testArgs.GetBoolArg("-a", false) == true);
246+
BOOST_CHECK(testArgs.GetBoolArg("-b", true) == false);
247+
BOOST_CHECK(testArgs.GetBoolArg("-c", true) == false);
248+
BOOST_CHECK(testArgs.GetBoolArg("-d", false) == true);
249+
BOOST_CHECK(testArgs.GetBoolArg("-e", true) == false);
250+
BOOST_CHECK(testArgs.GetBoolArg("-f", true) == false);
251+
}
226252
BOOST_AUTO_TEST_CASE(util_GetArg)
227253
{
228254
TestArgsManager testArgs;

0 commit comments

Comments
 (0)