CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
277 lines
9.0 KiB
C++
277 lines
9.0 KiB
C++
//===-- CompletionRequestTest.cpp -----------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "lldb/Utility/CompletionRequest.h"
|
|
using namespace lldb_private;
|
|
|
|
TEST(CompletionRequest, Constructor) {
|
|
std::string command = "a bad c";
|
|
const unsigned cursor_pos = 3;
|
|
const size_t arg_index = 1;
|
|
StringList matches;
|
|
CompletionResult result;
|
|
|
|
CompletionRequest request(command, cursor_pos, result);
|
|
result.GetMatches(matches);
|
|
|
|
EXPECT_EQ(request.GetRawLine(), "a b");
|
|
EXPECT_EQ(request.GetRawLineWithUnusedSuffix(), command);
|
|
EXPECT_EQ(request.GetRawCursorPos(), cursor_pos);
|
|
EXPECT_EQ(request.GetCursorIndex(), arg_index);
|
|
|
|
EXPECT_EQ(request.GetParsedLine().GetArgumentCount(), 2u);
|
|
EXPECT_EQ(request.GetCursorArgumentPrefix().str(), "b");
|
|
}
|
|
|
|
TEST(CompletionRequest, FakeLastArg) {
|
|
// We insert an empty fake argument into the argument list when the
|
|
// cursor is after a space.
|
|
std::string command = "a bad c ";
|
|
const unsigned cursor_pos = command.size();
|
|
CompletionResult result;
|
|
|
|
CompletionRequest request(command, cursor_pos, result);
|
|
|
|
EXPECT_EQ(request.GetRawLine(), command);
|
|
EXPECT_EQ(request.GetRawLineWithUnusedSuffix(), command);
|
|
EXPECT_EQ(request.GetRawCursorPos(), cursor_pos);
|
|
EXPECT_EQ(request.GetCursorIndex(), 3U);
|
|
|
|
EXPECT_EQ(request.GetParsedLine().GetArgumentCount(), 4U);
|
|
EXPECT_EQ(request.GetCursorArgumentPrefix().str(), "");
|
|
}
|
|
|
|
TEST(CompletionRequest, TryCompleteCurrentArgGood) {
|
|
std::string command = "a bad c";
|
|
StringList matches, descriptions;
|
|
CompletionResult result;
|
|
|
|
CompletionRequest request(command, 3, result);
|
|
request.TryCompleteCurrentArg("boo", "car");
|
|
result.GetMatches(matches);
|
|
result.GetDescriptions(descriptions);
|
|
|
|
EXPECT_EQ(1U, result.GetResults().size());
|
|
EXPECT_STREQ("boo", matches.GetStringAtIndex(0U));
|
|
EXPECT_EQ(1U, descriptions.GetSize());
|
|
EXPECT_STREQ("car", descriptions.GetStringAtIndex(0U));
|
|
}
|
|
|
|
TEST(CompletionRequest, TryCompleteCurrentArgBad) {
|
|
std::string command = "a bad c";
|
|
CompletionResult result;
|
|
|
|
CompletionRequest request(command, 3, result);
|
|
request.TryCompleteCurrentArg("car", "card");
|
|
|
|
EXPECT_EQ(0U, result.GetResults().size());
|
|
}
|
|
|
|
TEST(CompletionRequest, TryCompleteCurrentArgMode) {
|
|
std::string command = "a bad c";
|
|
CompletionResult result;
|
|
|
|
CompletionRequest request(command, 3, result);
|
|
request.TryCompleteCurrentArg<CompletionMode::Partial>("bar", "bard");
|
|
|
|
EXPECT_EQ(1U, result.GetResults().size());
|
|
EXPECT_EQ(CompletionMode::Partial, result.GetResults()[0].GetMode());
|
|
}
|
|
|
|
TEST(CompletionRequest, ShiftArguments) {
|
|
std::string command = "a bad c";
|
|
const unsigned cursor_pos = 3;
|
|
const size_t arg_index = 1;
|
|
StringList matches;
|
|
CompletionResult result;
|
|
|
|
CompletionRequest request(command, cursor_pos, result);
|
|
result.GetMatches(matches);
|
|
|
|
EXPECT_EQ(request.GetRawLine(), "a b");
|
|
EXPECT_EQ(request.GetRawLineWithUnusedSuffix(), command);
|
|
EXPECT_EQ(request.GetRawCursorPos(), cursor_pos);
|
|
EXPECT_EQ(request.GetCursorIndex(), arg_index);
|
|
|
|
EXPECT_EQ(request.GetParsedLine().GetArgumentCount(), 2u);
|
|
EXPECT_STREQ(request.GetParsedLine().GetArgumentAtIndex(1), "b");
|
|
|
|
// Shift away the 'a' argument.
|
|
request.ShiftArguments();
|
|
|
|
// The raw line/cursor stays identical.
|
|
EXPECT_EQ(request.GetRawLine(), "a b");
|
|
EXPECT_EQ(request.GetRawLineWithUnusedSuffix(), command);
|
|
EXPECT_EQ(request.GetRawCursorPos(), cursor_pos);
|
|
|
|
// Partially parsed line and cursor should be updated.
|
|
EXPECT_EQ(request.GetCursorIndex(), arg_index - 1U);
|
|
EXPECT_EQ(request.GetParsedLine().GetArgumentCount(), 1u);
|
|
EXPECT_EQ(request.GetCursorArgumentPrefix().str(), "b");
|
|
}
|
|
|
|
TEST(CompletionRequest, DuplicateFiltering) {
|
|
std::string command = "a bad c";
|
|
const unsigned cursor_pos = 3;
|
|
StringList matches;
|
|
|
|
CompletionResult result;
|
|
CompletionRequest request(command, cursor_pos, result);
|
|
result.GetMatches(matches);
|
|
|
|
EXPECT_EQ(0U, result.GetNumberOfResults());
|
|
|
|
// Add foo twice
|
|
request.AddCompletion("foo");
|
|
result.GetMatches(matches);
|
|
|
|
EXPECT_EQ(1U, result.GetNumberOfResults());
|
|
EXPECT_EQ(1U, matches.GetSize());
|
|
EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
|
|
|
|
request.AddCompletion("foo");
|
|
result.GetMatches(matches);
|
|
|
|
EXPECT_EQ(1U, result.GetNumberOfResults());
|
|
EXPECT_EQ(1U, matches.GetSize());
|
|
EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
|
|
|
|
// Add bar twice
|
|
request.AddCompletion("bar");
|
|
result.GetMatches(matches);
|
|
|
|
EXPECT_EQ(2U, result.GetNumberOfResults());
|
|
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, result.GetNumberOfResults());
|
|
EXPECT_EQ(2U, matches.GetSize());
|
|
EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
|
|
EXPECT_STREQ("bar", matches.GetStringAtIndex(1));
|
|
|
|
// Add foo again.
|
|
request.AddCompletion("foo");
|
|
result.GetMatches(matches);
|
|
|
|
EXPECT_EQ(2U, result.GetNumberOfResults());
|
|
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");
|
|
result.GetMatches(matches);
|
|
|
|
EXPECT_EQ(3U, result.GetNumberOfResults());
|
|
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, DuplicateFilteringWithComments) {
|
|
std::string command = "a bad c";
|
|
const unsigned cursor_pos = 3;
|
|
StringList matches, descriptions;
|
|
|
|
CompletionResult result;
|
|
CompletionRequest request(command, cursor_pos, result);
|
|
result.GetMatches(matches);
|
|
result.GetDescriptions(descriptions);
|
|
|
|
EXPECT_EQ(0U, result.GetNumberOfResults());
|
|
|
|
// Add foo twice with same comment
|
|
request.AddCompletion("foo", "comment");
|
|
result.GetMatches(matches);
|
|
result.GetDescriptions(descriptions);
|
|
|
|
EXPECT_EQ(1U, result.GetNumberOfResults());
|
|
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, result.GetNumberOfResults());
|
|
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, result.GetNumberOfResults());
|
|
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, result.GetNumberOfResults());
|
|
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, result.GetNumberOfResults());
|
|
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;
|
|
|
|
CompletionResult result;
|
|
CompletionRequest request(command, cursor_pos, result);
|
|
|
|
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';
|
|
|
|
result.GetMatches(matches);
|
|
EXPECT_EQ(1U, result.GetNumberOfResults());
|
|
EXPECT_STREQ("bar", matches.GetStringAtIndex(0));
|
|
}
|