summaryrefslogtreecommitdiff
path: root/unittests/Utility/CompletionRequestTest.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-08-02 17:33:54 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-08-02 17:33:54 +0000
commit39be7ce23363d12ae3e49aeb1fdb2bfeb892e836 (patch)
tree37fd694b2fe544b0ccefb369794632592d138dde /unittests/Utility/CompletionRequestTest.cpp
parentf73363f1dd94996356cefbf24388f561891acf0b (diff)
Notes
Diffstat (limited to 'unittests/Utility/CompletionRequestTest.cpp')
-rw-r--r--unittests/Utility/CompletionRequestTest.cpp67
1 files changed, 65 insertions, 2 deletions
diff --git a/unittests/Utility/CompletionRequestTest.cpp b/unittests/Utility/CompletionRequestTest.cpp
index 134bf517f854e..58dfab0da508a 100644
--- a/unittests/Utility/CompletionRequestTest.cpp
+++ b/unittests/Utility/CompletionRequestTest.cpp
@@ -34,7 +34,70 @@ TEST(CompletionRequest, Constructor) {
EXPECT_EQ(request.GetPartialParsedLine().GetArgumentCount(), 2u);
EXPECT_STREQ(request.GetPartialParsedLine().GetArgumentAtIndex(1), "b");
+}
+
+TEST(CompletionRequest, DuplicateFiltering) {
+ std::string command = "a bad c";
+ const unsigned cursor_pos = 3;
+ StringList matches;
+
+ CompletionRequest request(command, cursor_pos, 0, 0, matches);
+
+ EXPECT_EQ(0U, request.GetNumberOfMatches());
+
+ // Add foo twice
+ request.AddCompletion("foo");
+ EXPECT_EQ(1U, request.GetNumberOfMatches());
+ EXPECT_EQ(1U, matches.GetSize());
+ EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
+
+ request.AddCompletion("foo");
+ EXPECT_EQ(1U, request.GetNumberOfMatches());
+ EXPECT_EQ(1U, matches.GetSize());
+ EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
+
+ // Add bar twice
+ request.AddCompletion("bar");
+ EXPECT_EQ(2U, request.GetNumberOfMatches());
+ EXPECT_EQ(2U, matches.GetSize());
+ EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
+ EXPECT_STREQ("bar", matches.GetStringAtIndex(1));
+
+ request.AddCompletion("bar");
+ EXPECT_EQ(2U, request.GetNumberOfMatches());
+ EXPECT_EQ(2U, matches.GetSize());
+ EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
+ EXPECT_STREQ("bar", matches.GetStringAtIndex(1));
+
+ // Add foo again.
+ request.AddCompletion("foo");
+ EXPECT_EQ(2U, request.GetNumberOfMatches());
+ EXPECT_EQ(2U, matches.GetSize());
+ EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
+ EXPECT_STREQ("bar", matches.GetStringAtIndex(1));
+
+ // Add something with an existing prefix
+ request.AddCompletion("foobar");
+ EXPECT_EQ(3U, request.GetNumberOfMatches());
+ EXPECT_EQ(3U, matches.GetSize());
+ EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
+ EXPECT_STREQ("bar", matches.GetStringAtIndex(1));
+ EXPECT_STREQ("foobar", matches.GetStringAtIndex(2));
+}
+
+TEST(CompletionRequest, TestCompletionOwnership) {
+ std::string command = "a bad c";
+ const unsigned cursor_pos = 3;
+ StringList matches;
+
+ CompletionRequest request(command, cursor_pos, 0, 0, matches);
+
+ std::string Temporary = "bar";
+ request.AddCompletion(Temporary);
+ // Manipulate our completion. The request should have taken a copy, so that
+ // shouldn't influence anything.
+ Temporary[0] = 'f';
- // This is the generated matches should be equal to our passed string list.
- EXPECT_EQ(&request.GetMatches(), &matches);
+ EXPECT_EQ(1U, request.GetNumberOfMatches());
+ EXPECT_STREQ("bar", matches.GetStringAtIndex(0));
}