Files
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
clang-tools-extra
change-namespace
clang-apply-replacements
clang-move
clang-query
clang-reorder-fields
clang-tidy
clang-tidy-vs
clangd
docs
include-fixer
modularize
pp-trace
test
tool-template
unittests
change-namespace
clang-apply-replacements
clang-move
clang-query
clang-tidy
clangd
Annotations.cpp
Annotations.h
CMakeLists.txt
ClangdTests.cpp
CodeCompleteTests.cpp
CodeCompletionStringsTests.cpp
ContextTests.cpp
FileIndexTests.cpp
FuzzyMatchTests.cpp
IndexTests.cpp
JSONExprTests.cpp
Matchers.h
SourceCodeTests.cpp
SymbolCollectorTests.cpp
TestFS.cpp
TestFS.h
TraceTests.cpp
XRefsTests.cpp
include
include-fixer
CMakeLists.txt
.arcconfig
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
LICENSE.TXT
README.txt
compiler-rt
eng
libcxx
libcxxabi
libunwind
lld
lldb
llvm
nuget
openmp
polly
Directory.Build.props
Directory.Build.targets
NuGet.config
azure-pipelines.yml
build.cmd
build.sh
dir.common.props
global.json
llvm.proj
mxe-Win64.cmake.in
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
linux-packaging-mono/external/llvm-project/clang-tools-extra/unittests/clangd/CodeCompletionStringsTests.cpp

143 lines
4.5 KiB
C++
Raw Normal View History

//===-- CodeCompletionStringsTests.cpp --------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "CodeCompletionStrings.h"
#include "clang/Sema/CodeCompleteConsumer.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
namespace clang {
namespace clangd {
namespace {
class CompletionStringTest : public ::testing::Test {
public:
CompletionStringTest()
: Allocator(std::make_shared<clang::GlobalCodeCompletionAllocator>()),
CCTUInfo(Allocator), Builder(*Allocator, CCTUInfo) {}
protected:
void labelAndInsertText(const CodeCompletionString &CCS,
bool EnableSnippets = false) {
Label.clear();
InsertText.clear();
getLabelAndInsertText(CCS, &Label, &InsertText, EnableSnippets);
}
std::shared_ptr<clang::GlobalCodeCompletionAllocator> Allocator;
CodeCompletionTUInfo CCTUInfo;
CodeCompletionBuilder Builder;
std::string Label;
std::string InsertText;
};
TEST_F(CompletionStringTest, Detail) {
Builder.AddResultTypeChunk("result");
Builder.AddResultTypeChunk("redundant result no no");
EXPECT_EQ(getDetail(*Builder.TakeString()), "result");
}
TEST_F(CompletionStringTest, FilterText) {
Builder.AddTypedTextChunk("typed");
Builder.AddTypedTextChunk("redundant typed no no");
auto *S = Builder.TakeString();
EXPECT_EQ(getFilterText(*S), "typed");
}
TEST_F(CompletionStringTest, Documentation) {
Builder.addBriefComment("Is this brief?");
EXPECT_EQ(getDocumentation(*Builder.TakeString()), "Is this brief?");
}
TEST_F(CompletionStringTest, DocumentationWithAnnotation) {
Builder.addBriefComment("Is this brief?");
Builder.AddAnnotation("Ano");
EXPECT_EQ(getDocumentation(*Builder.TakeString()),
"Annotation: Ano\n\nIs this brief?");
}
TEST_F(CompletionStringTest, MultipleAnnotations) {
Builder.AddAnnotation("Ano1");
Builder.AddAnnotation("Ano2");
Builder.AddAnnotation("Ano3");
EXPECT_EQ(getDocumentation(*Builder.TakeString()),
"Annotations: Ano1 Ano2 Ano3\n");
}
TEST_F(CompletionStringTest, SimpleLabelAndInsert) {
Builder.AddTypedTextChunk("X");
Builder.AddResultTypeChunk("result no no");
labelAndInsertText(*Builder.TakeString());
EXPECT_EQ(Label, "X");
EXPECT_EQ(InsertText, "X");
}
TEST_F(CompletionStringTest, FunctionPlainText) {
Builder.AddResultTypeChunk("result no no");
Builder.AddTypedTextChunk("Foo");
Builder.AddChunk(CodeCompletionString::CK_LeftParen);
Builder.AddPlaceholderChunk("p1");
Builder.AddChunk(CodeCompletionString::CK_Comma);
Builder.AddPlaceholderChunk("p2");
Builder.AddChunk(CodeCompletionString::CK_RightParen);
Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddInformativeChunk("const");
labelAndInsertText(*Builder.TakeString());
EXPECT_EQ(Label, "Foo(p1, p2) const");
EXPECT_EQ(InsertText, "Foo");
}
TEST_F(CompletionStringTest, FunctionSnippet) {
Builder.AddResultTypeChunk("result no no");
Builder.addBriefComment("Foo's comment");
Builder.AddTypedTextChunk("Foo");
Builder.AddChunk(CodeCompletionString::CK_LeftParen);
Builder.AddPlaceholderChunk("p1");
Builder.AddChunk(CodeCompletionString::CK_Comma);
Builder.AddPlaceholderChunk("p2");
Builder.AddChunk(CodeCompletionString::CK_RightParen);
auto *CCS = Builder.TakeString();
labelAndInsertText(*CCS);
EXPECT_EQ(Label, "Foo(p1, p2)");
EXPECT_EQ(InsertText, "Foo");
labelAndInsertText(*CCS, /*EnableSnippets=*/true);
EXPECT_EQ(Label, "Foo(p1, p2)");
EXPECT_EQ(InsertText, "Foo(${1:p1}, ${2:p2})");
EXPECT_EQ(getDocumentation(*CCS), "Foo's comment");
EXPECT_EQ(getFilterText(*CCS), "Foo");
}
TEST_F(CompletionStringTest, EscapeSnippet) {
Builder.AddTypedTextChunk("Foo");
Builder.AddChunk(CodeCompletionString::CK_LeftParen);
Builder.AddPlaceholderChunk("$p}1\\");
Builder.AddChunk(CodeCompletionString::CK_RightParen);
labelAndInsertText(*Builder.TakeString(), /*EnableSnippets=*/true);
EXPECT_EQ(Label, "Foo($p}1\\)");
EXPECT_EQ(InsertText, "Foo(${1:\\$p\\}1\\\\})");
}
TEST_F(CompletionStringTest, IgnoreInformativeQualifier) {
Builder.AddTypedTextChunk("X");
Builder.AddInformativeChunk("info ok");
Builder.AddInformativeChunk("info no no::");
labelAndInsertText(*Builder.TakeString());
EXPECT_EQ(Label, "Xinfo ok");
EXPECT_EQ(InsertText, "X");
}
} // namespace
} // namespace clangd
} // namespace clang