From 7df41b626792ddf35b56f7aa68e33e6b97a83652 Mon Sep 17 00:00:00 2001 From: Pranav Srinivas Kumar Date: Sun, 31 Mar 2019 22:06:34 -0400 Subject: [PATCH] Added interesting edge case in compound argument parsing --- tests/test_compound_arguments.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_compound_arguments.hpp b/tests/test_compound_arguments.hpp index 6413ea1..a2c7b5d 100644 --- a/tests/test_compound_arguments.hpp +++ b/tests/test_compound_arguments.hpp @@ -100,4 +100,26 @@ TEST_CASE("Parse compound toggle arguments with implicit values and nargs and ot REQUIRE(argparse::get_from_list(numbers_list, 0) == 1); REQUIRE(argparse::get_from_list(numbers_list, 1) == 2); REQUIRE(argparse::get_from_list(numbers_list, 2) == 3); +} + +TEST_CASE("Parse out-of-order compound arguments", "[compound_arguments]") { + argparse::ArgumentParser program("test"); + + program.add_argument("-a") + .default_value(false) + .implicit_value(true); + + program.add_argument("-b") + .default_value(false) + .implicit_value(true); + + program.add_argument("-c") + .nargs(2) + .action([](const std::string& value) { return std::stof(value); }); + + program.parse_args({ "./main", "-cab", "3.14", "2.718" }); + + auto a = program.get("-a"); // true + auto b = program.get("-b"); // true + auto c = program.get>("-c"); // {3.14f, 2.718f} } \ No newline at end of file