X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=unittests%2FOption%2FOptionParsingTest.cpp;h=11d6d1e87ebb0e0382382fc05abb597c17394d54;hb=ccbfd5b18a79a07229f11af478843eae16ac9b26;hp=101568a567ee65a836855a1dae1f495a3f6f64e6;hpb=9dd8c0cffe7de82900823c05159bba765120f1e3;p=oota-llvm.git diff --git a/unittests/Option/OptionParsingTest.cpp b/unittests/Option/OptionParsingTest.cpp index 101568a567e..11d6d1e87eb 100644 --- a/unittests/Option/OptionParsingTest.cpp +++ b/unittests/Option/OptionParsingTest.cpp @@ -17,12 +17,10 @@ using namespace llvm; using namespace llvm::opt; -#define SUPPORT_ALIASARGS // FIXME: Remove when no longer necessary. - enum ID { OPT_INVALID = 0, // This is not an option ID. #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ - HELPTEXT, METAVAR) OPT_##ID, + HELPTEXT, METAVAR) OPT_##ID, #include "Opts.inc" LastOption #undef OPTION @@ -50,8 +48,8 @@ static const OptTable::Info InfoTable[] = { namespace { class TestOptTable : public OptTable { public: - TestOptTable() - : OptTable(InfoTable, array_lengthof(InfoTable)) {} + TestOptTable(bool IgnoreCase = false) + : OptTable(InfoTable, array_lengthof(InfoTable), IgnoreCase) {} }; } @@ -158,3 +156,50 @@ TEST(Option, AliasArgs) { EXPECT_EQ(AL->getAllArgValues(OPT_B)[0], "foo"); EXPECT_EQ(AL->getAllArgValues(OPT_B)[1], "bar"); } + +TEST(Option, IgnoreCase) { + TestOptTable T(true); + unsigned MAI, MAC; + + const char *MyArgs[] = { "-a", "-joo" }; + OwningPtr AL(T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC)); + EXPECT_TRUE(AL->hasArg(OPT_A)); + EXPECT_TRUE(AL->hasArg(OPT_B)); +} + +TEST(Option, DoNotIgnoreCase) { + TestOptTable T; + unsigned MAI, MAC; + + const char *MyArgs[] = { "-a", "-joo" }; + OwningPtr AL(T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC)); + EXPECT_FALSE(AL->hasArg(OPT_A)); + EXPECT_FALSE(AL->hasArg(OPT_B)); +} + +TEST(Option, SlurpEmpty) { + TestOptTable T; + unsigned MAI, MAC; + + const char *MyArgs[] = { "-A", "-slurp" }; + OwningPtr AL(T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC)); + EXPECT_TRUE(AL->hasArg(OPT_A)); + EXPECT_TRUE(AL->hasArg(OPT_Slurp)); + EXPECT_EQ(AL->getAllArgValues(OPT_Slurp).size(), 0U); +} + +TEST(Option, Slurp) { + TestOptTable T; + unsigned MAI, MAC; + + const char *MyArgs[] = { "-A", "-slurp", "-B", "--", "foo" }; + OwningPtr AL(T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC)); + EXPECT_EQ(AL->size(), 2U); + EXPECT_TRUE(AL->hasArg(OPT_A)); + EXPECT_FALSE(AL->hasArg(OPT_B)); + EXPECT_TRUE(AL->hasArg(OPT_Slurp)); + EXPECT_EQ(AL->getAllArgValues(OPT_Slurp).size(), 3U); + EXPECT_EQ(AL->getAllArgValues(OPT_Slurp)[0], "-B"); + EXPECT_EQ(AL->getAllArgValues(OPT_Slurp)[1], "--"); + EXPECT_EQ(AL->getAllArgValues(OPT_Slurp)[2], "foo"); +}