summaryrefslogtreecommitdiff
path: root/unittests/Utility/CompletionRequestTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/Utility/CompletionRequestTest.cpp')
-rw-r--r--unittests/Utility/CompletionRequestTest.cpp100
1 files changed, 97 insertions, 3 deletions
diff --git a/unittests/Utility/CompletionRequestTest.cpp b/unittests/Utility/CompletionRequestTest.cpp
index 58dfab0da508..bdf3c4d056fb 100644
--- a/unittests/Utility/CompletionRequestTest.cpp
+++ b/unittests/Utility/CompletionRequestTest.cpp
@@ -20,9 +20,11 @@ TEST(CompletionRequest, Constructor) {
const int match_start = 2345;
const int match_max_return = 12345;
StringList matches;
+ CompletionResult result;
CompletionRequest request(command, cursor_pos, match_start, match_max_return,
- matches);
+ result);
+ result.GetMatches(matches);
EXPECT_STREQ(request.GetRawLine().str().c_str(), command.c_str());
EXPECT_EQ(request.GetRawCursorPos(), cursor_pos);
@@ -41,29 +43,39 @@ TEST(CompletionRequest, DuplicateFiltering) {
const unsigned cursor_pos = 3;
StringList matches;
- CompletionRequest request(command, cursor_pos, 0, 0, matches);
+ CompletionResult result;
+ CompletionRequest request(command, cursor_pos, 0, 0, result);
+ result.GetMatches(matches);
EXPECT_EQ(0U, request.GetNumberOfMatches());
// Add foo twice
request.AddCompletion("foo");
+ result.GetMatches(matches);
+
EXPECT_EQ(1U, request.GetNumberOfMatches());
EXPECT_EQ(1U, matches.GetSize());
EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
request.AddCompletion("foo");
+ result.GetMatches(matches);
+
EXPECT_EQ(1U, request.GetNumberOfMatches());
EXPECT_EQ(1U, matches.GetSize());
EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
// Add bar twice
request.AddCompletion("bar");
+ result.GetMatches(matches);
+
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");
+ result.GetMatches(matches);
+
EXPECT_EQ(2U, request.GetNumberOfMatches());
EXPECT_EQ(2U, matches.GetSize());
EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
@@ -71,6 +83,8 @@ TEST(CompletionRequest, DuplicateFiltering) {
// Add foo again.
request.AddCompletion("foo");
+ result.GetMatches(matches);
+
EXPECT_EQ(2U, request.GetNumberOfMatches());
EXPECT_EQ(2U, matches.GetSize());
EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
@@ -78,6 +92,8 @@ TEST(CompletionRequest, DuplicateFiltering) {
// Add something with an existing prefix
request.AddCompletion("foobar");
+ result.GetMatches(matches);
+
EXPECT_EQ(3U, request.GetNumberOfMatches());
EXPECT_EQ(3U, matches.GetSize());
EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
@@ -85,12 +101,89 @@ TEST(CompletionRequest, DuplicateFiltering) {
EXPECT_STREQ("foobar", matches.GetStringAtIndex(2));
}
+TEST(CompletionRequest, DuplicateFilteringWithComments) {
+ std::string command = "a bad c";
+ const unsigned cursor_pos = 3;
+ StringList matches, descriptions;
+
+ CompletionResult result;
+ CompletionRequest request(command, cursor_pos, 0, 0, result);
+ result.GetMatches(matches);
+ result.GetDescriptions(descriptions);
+
+ EXPECT_EQ(0U, request.GetNumberOfMatches());
+
+ // Add foo twice with same comment
+ request.AddCompletion("foo", "comment");
+ result.GetMatches(matches);
+ result.GetDescriptions(descriptions);
+
+ EXPECT_EQ(1U, request.GetNumberOfMatches());
+ EXPECT_EQ(1U, matches.GetSize());
+ EXPECT_EQ(1U, descriptions.GetSize());
+ EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
+ EXPECT_STREQ("comment", descriptions.GetStringAtIndex(0));
+
+ request.AddCompletion("foo", "comment");
+ result.GetMatches(matches);
+ result.GetDescriptions(descriptions);
+
+ EXPECT_EQ(1U, request.GetNumberOfMatches());
+ EXPECT_EQ(1U, matches.GetSize());
+ EXPECT_EQ(1U, descriptions.GetSize());
+ EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
+ EXPECT_STREQ("comment", descriptions.GetStringAtIndex(0));
+
+ // Add bar twice with different comments
+ request.AddCompletion("bar", "comment");
+ result.GetMatches(matches);
+ result.GetDescriptions(descriptions);
+
+ EXPECT_EQ(2U, request.GetNumberOfMatches());
+ EXPECT_EQ(2U, matches.GetSize());
+ EXPECT_EQ(2U, descriptions.GetSize());
+ EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
+ EXPECT_STREQ("bar", matches.GetStringAtIndex(1));
+
+ request.AddCompletion("bar", "another comment");
+ result.GetMatches(matches);
+ result.GetDescriptions(descriptions);
+
+ EXPECT_EQ(3U, request.GetNumberOfMatches());
+ EXPECT_EQ(3U, matches.GetSize());
+ EXPECT_EQ(3U, descriptions.GetSize());
+ EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
+ EXPECT_STREQ("comment", descriptions.GetStringAtIndex(0));
+ EXPECT_STREQ("bar", matches.GetStringAtIndex(1));
+ EXPECT_STREQ("comment", descriptions.GetStringAtIndex(1));
+ EXPECT_STREQ("bar", matches.GetStringAtIndex(2));
+ EXPECT_STREQ("another comment", descriptions.GetStringAtIndex(2));
+
+ // Add foo again with no comment
+ request.AddCompletion("foo");
+ result.GetMatches(matches);
+ result.GetDescriptions(descriptions);
+
+ EXPECT_EQ(4U, request.GetNumberOfMatches());
+ EXPECT_EQ(4U, matches.GetSize());
+ EXPECT_EQ(4U, descriptions.GetSize());
+ EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
+ EXPECT_STREQ("comment", descriptions.GetStringAtIndex(0));
+ EXPECT_STREQ("bar", matches.GetStringAtIndex(1));
+ EXPECT_STREQ("comment", descriptions.GetStringAtIndex(1));
+ EXPECT_STREQ("bar", matches.GetStringAtIndex(2));
+ EXPECT_STREQ("another comment", descriptions.GetStringAtIndex(2));
+ EXPECT_STREQ("foo", matches.GetStringAtIndex(3));
+ EXPECT_STREQ("", descriptions.GetStringAtIndex(3));
+}
+
TEST(CompletionRequest, TestCompletionOwnership) {
std::string command = "a bad c";
const unsigned cursor_pos = 3;
StringList matches;
- CompletionRequest request(command, cursor_pos, 0, 0, matches);
+ CompletionResult result;
+ CompletionRequest request(command, cursor_pos, 0, 0, result);
std::string Temporary = "bar";
request.AddCompletion(Temporary);
@@ -98,6 +191,7 @@ TEST(CompletionRequest, TestCompletionOwnership) {
// shouldn't influence anything.
Temporary[0] = 'f';
+ result.GetMatches(matches);
EXPECT_EQ(1U, request.GetNumberOfMatches());
EXPECT_STREQ("bar", matches.GetStringAtIndex(0));
}