本文整理汇总了C++中ProgramOptions::values方法的典型用法代码示例。如果您正苦于以下问题:C++ ProgramOptions::values方法的具体用法?C++ ProgramOptions::values怎么用?C++ ProgramOptions::values使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProgramOptions
的用法示例。
在下文中一共展示了ProgramOptions::values方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST(ProgramOptions, Parse)
{
ProgramOptions po;
ProgramOptions::Option& help = po.add("help").mnemonic('?');
ProgramOptions::Option& input = po.add("input").mnemonic('i').requiresValue("INPUT");
ProgramOptions::Option& output = po.add("output").mnemonic('o').requiresValue("OUTPUT");
const char* argv1[] = { "program.exe", "-?" };
po.parse(2, argv1);
EXPECT_TRUE(help.enabled());
const char* argv2[] = { "program.exe", "--help" };
po.reset();
po.parse(2, argv2);
EXPECT_TRUE(help.enabled());
const char* argv3[] = { "program.exe", "--input", "hello.cpp", "--output", "hello.exe" };
po.reset();
po.parse(5, argv3);
EXPECT_FALSE(help.enabled());
EXPECT_TRUE(input.enabled());
EXPECT_TRUE(output.enabled());
EXPECT_EQ("hello.cpp", input.value());
EXPECT_EQ("hello.exe", output.value());
const char* argv4[] = { "program.exe", "--input=hi.c", "--output=out.exe" };
po.reset();
po.parse(3, argv4);
EXPECT_FALSE(help.enabled());
EXPECT_TRUE(input.enabled());
EXPECT_TRUE(output.enabled());
EXPECT_EQ("hi.c", input.value());
EXPECT_EQ("out.exe", output.value());
const char* argv5[] = { "program.exe", "-?i", "input.md", "-o", "output.html", "extra-file.txt" };
po.reset();
po.parse(6, argv5);
EXPECT_TRUE(help.enabled());
EXPECT_TRUE(input.enabled());
EXPECT_TRUE(output.enabled());
EXPECT_EQ("input.md", input.value());
EXPECT_EQ("output.html", output.value());
ASSERT_EQ(1, po.values().size());
EXPECT_EQ("extra-file.txt", po.values()[0]);
const char* argv6[] = { "program.exe", "value1", "value2", "-o", "output", "value3", "--input=input", "value4" };
po.reset();
po.parse(8, argv6);
ASSERT_EQ(4, po.values().size());
EXPECT_EQ("value1", po.values()[0]);
EXPECT_EQ("value2", po.values()[1]);
EXPECT_EQ("value3", po.values()[2]);
EXPECT_EQ("value4", po.values()[3]);
}