[Lldb-commits] [lldb] r371180 - [lldb][NFC] Extend ArgsTest

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 6 01:39:53 PDT 2019


Author: teemperor
Date: Fri Sep  6 01:39:53 2019
New Revision: 371180

URL: http://llvm.org/viewvc/llvm-project?rev=371180&view=rev
Log:
[lldb][NFC] Extend ArgsTest

Modified:
    lldb/trunk/unittests/Utility/ArgsTest.cpp

Modified: lldb/trunk/unittests/Utility/ArgsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/ArgsTest.cpp?rev=371180&r1=371179&r2=371180&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/ArgsTest.cpp (original)
+++ lldb/trunk/unittests/Utility/ArgsTest.cpp Fri Sep  6 01:39:53 2019
@@ -37,6 +37,34 @@ TEST(ArgsTest, TestSingleArgWithQuotedSp
   EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg with space");
 }
 
+TEST(ArgsTest, TestTrailingBackslash) {
+  Args args;
+  args.SetCommandString("arg\\");
+  EXPECT_EQ(1u, args.GetArgumentCount());
+  EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg\\");
+}
+
+TEST(ArgsTest, TestQuotedTrailingBackslash) {
+  Args args;
+  args.SetCommandString("\"arg\\");
+  EXPECT_EQ(1u, args.GetArgumentCount());
+  EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg\\");
+}
+
+TEST(ArgsTest, TestUnknownEscape) {
+  Args args;
+  args.SetCommandString("arg\\y");
+  EXPECT_EQ(1u, args.GetArgumentCount());
+  EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg\\y");
+}
+
+TEST(ArgsTest, TestQuotedUnknownEscape) {
+  Args args;
+  args.SetCommandString("\"arg\\y");
+  EXPECT_EQ(1u, args.GetArgumentCount());
+  EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg\\y");
+}
+
 TEST(ArgsTest, TestMultipleArgs) {
   Args args;
   args.SetCommandString("this has multiple args");
@@ -214,3 +242,43 @@ TEST(ArgsTest, EscapeLLDBCommandArgument
   EXPECT_EQ("quux\t", Args::EscapeLLDBCommandArgument(quux, '`'));
   EXPECT_EQ("quux\t", Args::EscapeLLDBCommandArgument(quux, '"'));
 }
+
+TEST(ArgsTest, ReplaceArgumentAtIndexShort) {
+  Args args;
+  args.SetCommandString("foo ba b");
+  args.ReplaceArgumentAtIndex(0, "f");
+  EXPECT_EQ(3u, args.GetArgumentCount());
+  EXPECT_STREQ(args.GetArgumentAtIndex(0), "f");
+}
+
+TEST(ArgsTest, ReplaceArgumentAtIndexEqual) {
+  Args args;
+  args.SetCommandString("foo ba b");
+  args.ReplaceArgumentAtIndex(0, "bar");
+  EXPECT_EQ(3u, args.GetArgumentCount());
+  EXPECT_STREQ(args.GetArgumentAtIndex(0), "bar");
+}
+
+TEST(ArgsTest, ReplaceArgumentAtIndexLonger) {
+  Args args;
+  args.SetCommandString("foo ba b");
+  args.ReplaceArgumentAtIndex(0, "baar");
+  EXPECT_EQ(3u, args.GetArgumentCount());
+  EXPECT_STREQ(args.GetArgumentAtIndex(0), "baar");
+}
+
+TEST(ArgsTest, ReplaceArgumentAtIndexOutOfRange) {
+  Args args;
+  args.SetCommandString("foo ba b");
+  args.ReplaceArgumentAtIndex(3, "baar");
+  EXPECT_EQ(3u, args.GetArgumentCount());
+  EXPECT_STREQ(args.GetArgumentAtIndex(2), "b");
+}
+
+TEST(ArgsTest, ReplaceArgumentAtIndexFarOutOfRange) {
+  Args args;
+  args.SetCommandString("foo ba b");
+  args.ReplaceArgumentAtIndex(4, "baar");
+  EXPECT_EQ(3u, args.GetArgumentCount());
+  EXPECT_STREQ(args.GetArgumentAtIndex(2), "b");
+}




More information about the lldb-commits mailing list