From 01c678efd5a3c3337564c11760d3c0418d98861f Mon Sep 17 00:00:00 2001 From: Pranav Srinivas Kumar Date: Sat, 30 Mar 2019 16:58:50 -0400 Subject: [PATCH] Unit test to parse a vector of ints --- tests/test_parse_args.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_parse_args.hpp b/tests/test_parse_args.hpp index 91130d2..722e621 100644 --- a/tests/test_parse_args.hpp +++ b/tests/test_parse_args.hpp @@ -82,4 +82,21 @@ TEST_CASE("Parse a double argument with default value", "[parse_args]") { auto arguments = program.get_arguments(); REQUIRE(arguments.size() == 1); REQUIRE(program.get("--ratio") == 3.14); +} + +TEST_CASE("Parse a vector of integer arguments", "[parse_args]") { + argparse::ArgumentParser program("test"); + program.add_argument("--vector") + .nargs(5) + .action([](const std::string& value) { return std::stoi(value); }); + program.parse_args({ "test", "--vector", "1", "2", "3", "4", "5" }); + auto arguments = program.get_arguments(); + REQUIRE(arguments.size() == 1); + auto vector = program.get>("--vector"); + REQUIRE(vector.size() == 5); + REQUIRE(vector[0] == 1); + REQUIRE(vector[1] == 2); + REQUIRE(vector[2] == 3); + REQUIRE(vector[3] == 4); + REQUIRE(vector[4] == 5); } \ No newline at end of file