Replace OwningPtr<T> with std::unique_ptr<T>.
[oota-llvm.git] / unittests / Option / OptionParsingTest.cpp
index 86286d11bd25ccc5dfe128fbfec6e34d10a5bd0c..6beb286cabfc23f1c95d5e9f9225885eb0833987 100644 (file)
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -20,7 +19,7 @@ using namespace llvm::opt;
 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
@@ -48,8 +47,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) {}
 };
 }
 
@@ -68,7 +67,8 @@ const char *Args[] = {
 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));
@@ -111,7 +111,7 @@ TEST(Option, OptionParsing) {
 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,
@@ -142,7 +142,8 @@ TEST(Option, ParseAliasInGroup) {
   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));
 }
 
@@ -151,18 +152,42 @@ TEST(Option, AliasArgs) {
   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);
@@ -173,7 +198,8 @@ TEST(Option, Slurp) {
   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));