//
//===----------------------------------------------------------------------===//
-#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
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
namespace {
class TestOptTable : public OptTable {
public:
- TestOptTable()
- : OptTable(InfoTable, array_lengthof(InfoTable)) {}
+ TestOptTable(bool IgnoreCase = false)
+ : OptTable(InfoTable, array_lengthof(InfoTable), IgnoreCase) {}
};
}
TEST(Option, OptionParsing) {
TestOptTable T;
unsigned MAI, MAC;
- OwningPtr<InputArgList> AL(T.ParseArgs(Args, array_endof(Args), MAI, MAC));
+ std::unique_ptr<InputArgList> AL(
+ T.ParseArgs(Args, array_endof(Args), MAI, MAC));
// Check they all exist.
EXPECT_TRUE(AL->hasArg(OPT_A));
TEST(Option, ParseWithFlagExclusions) {
TestOptTable T;
unsigned MAI, MAC;
- OwningPtr<InputArgList> AL;
+ std::unique_ptr<InputArgList> AL;
// Exclude flag3 to avoid parsing as OPT_SLASH_C.
AL.reset(T.ParseArgs(Args, array_endof(Args), MAI, MAC,
unsigned MAI, MAC;
const char *MyArgs[] = { "-I" };
- OwningPtr<InputArgList> AL(T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
+ std::unique_ptr<InputArgList> AL(
+ T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
EXPECT_TRUE(AL->hasArg(OPT_H));
}
unsigned MAI, MAC;
const char *MyArgs[] = { "-J", "-Joo" };
- OwningPtr<InputArgList> AL(T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
+ std::unique_ptr<InputArgList> AL(
+ T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
EXPECT_TRUE(AL->hasArg(OPT_B));
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" };
+ std::unique_ptr<InputArgList> 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" };
+ std::unique_ptr<InputArgList> 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<InputArgList> AL(T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
+ std::unique_ptr<InputArgList> 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);
unsigned MAI, MAC;
const char *MyArgs[] = { "-A", "-slurp", "-B", "--", "foo" };
- OwningPtr<InputArgList> AL(T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
+ std::unique_ptr<InputArgList> 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));