mirror of
https://github.com/CLIUtils/CLI11.git
synced 2026-01-19 04:52:08 +00:00
use of string_view in as<T> method (#1187)
Address Issue #881, allowing use of string_view in the as<XX> method on options. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -385,6 +385,40 @@ TEST_CASE_METHOD(TApp, "stringLikeTests", "[optiontype]") {
|
||||
CHECK("bca" == m_type.m_value);
|
||||
}
|
||||
|
||||
#if CLI11_HAS_FILESYSTEM
|
||||
#include <string_view>
|
||||
// test code from https://github.com/CLIUtils/CLI11/issues/881
|
||||
// https://github.com/Jean1995
|
||||
TEST_CASE_METHOD(TApp, "AsStringView", "[app]") {
|
||||
app.add_option("--input", "input option")->default_val("optA")->check(CLI::IsMember({"optA", "optB", "optC"}));
|
||||
|
||||
args = {};
|
||||
run();
|
||||
auto inputStr = app["--input"]->as<std::string_view>();
|
||||
CHECK(inputStr == "optA");
|
||||
|
||||
args = {"--input", "optC"};
|
||||
run();
|
||||
inputStr = app["--input"]->as<std::string_view>();
|
||||
CHECK(inputStr == "optC");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
TEST_CASE_METHOD(TApp, "AsStringRef", "[app]") {
|
||||
app.add_option("--input", "input option")->default_val("optA")->check(CLI::IsMember({"optA", "optB", "optC"}));
|
||||
|
||||
args = {};
|
||||
run();
|
||||
const std::string &inputStr = app["--input"]->as<std::string>();
|
||||
CHECK(inputStr == "optA");
|
||||
|
||||
args = {"--input", "optC"};
|
||||
run();
|
||||
const std::string &inputStr2 = app["--input"]->as<std::string>();
|
||||
CHECK(inputStr2 == "optC");
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(TApp, "VectorExpectedRange", "[optiontype]") {
|
||||
std::vector<std::string> strvec;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user