1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-30 04:33:53 +00:00

Adding and fixing a test for single name

This commit is contained in:
Henry Fredrick Schreiner 2017-11-22 14:33:55 -05:00
parent e8b15a2901
commit 851f8dc83d
2 changed files with 16 additions and 2 deletions

View File

@ -362,9 +362,9 @@ class Option : public OptionBase<Option> {
/// The most discriptive name available /// The most discriptive name available
std::string single_name() const { std::string single_name() const {
if(!lnames_.empty()) if(!lnames_.empty())
return lnames_[0]; return std::string("--") + lnames_[0];
else if(!snames_.empty()) else if(!snames_.empty())
return snames_[0]; return std::string("-") + snames_[0];
else else
return pname_; return pname_;
} }

View File

@ -354,6 +354,20 @@ TEST(THelp, CustomHelp) {
} }
} }
TEST(THelp, NiceName) {
CLI::App app;
int x;
auto long_name = app.add_option("-s,--long,-q,--other,that", x);
auto short_name = app.add_option("more,-x,-y", x);
auto positional = app.add_option("posit", x);
EXPECT_EQ(long_name->single_name(), "--long");
EXPECT_EQ(short_name->single_name(), "-x");
EXPECT_EQ(positional->single_name(), "posit");
}
TEST(Exit, ErrorWithHelp) { TEST(Exit, ErrorWithHelp) {
CLI::App app{"My prog"}; CLI::App app{"My prog"};