argparse/test/test_append.cpp
Sean Robinson a8900c2019 Replace simple type-converting Argument.action with Argument.scan in tests
Argument.scan handles simple string to numeric type conversions, removing
the need to create a lambda.  Argument.action is still necessary for more
complex conversions and those are left unchanged.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-08-24 09:25:49 -07:00

47 lines
1.4 KiB
C++

#include <doctest.hpp>
#include <argparse/argparse.hpp>
using doctest::test_suite;
TEST_CASE("Simplest .append" * test_suite("append")) {
argparse::ArgumentParser program("test");
program.add_argument("--dir")
.append();
program.parse_args({ "test", "--dir", "./Docs" });
std::string result { program.get("--dir") };
REQUIRE(result == "./Docs");
}
TEST_CASE("Two parameter .append" * test_suite("append")) {
argparse::ArgumentParser program("test");
program.add_argument("--dir")
.append();
program.parse_args({ "test", "--dir", "./Docs", "--dir", "./Src" });
auto result { program.get<std::vector<std::string>>("--dir") };
REQUIRE(result.at(0) == "./Docs");
REQUIRE(result.at(1) == "./Src");
}
TEST_CASE("Two int .append" * test_suite("append")) {
argparse::ArgumentParser program("test");
program.add_argument("--factor")
.append()
.scan<'i', int>();
program.parse_args({ "test", "--factor", "2", "--factor", "5" });
auto result { program.get<std::vector<int>>("--factor") };
REQUIRE(result.at(0) == 2);
REQUIRE(result.at(1) == 5);
}
TEST_CASE("Default value with .append" * test_suite("append")) {
std::vector<std::string> expected { "./Src", "./Imgs" };
argparse::ArgumentParser program("test");
program.add_argument("--dir")
.default_value(expected)
.append();
program.parse_args({ "test" });
auto result { program.get<std::vector<std::string>>("--dir") };
REQUIRE(result == expected);
}