[clangd] Cleanup of readability-identifier-naming

Auto-generated patch based on clang-tidy readability-identifier-naming.
Only some manual cleanup for `extern "C"` declarations and a GTest change was required.

I'm not sure if this cleanup is actually very useful. It cleans up clang-tidy findings to the number of warnings from clang-tidy should be lower.  Since it was easy to do and required only little cleanup I thought I'd upload it for discussion.

One pattern that keeps recurring: Test **matchers** are also supposed to start with a lowercase letter as per LLVM convention. However GTest naming convention for matchers start with upper case. I would propose to keep stay consistent with the GTest convention there. However that would imply a lot of `//NOLINT` throughout these files.

To re-product this patch run:
```
run-clang-tidy -checks="-*,readability-identifier-naming" -fix -format ./clang-tools-extra/clangd
```

To convert the macro names, I was using this script with some manual cleanup afterwards:
https://gist.github.com/ChristianKuehnel/a01cc4362b07c58281554ab46235a077

Differential Revision: https://reviews.llvm.org/D115634
This commit is contained in:
Christian Kühnel 2022-02-01 10:14:07 +00:00
parent fa7834a554
commit 8edfc2f814
40 changed files with 1595 additions and 1586 deletions

View File

@ -6,6 +6,10 @@ CheckOptions:
value: CamelCase
- key: readability-identifier-naming.FunctionCase
value: camelBack
# Exclude from scanning as this is an exported symbol used for fuzzing
# throughout the code base.
- key: readability-identifier-naming.FunctionIgnoredRegexp
value: "LLVMFuzzerTestOneInput"
- key: readability-identifier-naming.MemberCase
value: CamelCase
- key: readability-identifier-naming.ParameterCase

View File

@ -71,8 +71,8 @@ llvm::Optional<int64_t> decodeVersion(llvm::StringRef Encoded) {
return llvm::None;
}
const llvm::StringLiteral APPLY_FIX_COMMAND = "clangd.applyFix";
const llvm::StringLiteral APPLY_TWEAK_COMMAND = "clangd.applyTweak";
const llvm::StringLiteral ApplyFixCommand = "clangd.applyFix";
const llvm::StringLiteral ApplyTweakCommand = "clangd.applyTweak";
/// Transforms a tweak into a code action that would apply it if executed.
/// EXPECTS: T.prepare() was called and returned true.
@ -88,7 +88,7 @@ CodeAction toCodeAction(const ClangdServer::TweakRef &T, const URIForFile &File,
// directly.
CA.command.emplace();
CA.command->title = T.Title;
CA.command->command = std::string(APPLY_TWEAK_COMMAND);
CA.command->command = std::string(ApplyTweakCommand);
TweakArgs Args;
Args.file = File;
Args.tweakID = T.ID;
@ -950,7 +950,7 @@ static llvm::Optional<Command> asCommand(const CodeAction &Action) {
if (Action.command) {
Cmd = *Action.command;
} else if (Action.edit) {
Cmd.command = std::string(APPLY_FIX_COMMAND);
Cmd.command = std::string(ApplyFixCommand);
Cmd.argument = *Action.edit;
} else {
return None;
@ -1495,8 +1495,8 @@ void ClangdLSPServer::bindMethods(LSPBinder &Bind,
Bind.method("$/memoryUsage", this, &ClangdLSPServer::onMemoryUsage);
if (Opts.FoldingRanges)
Bind.method("textDocument/foldingRange", this, &ClangdLSPServer::onFoldingRange);
Bind.command(APPLY_FIX_COMMAND, this, &ClangdLSPServer::onCommandApplyEdit);
Bind.command(APPLY_TWEAK_COMMAND, this, &ClangdLSPServer::onCommandApplyTweak);
Bind.command(ApplyFixCommand, this, &ClangdLSPServer::onCommandApplyEdit);
Bind.command(ApplyTweakCommand, this, &ClangdLSPServer::onCommandApplyTweak);
ApplyWorkspaceEdit = Bind.outgoingMethod("workspace/applyEdit");
PublishDiagnostics = Bind.outgoingNotification("textDocument/publishDiagnostics");

View File

@ -1177,10 +1177,10 @@ bool isProtoFile(SourceLocation Loc, const SourceManager &SM) {
return false;
auto FID = SM.getFileID(Loc);
// All proto generated headers should start with this line.
static const char *PROTO_HEADER_COMMENT =
static const char *ProtoHeaderComment =
"// Generated by the protocol buffer compiler. DO NOT EDIT!";
// Double check that this is an actual protobuf header.
return SM.getBufferData(FID).startswith(PROTO_HEADER_COMMENT);
return SM.getBufferData(FID).startswith(ProtoHeaderComment);
}
namespace {

View File

@ -100,10 +100,10 @@ namespace {
class ASTWorker;
} // namespace
static clang::clangd::Key<std::string> kFileBeingProcessed;
static clang::clangd::Key<std::string> FileBeingProcessed;
llvm::Optional<llvm::StringRef> TUScheduler::getFileBeingProcessedInContext() {
if (auto *File = Context::current().get(kFileBeingProcessed))
if (auto *File = Context::current().get(FileBeingProcessed))
return llvm::StringRef(*File);
return None;
}
@ -1228,7 +1228,7 @@ void ASTWorker::startTask(llvm::StringRef Name,
}
// Allow this request to be cancelled if invalidated.
Context Ctx = Context::current().derive(kFileBeingProcessed, FileName);
Context Ctx = Context::current().derive(FileBeingProcessed, FileName);
Canceler Invalidate = nullptr;
if (Invalidation) {
WithContext WC(std::move(Ctx));
@ -1656,7 +1656,7 @@ void TUScheduler::runWithPreamble(llvm::StringRef Name, PathRef File,
auto Task = [Worker, Consistency, Name = Name.str(), File = File.str(),
Contents = It->second->Contents,
Command = Worker->getCurrentCompileCommand(),
Ctx = Context::current().derive(kFileBeingProcessed,
Ctx = Context::current().derive(FileBeingProcessed,
std::string(File)),
Action = std::move(Action), this]() mutable {
ThreadCrashReporter ScopedReporter([&Name, &Contents, &Command]() {

View File

@ -1861,7 +1861,9 @@ static QualType typeForNode(const SelectionTree::Node *N) {
QualType VisitCXXThrowExpr(const CXXThrowExpr *S) {
return S->getSubExpr()->getType();
}
QualType VisitCoyieldStmt(const CoyieldExpr *S) {
// FIXME(sammccall): this should be VisitCoyieldExpr
// see https://reviews.llvm.org/D115634
QualType visitCoyieldStmt(const CoyieldExpr *S) {
return type(S->getOperand());
}
// Treat a designated initializer like a reference to the field.

View File

@ -73,29 +73,29 @@ std::vector<FuzzyFindRequest> extractQueriesFromLogs() {
return Requests;
}
static void MemQueries(benchmark::State &State) {
static void memQueries(benchmark::State &State) {
const auto Mem = buildMem();
const auto Requests = extractQueriesFromLogs();
for (auto _ : State)
for (const auto &Request : Requests)
Mem->fuzzyFind(Request, [](const Symbol &S) {});
}
BENCHMARK(MemQueries);
BENCHMARK(memQueries);
static void DexQueries(benchmark::State &State) {
static void dexQueries(benchmark::State &State) {
const auto Dex = buildDex();
const auto Requests = extractQueriesFromLogs();
for (auto _ : State)
for (const auto &Request : Requests)
Dex->fuzzyFind(Request, [](const Symbol &S) {});
}
BENCHMARK(DexQueries);
BENCHMARK(dexQueries);
static void DexBuild(benchmark::State &State) {
static void dexBuild(benchmark::State &State) {
for (auto _ : State)
buildDex();
}
BENCHMARK(DexBuild);
BENCHMARK(dexBuild);
} // namespace
} // namespace clangd

View File

@ -19,12 +19,12 @@
using namespace clang::clangd;
extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
if (size == 0)
extern "C" int LLVMFuzzerTestOneInput(uint8_t *Data, size_t Size) {
if (Size == 0)
return 0;
// fmemopen isn't portable, but I think we only run the fuzzer on Linux.
std::FILE *In = fmemopen(data, size, "r");
std::FILE *In = fmemopen(Data, Size, "r");
auto Transport = newJSONTransport(In, llvm::nulls(),
/*InMirror=*/nullptr, /*Pretty=*/false,
/*Style=*/JSONStreamStyle::Delimited);

View File

@ -161,19 +161,19 @@ template <> struct MappingTraits<SymbolLocation> {
};
template <> struct MappingTraits<SymbolInfo> {
static void mapping(IO &io, SymbolInfo &SymInfo) {
static void mapping(IO &IO, SymbolInfo &SymInfo) {
// FIXME: expose other fields?
io.mapRequired("Kind", SymInfo.Kind);
io.mapRequired("Lang", SymInfo.Lang);
IO.mapRequired("Kind", SymInfo.Kind);
IO.mapRequired("Lang", SymInfo.Lang);
}
};
template <>
struct MappingTraits<clang::clangd::Symbol::IncludeHeaderWithReferences> {
static void mapping(IO &io,
static void mapping(IO &IO,
clang::clangd::Symbol::IncludeHeaderWithReferences &Inc) {
io.mapRequired("Header", Inc.IncludeHeader);
io.mapRequired("References", Inc.References);
IO.mapRequired("Header", Inc.IncludeHeader);
IO.mapRequired("References", Inc.References);
}
};

View File

@ -28,28 +28,28 @@ using ::testing::UnorderedElementsAre;
namespace clang {
namespace clangd {
MATCHER_P(Named, N, "") { return arg.Name == N; }
MATCHER_P(QName, N, "") { return (arg.Scope + arg.Name).str() == N; }
MATCHER(Declared, "") {
MATCHER_P(named, N, "") { return arg.Name == N; }
MATCHER_P(qName, N, "") { return (arg.Scope + arg.Name).str() == N; }
MATCHER(declared, "") {
return !StringRef(arg.CanonicalDeclaration.FileURI).empty();
}
MATCHER(Defined, "") { return !StringRef(arg.Definition.FileURI).empty(); }
MATCHER_P(FileURI, F, "") { return StringRef(arg.Location.FileURI) == F; }
MATCHER(defined, "") { return !StringRef(arg.Definition.FileURI).empty(); }
MATCHER_P(fileURI, F, "") { return StringRef(arg.Location.FileURI) == F; }
::testing::Matcher<const RefSlab &>
RefsAre(std::vector<::testing::Matcher<Ref>> Matchers) {
refsAre(std::vector<::testing::Matcher<Ref>> Matchers) {
return ElementsAre(::testing::Pair(_, UnorderedElementsAreArray(Matchers)));
}
// URI cannot be empty since it references keys in the IncludeGraph.
MATCHER(EmptyIncludeNode, "") {
MATCHER(emptyIncludeNode, "") {
return arg.Flags == IncludeGraphNode::SourceFlag::None && !arg.URI.empty() &&
arg.Digest == FileDigest{{0}} && arg.DirectIncludes.empty();
}
MATCHER(HadErrors, "") {
MATCHER(hadErrors, "") {
return arg.Flags & IncludeGraphNode::SourceFlag::HadErrors;
}
MATCHER_P(NumReferences, N, "") { return arg.References == N; }
MATCHER_P(numReferences, N, "") { return arg.References == N; }
class MemoryShardStorage : public BackgroundIndexStorage {
mutable std::mutex StorageMu;
@ -159,8 +159,8 @@ TEST_F(BackgroundIndexTest, Config) {
// Wait for both files to be indexed.
ASSERT_TRUE(Idx.blockUntilIdleForTest());
EXPECT_THAT(runFuzzyFind(Idx, ""),
UnorderedElementsAre(QName("foo"), QName("foo::two"),
QName("bar"), QName("bar::one")));
UnorderedElementsAre(qName("foo"), qName("foo::two"),
qName("bar"), qName("bar::one")));
}
TEST_F(BackgroundIndexTest, IndexTwoFiles) {
@ -203,11 +203,11 @@ TEST_F(BackgroundIndexTest, IndexTwoFiles) {
ASSERT_TRUE(Idx.blockUntilIdleForTest());
EXPECT_THAT(runFuzzyFind(Idx, ""),
UnorderedElementsAre(AllOf(Named("common"), NumReferences(1U)),
AllOf(Named("A_CC"), NumReferences(0U)),
AllOf(Named("g"), NumReferences(1U)),
AllOf(Named("f_b"), Declared(),
Not(Defined()), NumReferences(0U))));
UnorderedElementsAre(AllOf(named("common"), numReferences(1U)),
AllOf(named("A_CC"), numReferences(0U)),
AllOf(named("g"), numReferences(1U)),
AllOf(named("f_b"), declared(),
Not(defined()), numReferences(0U))));
Cmd.Filename = testPath("root/B.cc");
Cmd.CommandLine = {"clang++", Cmd.Filename};
@ -216,22 +216,22 @@ TEST_F(BackgroundIndexTest, IndexTwoFiles) {
ASSERT_TRUE(Idx.blockUntilIdleForTest());
// B_CC is dropped as we don't collect symbols from A.h in this compilation.
EXPECT_THAT(runFuzzyFind(Idx, ""),
UnorderedElementsAre(AllOf(Named("common"), NumReferences(5U)),
AllOf(Named("A_CC"), NumReferences(0U)),
AllOf(Named("g"), NumReferences(1U)),
AllOf(Named("f_b"), Declared(), Defined(),
NumReferences(1U))));
UnorderedElementsAre(AllOf(named("common"), numReferences(5U)),
AllOf(named("A_CC"), numReferences(0U)),
AllOf(named("g"), numReferences(1U)),
AllOf(named("f_b"), declared(), defined(),
numReferences(1U))));
auto Syms = runFuzzyFind(Idx, "common");
EXPECT_THAT(Syms, UnorderedElementsAre(Named("common")));
EXPECT_THAT(Syms, UnorderedElementsAre(named("common")));
auto Common = *Syms.begin();
EXPECT_THAT(getRefs(Idx, Common.ID),
RefsAre({FileURI("unittest:///root/A.h"),
FileURI("unittest:///root/A.cc"),
FileURI("unittest:///root/B.cc"),
FileURI("unittest:///root/B.cc"),
FileURI("unittest:///root/B.cc"),
FileURI("unittest:///root/B.cc")}));
refsAre({fileURI("unittest:///root/A.h"),
fileURI("unittest:///root/A.cc"),
fileURI("unittest:///root/B.cc"),
fileURI("unittest:///root/B.cc"),
fileURI("unittest:///root/B.cc"),
fileURI("unittest:///root/B.cc")}));
}
TEST_F(BackgroundIndexTest, MainFileRefs) {
@ -259,8 +259,8 @@ TEST_F(BackgroundIndexTest, MainFileRefs) {
ASSERT_TRUE(Idx.blockUntilIdleForTest());
EXPECT_THAT(
runFuzzyFind(Idx, ""),
UnorderedElementsAre(AllOf(Named("header_sym"), NumReferences(1U)),
AllOf(Named("main_sym"), NumReferences(1U))));
UnorderedElementsAre(AllOf(named("header_sym"), numReferences(1U)),
AllOf(named("main_sym"), numReferences(1U))));
}
TEST_F(BackgroundIndexTest, ShardStorageTest) {
@ -270,7 +270,6 @@ TEST_F(BackgroundIndexTest, ShardStorageTest) {
void f_b();
class A_CC {};
)cpp";
std::string A_CC = "";
FS.Files[testPath("root/A.cc")] = R"cpp(
#include "A.h"
void g() { (void)common; }
@ -310,19 +309,19 @@ TEST_F(BackgroundIndexTest, ShardStorageTest) {
EXPECT_NE(ShardHeader, nullptr);
EXPECT_THAT(
*ShardHeader->Symbols,
UnorderedElementsAre(Named("common"), Named("A_CC"),
AllOf(Named("f_b"), Declared(), Not(Defined()))));
UnorderedElementsAre(named("common"), named("A_CC"),
AllOf(named("f_b"), declared(), Not(defined()))));
for (const auto &Ref : *ShardHeader->Refs)
EXPECT_THAT(Ref.second,
UnorderedElementsAre(FileURI("unittest:///root/A.h")));
UnorderedElementsAre(fileURI("unittest:///root/A.h")));
auto ShardSource = MSS.loadShard(testPath("root/A.cc"));
EXPECT_NE(ShardSource, nullptr);
EXPECT_THAT(*ShardSource->Symbols,
UnorderedElementsAre(Named("g"), Named("B_CC")));
UnorderedElementsAre(named("g"), named("B_CC")));
for (const auto &Ref : *ShardSource->Refs)
EXPECT_THAT(Ref.second,
UnorderedElementsAre(FileURI("unittest:///root/A.cc")));
UnorderedElementsAre(fileURI("unittest:///root/A.cc")));
// The BaseOf relationship between A_CC and B_CC is stored in both the file
// containing the definition of the subject (A_CC) and the file containing
@ -344,8 +343,8 @@ TEST_F(BackgroundIndexTest, DirectIncludesTest) {
void f_b();
class A_CC {};
)cpp";
std::string A_CC = "#include \"A.h\"\nvoid g() { (void)common; }";
FS.Files[testPath("root/A.cc")] = A_CC;
FS.Files[testPath("root/A.cc")] =
"#include \"A.h\"\nvoid g() { (void)common; }";
llvm::StringMap<std::string> Storage;
size_t CacheHits = 0;
@ -372,7 +371,7 @@ TEST_F(BackgroundIndexTest, DirectIncludesTest) {
EXPECT_NE(ShardSource->Sources->lookup("unittest:///root/A.cc").Digest,
FileDigest{{0}});
EXPECT_THAT(ShardSource->Sources->lookup("unittest:///root/A.h"),
EmptyIncludeNode());
emptyIncludeNode());
auto ShardHeader = MSS.loadShard(testPath("root/A.h"));
EXPECT_TRUE(ShardHeader->Sources);
@ -383,7 +382,7 @@ TEST_F(BackgroundIndexTest, DirectIncludesTest) {
EXPECT_NE(ShardHeader->Sources->lookup("unittest:///root/A.h").Digest,
FileDigest{{0}});
EXPECT_THAT(ShardHeader->Sources->lookup("unittest:///root/B.h"),
EmptyIncludeNode());
emptyIncludeNode());
}
TEST_F(BackgroundIndexTest, ShardStorageLoad) {
@ -432,7 +431,7 @@ TEST_F(BackgroundIndexTest, ShardStorageLoad) {
// Check if the new symbol has arrived.
auto ShardHeader = MSS.loadShard(testPath("root/A.h"));
EXPECT_NE(ShardHeader, nullptr);
EXPECT_THAT(*ShardHeader->Symbols, Contains(Named("A_CCnew")));
EXPECT_THAT(*ShardHeader->Symbols, Contains(named("A_CCnew")));
// Change source.
FS.Files[testPath("root/A.cc")] =
@ -450,11 +449,11 @@ TEST_F(BackgroundIndexTest, ShardStorageLoad) {
// Check if the new symbol has arrived.
ShardHeader = MSS.loadShard(testPath("root/A.h"));
EXPECT_NE(ShardHeader, nullptr);
EXPECT_THAT(*ShardHeader->Symbols, Contains(Named("A_CCnew")));
EXPECT_THAT(*ShardHeader->Symbols, Contains(named("A_CCnew")));
auto ShardSource = MSS.loadShard(testPath("root/A.cc"));
EXPECT_NE(ShardSource, nullptr);
EXPECT_THAT(*ShardSource->Symbols,
Contains(AllOf(Named("f_b"), Declared(), Defined())));
Contains(AllOf(named("f_b"), declared(), defined())));
}
TEST_F(BackgroundIndexTest, ShardStorageEmptyFile) {
@ -522,7 +521,7 @@ TEST_F(BackgroundIndexTest, ShardStorageEmptyFile) {
ShardHeader = MSS.loadShard(testPath("root/B.h"));
EXPECT_NE(ShardHeader, nullptr);
EXPECT_THAT(*ShardHeader->Symbols,
Contains(AllOf(Named("new_func"), Declared(), Not(Defined()))));
Contains(AllOf(named("new_func"), declared(), Not(defined()))));
}
TEST_F(BackgroundIndexTest, NoDotsInAbsPath) {
@ -587,27 +586,27 @@ TEST_F(BackgroundIndexTest, UncompilableFiles) {
{
auto Shard = MSS.loadShard(testPath("A.cc"));
EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(Named("foo")));
EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(named("foo")));
EXPECT_THAT(Shard->Sources->keys(),
UnorderedElementsAre("unittest:///A.cc", "unittest:///A.h",
"unittest:///B.h"));
EXPECT_THAT(Shard->Sources->lookup("unittest:///A.cc"), HadErrors());
EXPECT_THAT(Shard->Sources->lookup("unittest:///A.cc"), hadErrors());
}
{
auto Shard = MSS.loadShard(testPath("A.h"));
EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(Named("foo")));
EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(named("foo")));
EXPECT_THAT(Shard->Sources->keys(),
UnorderedElementsAre("unittest:///A.h"));
EXPECT_THAT(Shard->Sources->lookup("unittest:///A.h"), HadErrors());
EXPECT_THAT(Shard->Sources->lookup("unittest:///A.h"), hadErrors());
}
{
auto Shard = MSS.loadShard(testPath("B.h"));
EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(Named("asdf")));
EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(named("asdf")));
EXPECT_THAT(Shard->Sources->keys(),
UnorderedElementsAre("unittest:///B.h", "unittest:///C.h"));
EXPECT_THAT(Shard->Sources->lookup("unittest:///B.h"), HadErrors());
EXPECT_THAT(Shard->Sources->lookup("unittest:///B.h"), hadErrors());
}
{
@ -615,7 +614,7 @@ TEST_F(BackgroundIndexTest, UncompilableFiles) {
EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre());
EXPECT_THAT(Shard->Sources->keys(),
UnorderedElementsAre("unittest:///C.h"));
EXPECT_THAT(Shard->Sources->lookup("unittest:///C.h"), HadErrors());
EXPECT_THAT(Shard->Sources->lookup("unittest:///C.h"), hadErrors());
}
}

View File

@ -52,15 +52,15 @@ using ::testing::Matcher;
using ::testing::UnorderedElementsAre;
// Helpers for matching call hierarchy data structures.
MATCHER_P(WithName, N, "") { return arg.name == N; }
MATCHER_P(WithSelectionRange, R, "") { return arg.selectionRange == R; }
MATCHER_P(withName, N, "") { return arg.name == N; }
MATCHER_P(withSelectionRange, R, "") { return arg.selectionRange == R; }
template <class ItemMatcher>
::testing::Matcher<CallHierarchyIncomingCall> From(ItemMatcher M) {
::testing::Matcher<CallHierarchyIncomingCall> from(ItemMatcher M) {
return Field(&CallHierarchyIncomingCall::from, M);
}
template <class... RangeMatchers>
::testing::Matcher<CallHierarchyIncomingCall> FromRanges(RangeMatchers... M) {
::testing::Matcher<CallHierarchyIncomingCall> fromRanges(RangeMatchers... M) {
return Field(&CallHierarchyIncomingCall::fromRanges,
UnorderedElementsAre(M...));
}
@ -86,23 +86,23 @@ TEST(CallHierarchy, IncomingOneFileCpp) {
std::vector<CallHierarchyItem> Items =
prepareCallHierarchy(AST, Source.point(), testPath(TU.Filename));
ASSERT_THAT(Items, ElementsAre(WithName("callee")));
ASSERT_THAT(Items, ElementsAre(withName("callee")));
auto IncomingLevel1 = incomingCalls(Items[0], Index.get());
ASSERT_THAT(IncomingLevel1,
ElementsAre(AllOf(From(WithName("caller1")),
FromRanges(Source.range("Callee")))));
ElementsAre(AllOf(from(withName("caller1")),
fromRanges(Source.range("Callee")))));
auto IncomingLevel2 = incomingCalls(IncomingLevel1[0].from, Index.get());
ASSERT_THAT(IncomingLevel2,
ElementsAre(AllOf(From(WithName("caller2")),
FromRanges(Source.range("Caller1A"),
ElementsAre(AllOf(from(withName("caller2")),
fromRanges(Source.range("Caller1A"),
Source.range("Caller1B"))),
AllOf(From(WithName("caller3")),
FromRanges(Source.range("Caller1C")))));
AllOf(from(withName("caller3")),
fromRanges(Source.range("Caller1C")))));
auto IncomingLevel3 = incomingCalls(IncomingLevel2[0].from, Index.get());
ASSERT_THAT(IncomingLevel3,
ElementsAre(AllOf(From(WithName("caller3")),
FromRanges(Source.range("Caller2")))));
ElementsAre(AllOf(from(withName("caller3")),
fromRanges(Source.range("Caller2")))));
auto IncomingLevel4 = incomingCalls(IncomingLevel3[0].from, Index.get());
EXPECT_THAT(IncomingLevel4, IsEmpty());
@ -131,23 +131,23 @@ TEST(CallHierarchy, IncomingOneFileObjC) {
auto Index = TU.index();
std::vector<CallHierarchyItem> Items =
prepareCallHierarchy(AST, Source.point(), testPath(TU.Filename));
ASSERT_THAT(Items, ElementsAre(WithName("callee")));
ASSERT_THAT(Items, ElementsAre(withName("callee")));
auto IncomingLevel1 = incomingCalls(Items[0], Index.get());
ASSERT_THAT(IncomingLevel1,
ElementsAre(AllOf(From(WithName("caller1")),
FromRanges(Source.range("Callee")))));
ElementsAre(AllOf(from(withName("caller1")),
fromRanges(Source.range("Callee")))));
auto IncomingLevel2 = incomingCalls(IncomingLevel1[0].from, Index.get());
ASSERT_THAT(IncomingLevel2,
ElementsAre(AllOf(From(WithName("caller2")),
FromRanges(Source.range("Caller1A"),
ElementsAre(AllOf(from(withName("caller2")),
fromRanges(Source.range("Caller1A"),
Source.range("Caller1B"))),
AllOf(From(WithName("caller3")),
FromRanges(Source.range("Caller1C")))));
AllOf(from(withName("caller3")),
fromRanges(Source.range("Caller1C")))));
auto IncomingLevel3 = incomingCalls(IncomingLevel2[0].from, Index.get());
ASSERT_THAT(IncomingLevel3,
ElementsAre(AllOf(From(WithName("caller3")),
FromRanges(Source.range("Caller2")))));
ElementsAre(AllOf(from(withName("caller3")),
fromRanges(Source.range("Caller2")))));
auto IncomingLevel4 = incomingCalls(IncomingLevel3[0].from, Index.get());
EXPECT_THAT(IncomingLevel4, IsEmpty());
@ -174,16 +174,16 @@ TEST(CallHierarchy, MainFileOnlyRef) {
std::vector<CallHierarchyItem> Items =
prepareCallHierarchy(AST, Source.point(), testPath(TU.Filename));
ASSERT_THAT(Items, ElementsAre(WithName("callee")));
ASSERT_THAT(Items, ElementsAre(withName("callee")));
auto IncomingLevel1 = incomingCalls(Items[0], Index.get());
ASSERT_THAT(IncomingLevel1,
ElementsAre(AllOf(From(WithName("caller1")),
FromRanges(Source.range("Callee")))));
ElementsAre(AllOf(from(withName("caller1")),
fromRanges(Source.range("Callee")))));
auto IncomingLevel2 = incomingCalls(IncomingLevel1[0].from, Index.get());
EXPECT_THAT(IncomingLevel2,
ElementsAre(AllOf(From(WithName("caller2")),
FromRanges(Source.range("Caller1")))));
ElementsAre(AllOf(from(withName("caller2")),
fromRanges(Source.range("Caller1")))));
}
TEST(CallHierarchy, IncomingQualified) {
@ -207,13 +207,13 @@ TEST(CallHierarchy, IncomingQualified) {
std::vector<CallHierarchyItem> Items =
prepareCallHierarchy(AST, Source.point(), testPath(TU.Filename));
ASSERT_THAT(Items, ElementsAre(WithName("Waldo::find")));
ASSERT_THAT(Items, ElementsAre(withName("Waldo::find")));
auto Incoming = incomingCalls(Items[0], Index.get());
EXPECT_THAT(Incoming,
ElementsAre(AllOf(From(WithName("caller1")),
FromRanges(Source.range("Caller1"))),
AllOf(From(WithName("caller2")),
FromRanges(Source.range("Caller2")))));
ElementsAre(AllOf(from(withName("caller1")),
fromRanges(Source.range("Caller1"))),
AllOf(from(withName("caller2")),
fromRanges(Source.range("Caller2")))));
}
TEST(CallHierarchy, IncomingMultiFileCpp) {
@ -273,24 +273,24 @@ TEST(CallHierarchy, IncomingMultiFileCpp) {
auto CheckCallHierarchy = [&](ParsedAST &AST, Position Pos, PathRef TUPath) {
std::vector<CallHierarchyItem> Items =
prepareCallHierarchy(AST, Pos, TUPath);
ASSERT_THAT(Items, ElementsAre(WithName("callee")));
ASSERT_THAT(Items, ElementsAre(withName("callee")));
auto IncomingLevel1 = incomingCalls(Items[0], Index.get());
ASSERT_THAT(IncomingLevel1,
ElementsAre(AllOf(From(WithName("caller1")),
FromRanges(Caller1C.range()))));
ElementsAre(AllOf(from(withName("caller1")),
fromRanges(Caller1C.range()))));
auto IncomingLevel2 = incomingCalls(IncomingLevel1[0].from, Index.get());
ASSERT_THAT(
IncomingLevel2,
ElementsAre(AllOf(From(WithName("caller2")),
FromRanges(Caller2C.range("A"), Caller2C.range("B"))),
AllOf(From(WithName("caller3")),
FromRanges(Caller3C.range("Caller1")))));
ElementsAre(AllOf(from(withName("caller2")),
fromRanges(Caller2C.range("A"), Caller2C.range("B"))),
AllOf(from(withName("caller3")),
fromRanges(Caller3C.range("Caller1")))));
auto IncomingLevel3 = incomingCalls(IncomingLevel2[0].from, Index.get());
ASSERT_THAT(IncomingLevel3,
ElementsAre(AllOf(From(WithName("caller3")),
FromRanges(Caller3C.range("Caller2")))));
ElementsAre(AllOf(from(withName("caller3")),
fromRanges(Caller3C.range("Caller2")))));
auto IncomingLevel4 = incomingCalls(IncomingLevel3[0].from, Index.get());
EXPECT_THAT(IncomingLevel4, IsEmpty());
@ -382,24 +382,24 @@ TEST(CallHierarchy, IncomingMultiFileObjC) {
auto CheckCallHierarchy = [&](ParsedAST &AST, Position Pos, PathRef TUPath) {
std::vector<CallHierarchyItem> Items =
prepareCallHierarchy(AST, Pos, TUPath);
ASSERT_THAT(Items, ElementsAre(WithName("callee")));
ASSERT_THAT(Items, ElementsAre(withName("callee")));
auto IncomingLevel1 = incomingCalls(Items[0], Index.get());
ASSERT_THAT(IncomingLevel1,
ElementsAre(AllOf(From(WithName("caller1")),
FromRanges(Caller1C.range()))));
ElementsAre(AllOf(from(withName("caller1")),
fromRanges(Caller1C.range()))));
auto IncomingLevel2 = incomingCalls(IncomingLevel1[0].from, Index.get());
ASSERT_THAT(
IncomingLevel2,
ElementsAre(AllOf(From(WithName("caller2")),
FromRanges(Caller2C.range("A"), Caller2C.range("B"))),
AllOf(From(WithName("caller3")),
FromRanges(Caller3C.range("Caller1")))));
ElementsAre(AllOf(from(withName("caller2")),
fromRanges(Caller2C.range("A"), Caller2C.range("B"))),
AllOf(from(withName("caller3")),
fromRanges(Caller3C.range("Caller1")))));
auto IncomingLevel3 = incomingCalls(IncomingLevel2[0].from, Index.get());
ASSERT_THAT(IncomingLevel3,
ElementsAre(AllOf(From(WithName("caller3")),
FromRanges(Caller3C.range("Caller2")))));
ElementsAre(AllOf(from(withName("caller3")),
fromRanges(Caller3C.range("Caller2")))));
auto IncomingLevel4 = incomingCalls(IncomingLevel3[0].from, Index.get());
EXPECT_THAT(IncomingLevel4, IsEmpty());
@ -444,15 +444,15 @@ TEST(CallHierarchy, CallInLocalVarDecl) {
std::vector<CallHierarchyItem> Items =
prepareCallHierarchy(AST, Source.point(), testPath(TU.Filename));
ASSERT_THAT(Items, ElementsAre(WithName("callee")));
ASSERT_THAT(Items, ElementsAre(withName("callee")));
auto Incoming = incomingCalls(Items[0], Index.get());
ASSERT_THAT(
Incoming,
ElementsAre(
AllOf(From(WithName("caller1")), FromRanges(Source.range("call1"))),
AllOf(From(WithName("caller2")), FromRanges(Source.range("call2"))),
AllOf(From(WithName("caller3")), FromRanges(Source.range("call3")))));
AllOf(from(withName("caller1")), fromRanges(Source.range("call1"))),
AllOf(from(withName("caller2")), fromRanges(Source.range("call2"))),
AllOf(from(withName("caller3")), fromRanges(Source.range("call3")))));
}
} // namespace

View File

@ -27,7 +27,7 @@ namespace {
using llvm::Succeeded;
using testing::ElementsAre;
MATCHER_P(DiagMessage, M, "") {
MATCHER_P(diagMessage, M, "") {
if (const auto *O = arg.getAsObject()) {
if (const auto Msg = O->getString("message"))
return *Msg == M;
@ -125,12 +125,12 @@ TEST_F(LSPTest, Diagnostics) {
Client.didOpen("foo.cpp", "void main(int, char**);");
EXPECT_THAT(Client.diagnostics("foo.cpp"),
llvm::ValueIs(testing::ElementsAre(
DiagMessage("'main' must return 'int' (fix available)"))));
diagMessage("'main' must return 'int' (fix available)"))));
Client.didChange("foo.cpp", "int x = \"42\";");
EXPECT_THAT(Client.diagnostics("foo.cpp"),
llvm::ValueIs(testing::ElementsAre(
DiagMessage("Cannot initialize a variable of type 'int' with "
diagMessage("Cannot initialize a variable of type 'int' with "
"an lvalue of type 'const char[3]'"))));
Client.didClose("foo.cpp");
@ -145,8 +145,8 @@ TEST_F(LSPTest, DiagnosticsHeaderSaved) {
)cpp");
EXPECT_THAT(Client.diagnostics("foo.cpp"),
llvm::ValueIs(testing::ElementsAre(
DiagMessage("'foo.h' file not found"),
DiagMessage("Use of undeclared identifier 'VAR'"))));
diagMessage("'foo.h' file not found"),
diagMessage("Use of undeclared identifier 'VAR'"))));
// Now create the header.
FS.Files["foo.h"] = "#define VAR original";
Client.notify(
@ -154,7 +154,7 @@ TEST_F(LSPTest, DiagnosticsHeaderSaved) {
llvm::json::Object{{"textDocument", Client.documentID("foo.h")}});
EXPECT_THAT(Client.diagnostics("foo.cpp"),
llvm::ValueIs(testing::ElementsAre(
DiagMessage("Use of undeclared identifier 'original'"))));
diagMessage("Use of undeclared identifier 'original'"))));
// Now modify the header from within the "editor".
FS.Files["foo.h"] = "#define VAR changed";
Client.notify(
@ -163,7 +163,7 @@ TEST_F(LSPTest, DiagnosticsHeaderSaved) {
// Foo.cpp should be rebuilt with new diagnostics.
EXPECT_THAT(Client.diagnostics("foo.cpp"),
llvm::ValueIs(testing::ElementsAre(
DiagMessage("Use of undeclared identifier 'changed'"))));
diagMessage("Use of undeclared identifier 'changed'"))));
}
TEST_F(LSPTest, RecordsLatencies) {
@ -221,12 +221,12 @@ CompileFlags:
Client.didOpen("foo.cpp", "int x = FOO;");
EXPECT_THAT(Client.diagnostics("foo.cpp"),
llvm::ValueIs(testing::ElementsAre(
DiagMessage("Use of undeclared identifier 'FOO'"))));
diagMessage("Use of undeclared identifier 'FOO'"))));
// bar.cpp shows the configured compile command.
Client.didOpen("bar.cpp", "int x = FOO;");
EXPECT_THAT(Client.diagnostics("bar.cpp"),
llvm::ValueIs(testing::ElementsAre(
DiagMessage("Use of undeclared identifier 'BAR'"))));
diagMessage("Use of undeclared identifier 'BAR'"))));
}
TEST_F(LSPTest, ModulesTest) {
@ -384,7 +384,7 @@ TEST_F(LSPTest, DiagModuleTest) {
auto &Client = start();
Client.didOpen("foo.cpp", "test;");
EXPECT_THAT(Client.diagnostics("foo.cpp"),
llvm::ValueIs(testing::ElementsAre(DiagMessage(DiagMsg))));
llvm::ValueIs(testing::ElementsAre(diagMessage(DiagMsg))));
}
} // namespace
} // namespace clangd

File diff suppressed because it is too large Load Diff

View File

@ -107,7 +107,7 @@ TEST(CommandMangler, ClangPath) {
// Only run the PATH/symlink resolving test on unix, we need to fiddle
// with permissions and environment variables...
#ifdef LLVM_ON_UNIX
MATCHER(Ok, "") {
MATCHER(ok, "") {
if (arg) {
*result_listener << arg.message();
return false;
@ -124,20 +124,20 @@ TEST(CommandMangler, ClangPathResolve) {
// bar
llvm::SmallString<256> TempDir;
ASSERT_THAT(llvm::sys::fs::createUniqueDirectory("ClangPathResolve", TempDir),
Ok());
ok());
// /var/tmp is a symlink on Mac. Resolve it so we're asserting the right path.
ASSERT_THAT(llvm::sys::fs::real_path(TempDir.str(), TempDir), Ok());
ASSERT_THAT(llvm::sys::fs::real_path(TempDir.str(), TempDir), ok());
auto CleanDir = llvm::make_scope_exit(
[&] { llvm::sys::fs::remove_directories(TempDir); });
ASSERT_THAT(llvm::sys::fs::create_directory(TempDir + "/bin"), Ok());
ASSERT_THAT(llvm::sys::fs::create_directory(TempDir + "/lib"), Ok());
ASSERT_THAT(llvm::sys::fs::create_directory(TempDir + "/bin"), ok());
ASSERT_THAT(llvm::sys::fs::create_directory(TempDir + "/lib"), ok());
int FD;
ASSERT_THAT(llvm::sys::fs::openFileForWrite(TempDir + "/lib/bar", FD), Ok());
ASSERT_THAT(llvm::sys::Process::SafelyCloseFileDescriptor(FD), Ok());
ASSERT_THAT(llvm::sys::fs::openFileForWrite(TempDir + "/lib/bar", FD), ok());
ASSERT_THAT(llvm::sys::Process::SafelyCloseFileDescriptor(FD), ok());
::chmod((TempDir + "/lib/bar").str().c_str(), 0755); // executable
ASSERT_THAT(
llvm::sys::fs::create_link(TempDir + "/lib/bar", TempDir + "/bin/foo"),
Ok());
ok());
// Test the case where the driver is an absolute path to a symlink.
auto Mangler = CommandMangler::forTests();

View File

@ -150,7 +150,7 @@ TEST_F(ConfigCompileTests, CompilationDatabase) {
Config::CDBSearchSpec::Ancestors)
<< "default value";
EXPECT_THAT(Diags.Diagnostics,
ElementsAre(DiagMessage(
ElementsAre(diagMessage(
"CompilationDatabase must be an absolute path, because this "
"fragment is not associated with any directory.")));
@ -184,7 +184,7 @@ TEST_F(ConfigCompileTests, Index) {
<< "by default";
EXPECT_THAT(
Diags.Diagnostics,
ElementsAre(DiagMessage(
ElementsAre(diagMessage(
"Invalid Background value 'Foo'. Valid values are Build, Skip.")));
}
@ -325,9 +325,9 @@ TEST_F(ConfigCompileTests, Tidy) {
EXPECT_THAT(
Diags.Diagnostics,
ElementsAre(
DiagMessage(
diagMessage(
"clang-tidy check 'bugprone-use-after-move' was not found"),
DiagMessage("clang-tidy check 'llvm-include-order' was not found")));
diagMessage("clang-tidy check 'llvm-include-order' was not found")));
#endif
}
@ -342,11 +342,11 @@ TEST_F(ConfigCompileTests, TidyBadChecks) {
EXPECT_THAT(
Diags.Diagnostics,
ElementsAre(
AllOf(DiagMessage("clang-tidy check 'unknown-check' was not found"),
DiagKind(llvm::SourceMgr::DK_Warning)),
AllOf(diagMessage("clang-tidy check 'unknown-check' was not found"),
diagKind(llvm::SourceMgr::DK_Warning)),
AllOf(
DiagMessage("clang-tidy check 'llvm-includeorder' was not found"),
DiagKind(llvm::SourceMgr::DK_Warning))));
diagMessage("clang-tidy check 'llvm-includeorder' was not found"),
diagKind(llvm::SourceMgr::DK_Warning))));
}
TEST_F(ConfigCompileTests, ExternalServerNeedsTrusted) {
@ -356,7 +356,7 @@ TEST_F(ConfigCompileTests, ExternalServerNeedsTrusted) {
compileAndApply();
EXPECT_THAT(
Diags.Diagnostics,
ElementsAre(DiagMessage(
ElementsAre(diagMessage(
"Remote index may not be specified by untrusted configuration. "
"Copy this into user config to use it.")));
EXPECT_EQ(Conf.Index.External.Kind, Config::ExternalIndexSpec::None);
@ -373,8 +373,8 @@ TEST_F(ConfigCompileTests, ExternalBlockWarnOnMultipleSource) {
EXPECT_THAT(
Diags.Diagnostics,
Contains(
AllOf(DiagMessage("Exactly one of File, Server or None must be set."),
DiagKind(llvm::SourceMgr::DK_Error))));
AllOf(diagMessage("Exactly one of File, Server or None must be set."),
diagKind(llvm::SourceMgr::DK_Error))));
#else
ASSERT_TRUE(Conf.Index.External.hasValue());
EXPECT_EQ(Conf.Index.External->Kind, Config::ExternalIndexSpec::File);
@ -398,8 +398,8 @@ TEST_F(ConfigCompileTests, ExternalBlockErrOnNoSource) {
EXPECT_THAT(
Diags.Diagnostics,
Contains(
AllOf(DiagMessage("Exactly one of File, Server or None must be set."),
DiagKind(llvm::SourceMgr::DK_Error))));
AllOf(diagMessage("Exactly one of File, Server or None must be set."),
diagKind(llvm::SourceMgr::DK_Error))));
}
TEST_F(ConfigCompileTests, ExternalBlockDisablesBackgroundIndex) {
@ -437,9 +437,9 @@ TEST_F(ConfigCompileTests, ExternalBlockMountPoint) {
ASSERT_THAT(
Diags.Diagnostics,
ElementsAre(
AllOf(DiagMessage("MountPoint must be an absolute path, because this "
AllOf(diagMessage("MountPoint must be an absolute path, because this "
"fragment is not associated with any directory."),
DiagKind(llvm::SourceMgr::DK_Error))));
diagKind(llvm::SourceMgr::DK_Error))));
EXPECT_EQ(Conf.Index.External.Kind, Config::ExternalIndexSpec::None);
auto FooPath = testPath("foo/", llvm::sys::path::Style::posix);

View File

@ -63,13 +63,13 @@ TEST(ProviderTest, Combine) {
auto Combined = Provider::combine({&Foo, &Bar});
Config Cfg = Combined->getConfig(Params(), Diags.callback());
EXPECT_THAT(Diags.Diagnostics,
ElementsAre(DiagMessage("foo"), DiagMessage("bar")));
ElementsAre(diagMessage("foo"), diagMessage("bar")));
EXPECT_THAT(getAddedArgs(Cfg), ElementsAre("foo1", "bar1"));
Diags.Diagnostics.clear();
Cfg = Combined->getConfig(Params(), Diags.callback());
EXPECT_THAT(Diags.Diagnostics,
ElementsAre(DiagMessage("foo"), DiagMessage("bar")));
ElementsAre(diagMessage("foo"), diagMessage("bar")));
EXPECT_THAT(getAddedArgs(Cfg), ElementsAre("foo2", "bar2"));
}
@ -101,7 +101,7 @@ TEST(ProviderTest, FromYAMLFile) {
auto P = Provider::fromYAMLFile(testPath("foo.yaml"), /*Directory=*/"", FS);
auto Cfg = P->getConfig(Params(), Diags.callback());
EXPECT_THAT(Diags.Diagnostics,
ElementsAre(DiagMessage("Unknown CompileFlags key 'Unknown'")));
ElementsAre(diagMessage("Unknown CompileFlags key 'Unknown'")));
EXPECT_THAT(Diags.Files, ElementsAre(testPath("foo.yaml")));
EXPECT_THAT(getAddedArgs(Cfg), ElementsAre("foo"));
Diags.clear();
@ -115,7 +115,7 @@ TEST(ProviderTest, FromYAMLFile) {
Cfg = P->getConfig(Params(), Diags.callback());
EXPECT_THAT(
Diags.Diagnostics,
ElementsAre(DiagMessage(
ElementsAre(diagMessage(
"Unknown CompileFlags key 'Removr'; did you mean 'Remove'?")));
EXPECT_THAT(Diags.Files, ElementsAre(testPath("foo.yaml")));
EXPECT_THAT(getAddedArgs(Cfg), ElementsAre("foo"));
@ -159,7 +159,7 @@ TEST(ProviderTest, FromAncestorRelativeYAMLFiles) {
Cfg = P->getConfig(ABCParams, Diags.callback());
EXPECT_THAT(Diags.Diagnostics,
ElementsAre(DiagMessage("Unknown CompileFlags key 'Unknown'")));
ElementsAre(diagMessage("Unknown CompileFlags key 'Unknown'")));
// FIXME: fails on windows: paths have mixed slashes like C:\a/b\c.yaml
EXPECT_THAT(Diags.Files,
ElementsAre(testPath("a/foo.yaml"), testPath("a/b/c/foo.yaml")));
@ -194,7 +194,7 @@ TEST(ProviderTest, Staleness) {
FS.Files["foo.yaml"] = AddFooWithErr;
auto Cfg = P->getConfig(StaleOK, Diags.callback());
EXPECT_THAT(Diags.Diagnostics,
ElementsAre(DiagMessage("Unknown CompileFlags key 'Unknown'")));
ElementsAre(diagMessage("Unknown CompileFlags key 'Unknown'")));
EXPECT_THAT(getAddedArgs(Cfg), ElementsAre("foo"));
Diags.clear();

View File

@ -65,10 +65,10 @@ struct CapturedDiags {
}
};
MATCHER_P(DiagMessage, M, "") { return arg.Message == M; }
MATCHER_P(DiagKind, K, "") { return arg.Kind == K; }
MATCHER_P(DiagPos, P, "") { return arg.Pos == P; }
MATCHER_P(DiagRange, R, "") { return arg.Rng == R; }
MATCHER_P(diagMessage, M, "") { return arg.Message == M; }
MATCHER_P(diagKind, K, "") { return arg.Kind == K; }
MATCHER_P(diagPos, P, "") { return arg.Pos == P; }
MATCHER_P(diagRange, R, "") { return arg.Rng == R; }
inline Position toPosition(llvm::SMLoc L, const llvm::SourceMgr &SM) {
auto LineCol = SM.getLineAndColumn(L);

View File

@ -22,6 +22,9 @@
namespace clang {
namespace clangd {
namespace config {
// PrintTo is a magic identifier of GTest
// NOLINTNEXTLINE (readability-identifier-naming)
template <typename T> void PrintTo(const Located<T> &V, std::ostream *OS) {
*OS << ::testing::PrintToString(*V);
}
@ -31,7 +34,7 @@ using ::testing::AllOf;
using ::testing::ElementsAre;
using ::testing::IsEmpty;
MATCHER_P(Val, Value, "") {
MATCHER_P(val, Value, "") {
if (*arg == Value)
return true;
*result_listener << "value is " << *arg;
@ -74,10 +77,10 @@ Diagnostics:
EXPECT_THAT(Diags.Files, ElementsAre("config.yaml"));
ASSERT_EQ(Results.size(), 4u);
EXPECT_FALSE(Results[0].If.HasUnrecognizedCondition);
EXPECT_THAT(Results[0].If.PathMatch, ElementsAre(Val("abc")));
EXPECT_THAT(Results[0].CompileFlags.Add, ElementsAre(Val("foo"), Val("bar")));
EXPECT_THAT(Results[0].If.PathMatch, ElementsAre(val("abc")));
EXPECT_THAT(Results[0].CompileFlags.Add, ElementsAre(val("foo"), val("bar")));
EXPECT_THAT(Results[1].CompileFlags.Add, ElementsAre(Val("b\naz\n")));
EXPECT_THAT(Results[1].CompileFlags.Add, ElementsAre(val("b\naz\n")));
ASSERT_TRUE(Results[2].Index.Background);
EXPECT_EQ("Skip", *Results[2].Index.Background.getValue());
@ -119,18 +122,18 @@ CompileFlags: {$unexpected^
ASSERT_THAT(
Diags.Diagnostics,
ElementsAre(AllOf(DiagMessage("Unknown If key 'UnknownCondition'"),
DiagKind(llvm::SourceMgr::DK_Warning),
DiagPos(YAML.range("unknown").start),
DiagRange(YAML.range("unknown"))),
AllOf(DiagMessage("Unexpected token. Expected Key, Flow "
ElementsAre(AllOf(diagMessage("Unknown If key 'UnknownCondition'"),
diagKind(llvm::SourceMgr::DK_Warning),
diagPos(YAML.range("unknown").start),
diagRange(YAML.range("unknown"))),
AllOf(diagMessage("Unexpected token. Expected Key, Flow "
"Entry, or Flow Mapping End."),
DiagKind(llvm::SourceMgr::DK_Error),
DiagPos(YAML.point("unexpected")),
DiagRange(llvm::None))));
diagKind(llvm::SourceMgr::DK_Error),
diagPos(YAML.point("unexpected")),
diagRange(llvm::None))));
ASSERT_EQ(Results.size(), 1u); // invalid fragment discarded.
EXPECT_THAT(Results.front().CompileFlags.Add, ElementsAre(Val("first")));
EXPECT_THAT(Results.front().CompileFlags.Add, ElementsAre(val("first")));
EXPECT_TRUE(Results.front().If.HasUnrecognizedCondition);
}
@ -145,8 +148,8 @@ horrible
)yaml";
auto Results = Fragment::parseYAML(YAML, "config.yaml", Diags.callback());
EXPECT_THAT(Diags.Diagnostics,
ElementsAre(DiagMessage("If should be a dictionary"),
DiagMessage("Config should be a dictionary")));
ElementsAre(diagMessage("If should be a dictionary"),
diagMessage("Config should be a dictionary")));
ASSERT_THAT(Results, IsEmpty());
}
@ -180,10 +183,10 @@ Index:
Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
ASSERT_EQ(Results.size(), 1u);
ASSERT_TRUE(Results[0].Index.External);
EXPECT_THAT(*Results[0].Index.External.getValue()->File, Val("foo"));
EXPECT_THAT(*Results[0].Index.External.getValue()->MountPoint, Val("baz"));
EXPECT_THAT(*Results[0].Index.External.getValue()->File, val("foo"));
EXPECT_THAT(*Results[0].Index.External.getValue()->MountPoint, val("baz"));
ASSERT_THAT(Diags.Diagnostics, IsEmpty());
EXPECT_THAT(*Results[0].Index.External.getValue()->Server, Val("bar"));
EXPECT_THAT(*Results[0].Index.External.getValue()->Server, val("bar"));
}
TEST(ParseYAML, AllScopes) {
@ -196,7 +199,7 @@ Completion:
Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
ASSERT_THAT(Diags.Diagnostics, IsEmpty());
ASSERT_EQ(Results.size(), 1u);
EXPECT_THAT(Results[0].Completion.AllScopes, llvm::ValueIs(Val(true)));
EXPECT_THAT(Results[0].Completion.AllScopes, llvm::ValueIs(val(true)));
}
TEST(ParseYAML, AllScopesWarn) {
@ -208,10 +211,10 @@ Completion:
auto Results =
Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
EXPECT_THAT(Diags.Diagnostics,
ElementsAre(AllOf(DiagMessage("AllScopes should be a boolean"),
DiagKind(llvm::SourceMgr::DK_Warning),
DiagPos(YAML.range("diagrange").start),
DiagRange(YAML.range("diagrange")))));
ElementsAre(AllOf(diagMessage("AllScopes should be a boolean"),
diagKind(llvm::SourceMgr::DK_Warning),
diagPos(YAML.range("diagrange").start),
diagRange(YAML.range("diagrange")))));
ASSERT_EQ(Results.size(), 1u);
EXPECT_THAT(Results[0].Completion.AllScopes, testing::Eq(llvm::None));
}
@ -226,7 +229,7 @@ Hover:
Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
ASSERT_THAT(Diags.Diagnostics, IsEmpty());
ASSERT_EQ(Results.size(), 1u);
EXPECT_THAT(Results[0].Hover.ShowAKA, llvm::ValueIs(Val(true)));
EXPECT_THAT(Results[0].Hover.ShowAKA, llvm::ValueIs(val(true)));
}
TEST(ParseYAML, InlayHints) {
@ -240,8 +243,8 @@ InlayHints:
Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
ASSERT_THAT(Diags.Diagnostics, IsEmpty());
ASSERT_EQ(Results.size(), 1u);
EXPECT_THAT(Results[0].InlayHints.Enabled, llvm::ValueIs(Val(false)));
EXPECT_THAT(Results[0].InlayHints.ParameterNames, llvm::ValueIs(Val(true)));
EXPECT_THAT(Results[0].InlayHints.Enabled, llvm::ValueIs(val(false)));
EXPECT_THAT(Results[0].InlayHints.ParameterNames, llvm::ValueIs(val(true)));
EXPECT_EQ(Results[0].InlayHints.DeducedTypes, llvm::None);
}

View File

@ -44,32 +44,32 @@ using ::testing::SizeIs;
using ::testing::UnorderedElementsAre;
using testing::UnorderedElementsAreArray;
::testing::Matcher<const Diag &> WithFix(::testing::Matcher<Fix> FixMatcher) {
::testing::Matcher<const Diag &> withFix(::testing::Matcher<Fix> FixMatcher) {
return Field(&Diag::Fixes, ElementsAre(FixMatcher));
}
::testing::Matcher<const Diag &> WithFix(::testing::Matcher<Fix> FixMatcher1,
::testing::Matcher<const Diag &> withFix(::testing::Matcher<Fix> FixMatcher1,
::testing::Matcher<Fix> FixMatcher2) {
return Field(&Diag::Fixes, UnorderedElementsAre(FixMatcher1, FixMatcher2));
}
::testing::Matcher<const Diag &>
WithNote(::testing::Matcher<Note> NoteMatcher) {
withNote(::testing::Matcher<Note> NoteMatcher) {
return Field(&Diag::Notes, ElementsAre(NoteMatcher));
}
::testing::Matcher<const Diag &>
WithNote(::testing::Matcher<Note> NoteMatcher1,
withNote(::testing::Matcher<Note> NoteMatcher1,
::testing::Matcher<Note> NoteMatcher2) {
return Field(&Diag::Notes, UnorderedElementsAre(NoteMatcher1, NoteMatcher2));
}
::testing::Matcher<const Diag &>
WithTag(::testing::Matcher<DiagnosticTag> TagMatcher) {
withTag(::testing::Matcher<DiagnosticTag> TagMatcher) {
return Field(&Diag::Tags, Contains(TagMatcher));
}
MATCHER_P(HasRange, Range, "") { return arg.Range == Range; }
MATCHER_P(hasRange, Range, "") { return arg.Range == Range; }
MATCHER_P2(Diag, Range, Message,
"Diag at " + llvm::to_string(Range) + " = [" + Message + "]") {
@ -83,9 +83,9 @@ MATCHER_P3(Fix, Range, Replacement, Message,
arg.Edits[0].range == Range && arg.Edits[0].newText == Replacement;
}
MATCHER_P(FixMessage, Message, "") { return arg.Message == Message; }
MATCHER_P(fixMessage, Message, "") { return arg.Message == Message; }
MATCHER_P(EqualToLSPDiag, LSPDiag,
MATCHER_P(equalToLSPDiag, LSPDiag,
"LSP diagnostic " + llvm::to_string(LSPDiag)) {
if (toJSON(arg) != toJSON(LSPDiag)) {
*result_listener << llvm::formatv("expected:\n{0:2}\ngot\n{1:2}",
@ -96,11 +96,11 @@ MATCHER_P(EqualToLSPDiag, LSPDiag,
return true;
}
MATCHER_P(DiagSource, S, "") { return arg.Source == S; }
MATCHER_P(DiagName, N, "") { return arg.Name == N; }
MATCHER_P(DiagSeverity, S, "") { return arg.Severity == S; }
MATCHER_P(diagSource, S, "") { return arg.Source == S; }
MATCHER_P(diagName, N, "") { return arg.Name == N; }
MATCHER_P(diagSeverity, S, "") { return arg.Severity == S; }
MATCHER_P(EqualToFix, Fix, "LSP fix " + llvm::to_string(Fix)) {
MATCHER_P(equalToFix, Fix, "LSP fix " + llvm::to_string(Fix)) {
if (arg.Message != Fix.Message)
return false;
if (arg.Edits.size() != Fix.Edits.size())
@ -114,10 +114,10 @@ MATCHER_P(EqualToFix, Fix, "LSP fix " + llvm::to_string(Fix)) {
}
// Helper function to make tests shorter.
Position pos(int line, int character) {
Position pos(int Line, int Character) {
Position Res;
Res.line = line;
Res.character = character;
Res.line = Line;
Res.character = Character;
return Res;
}
@ -164,20 +164,20 @@ o]]();
AllOf(Diag(Test.range("range"),
"invalid range expression of type 'struct Container *'; "
"did you mean to dereference it with '*'?"),
WithFix(Fix(Test.range("insertstar"), "*", "insert '*'"))),
withFix(Fix(Test.range("insertstar"), "*", "insert '*'"))),
// This range spans lines.
AllOf(Diag(Test.range("typo"),
"use of undeclared identifier 'goo'; did you mean 'foo'?"),
DiagSource(Diag::Clang), DiagName("undeclared_var_use_suggest"),
WithFix(
diagSource(Diag::Clang), diagName("undeclared_var_use_suggest"),
withFix(
Fix(Test.range("typo"), "foo", "change 'go\\…' to 'foo'")),
// This is a pretty normal range.
WithNote(Diag(Test.range("decl"), "'foo' declared here"))),
withNote(Diag(Test.range("decl"), "'foo' declared here"))),
// This range is zero-width and insertion. Therefore make sure we are
// not expanding it into other tokens. Since we are not going to
// replace those.
AllOf(Diag(Test.range("semicolon"), "expected ';' after expression"),
WithFix(Fix(Test.range("semicolon"), ";", "insert ';'"))),
withFix(Fix(Test.range("semicolon"), ";", "insert ';'"))),
// This range isn't provided by clang, we expand to the token.
Diag(Test.range("unk"), "use of undeclared identifier 'unknown'"),
Diag(Test.range("type"),
@ -188,7 +188,7 @@ o]]();
"no member named 'test' in namespace 'test'"),
AllOf(Diag(Test.range("macro"),
"use of undeclared identifier 'fod'; did you mean 'foo'?"),
WithFix(Fix(Test.range("macroarg"), "foo",
withFix(Fix(Test.range("macroarg"), "foo",
"change 'fod' to 'foo'")))));
}
@ -217,7 +217,7 @@ TEST(DiagnosticsTest, FlagsMatter) {
auto TU = TestTU::withCode(Test.code());
EXPECT_THAT(*TU.build().getDiagnostics(),
ElementsAre(AllOf(Diag(Test.range(), "'main' must return 'int'"),
WithFix(Fix(Test.range(), "int",
withFix(Fix(Test.range(), "int",
"change 'void' to 'int'")))));
// Same code built as C gets different diagnostics.
TU.Filename = "Plain.c";
@ -225,7 +225,7 @@ TEST(DiagnosticsTest, FlagsMatter) {
*TU.build().getDiagnostics(),
ElementsAre(AllOf(
Diag(Test.range(), "return type of 'main' is not 'int'"),
WithFix(Fix(Test.range(), "int", "change return type to 'int'")))));
withFix(Fix(Test.range(), "int", "change return type to 'int'")))));
}
TEST(DiagnosticsTest, DiagnosticPreamble) {
@ -237,7 +237,7 @@ TEST(DiagnosticsTest, DiagnosticPreamble) {
EXPECT_THAT(*TU.build().getDiagnostics(),
ElementsAre(::testing::AllOf(
Diag(Test.range(), "'not-found.h' file not found"),
DiagSource(Diag::Clang), DiagName("pp_file_not_found"))));
diagSource(Diag::Clang), diagName("pp_file_not_found"))));
}
TEST(DiagnosticsTest, DeduplicatedClangTidyDiagnostics) {
@ -255,7 +255,7 @@ TEST(DiagnosticsTest, DeduplicatedClangTidyDiagnostics) {
ifTidyChecks(UnorderedElementsAre(::testing::AllOf(
Diag(Test.range(),
"floating point literal has suffix 'f', which is not uppercase"),
DiagSource(Diag::ClangTidy)))));
diagSource(Diag::ClangTidy)))));
Test = Annotations(R"cpp(
template<typename T>
@ -275,7 +275,7 @@ TEST(DiagnosticsTest, DeduplicatedClangTidyDiagnostics) {
ifTidyChecks(UnorderedElementsAre(::testing::AllOf(
Diag(Test.range(),
"floating point literal has suffix 'f', which is not uppercase"),
DiagSource(Diag::ClangTidy)))));
diagSource(Diag::ClangTidy)))));
}
TEST(DiagnosticsTest, ClangTidy) {
@ -312,9 +312,9 @@ TEST(DiagnosticsTest, ClangTidy) {
AllOf(Diag(Test.range("deprecated"),
"inclusion of deprecated C++ header 'assert.h'; consider "
"using 'cassert' instead"),
DiagSource(Diag::ClangTidy),
DiagName("modernize-deprecated-headers"),
WithFix(Fix(Test.range("deprecated"), "<cassert>",
diagSource(Diag::ClangTidy),
diagName("modernize-deprecated-headers"),
withFix(Fix(Test.range("deprecated"), "<cassert>",
"change '\"assert.h\"' to '<cassert>'"))),
Diag(Test.range("doubled"),
"suspicious usage of 'sizeof(sizeof(...))'"),
@ -322,16 +322,16 @@ TEST(DiagnosticsTest, ClangTidy) {
"side effects in the 1st macro argument 'X' are "
"repeated in "
"macro expansion"),
DiagSource(Diag::ClangTidy),
DiagName("bugprone-macro-repeated-side-effects"),
WithNote(Diag(Test.range("macrodef"),
diagSource(Diag::ClangTidy),
diagName("bugprone-macro-repeated-side-effects"),
withNote(Diag(Test.range("macrodef"),
"macro 'SQUARE' defined here"))),
AllOf(Diag(Test.range("main"),
"use a trailing return type for this function"),
DiagSource(Diag::ClangTidy),
DiagName("modernize-use-trailing-return-type"),
diagSource(Diag::ClangTidy),
diagName("modernize-use-trailing-return-type"),
// Verify there's no "[check-name]" suffix in the message.
WithFix(FixMessage(
withFix(fixMessage(
"use a trailing return type for this function"))),
Diag(Test.range("foo"),
"function 'foo' is within a recursive call chain"),
@ -353,7 +353,7 @@ TEST(DiagnosticsTest, ClangTidyEOF) {
*TU.build().getDiagnostics(),
ifTidyChecks(Contains(
AllOf(Diag(Test.range(), "#includes are not sorted properly"),
DiagSource(Diag::ClangTidy), DiagName("llvm-include-order")))));
diagSource(Diag::ClangTidy), diagName("llvm-include-order")))));
}
TEST(DiagnosticTest, TemplatesInHeaders) {
@ -371,7 +371,7 @@ TEST(DiagnosticTest, TemplatesInHeaders) {
*TU.build().getDiagnostics(),
ElementsAre(AllOf(
Diag(Main.range(), "in template: base specifier must name a class"),
WithNote(Diag(Header.range(), "error occurred here"),
withNote(Diag(Header.range(), "error occurred here"),
Diag(Main.range(), "in instantiation of template class "
"'Derived<int>' requested here")))));
}
@ -425,7 +425,7 @@ TEST(DiagnosticTest, NoMultipleDiagnosticInFlight) {
*TU.build().getDiagnostics(),
ifTidyChecks(UnorderedElementsAre(::testing::AllOf(
Diag(Main.range(), "use range-based for loop instead"),
DiagSource(Diag::ClangTidy), DiagName("modernize-loop-convert")))));
diagSource(Diag::ClangTidy), diagName("modernize-loop-convert")))));
}
TEST(DiagnosticTest, RespectsDiagnosticConfig) {
@ -494,8 +494,8 @@ TEST(DiagnosticTest, ClangTidySuppressionComment) {
ifTidyChecks(UnorderedElementsAre(::testing::AllOf(
Diag(Main.range(), "result of integer division used in a floating "
"point context; possible loss of precision"),
DiagSource(Diag::ClangTidy),
DiagName("bugprone-integer-division")))));
diagSource(Diag::ClangTidy),
diagName("bugprone-integer-division")))));
}
TEST(DiagnosticTest, ClangTidyWarningAsError) {
@ -513,8 +513,8 @@ TEST(DiagnosticTest, ClangTidyWarningAsError) {
ifTidyChecks(UnorderedElementsAre(::testing::AllOf(
Diag(Main.range(), "result of integer division used in a floating "
"point context; possible loss of precision"),
DiagSource(Diag::ClangTidy), DiagName("bugprone-integer-division"),
DiagSeverity(DiagnosticsEngine::Error)))));
diagSource(Diag::ClangTidy), diagName("bugprone-integer-division"),
diagSeverity(DiagnosticsEngine::Error)))));
}
TidyProvider addClangArgs(std::vector<llvm::StringRef> ExtraArgs) {
@ -535,8 +535,8 @@ TEST(DiagnosticTest, ClangTidyEnablesClangWarning) {
// This is always emitted as a clang warning, not a clang-tidy diagnostic.
auto UnusedFooWarning =
AllOf(Diag(Main.range(), "unused function 'foo'"),
DiagName("-Wunused-function"), DiagSource(Diag::Clang),
DiagSeverity(DiagnosticsEngine::Warning));
diagName("-Wunused-function"), diagSource(Diag::Clang),
diagSeverity(DiagnosticsEngine::Warning));
// Check the -Wunused warning isn't initially on.
EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
@ -554,19 +554,19 @@ TEST(DiagnosticTest, ClangTidyEnablesClangWarning) {
TU.ExtraArgs = {"-Werror"};
TU.ClangTidyProvider = addClangArgs({"-Wunused"});
EXPECT_THAT(*TU.build().getDiagnostics(),
ElementsAre(DiagSeverity(DiagnosticsEngine::Warning)));
ElementsAre(diagSeverity(DiagnosticsEngine::Warning)));
// But clang-tidy extra args won't *downgrade* errors to warnings either.
TU.ExtraArgs = {"-Wunused", "-Werror"};
TU.ClangTidyProvider = addClangArgs({"-Wunused"});
EXPECT_THAT(*TU.build().getDiagnostics(),
ElementsAre(DiagSeverity(DiagnosticsEngine::Error)));
ElementsAre(diagSeverity(DiagnosticsEngine::Error)));
// FIXME: we're erroneously downgrading the whole group, this should be Error.
TU.ExtraArgs = {"-Wunused-function", "-Werror"};
TU.ClangTidyProvider = addClangArgs({"-Wunused"});
EXPECT_THAT(*TU.build().getDiagnostics(),
ElementsAre(DiagSeverity(DiagnosticsEngine::Warning)));
ElementsAre(diagSeverity(DiagnosticsEngine::Warning)));
// This looks silly, but it's the typical result if a warning is enabled by a
// high-level .clang-tidy file and disabled by a low-level one.
@ -603,7 +603,7 @@ TEST(DiagnosticTest, LongFixMessages) {
TestTU TU = TestTU::withCode(Source.code());
EXPECT_THAT(
*TU.build().getDiagnostics(),
ElementsAre(WithFix(Fix(
ElementsAre(withFix(Fix(
Source.range(),
"somereallyreallyreallyreallyreallyreallyreallyreallylongidentifier",
"change 'omereallyreallyreallyreallyreallyreallyreallyreall…' to "
@ -619,7 +619,7 @@ n]] = 10; // error-ok
)cpp");
TU.Code = std::string(Source.code());
EXPECT_THAT(*TU.build().getDiagnostics(),
ElementsAre(WithFix(
ElementsAre(withFix(
Fix(Source.range(), "ident", "change 'ide\\…' to 'ident'"))));
}
@ -629,7 +629,7 @@ TEST(DiagnosticTest, NewLineFixMessage) {
TU.ExtraArgs = {"-Wnewline-eof"};
EXPECT_THAT(
*TU.build().getDiagnostics(),
ElementsAre(WithFix((Fix(Source.range(), "\n", "insert '\\n'")))));
ElementsAre(withFix((Fix(Source.range(), "\n", "insert '\\n'")))));
}
TEST(DiagnosticTest, ClangTidySuppressionCommentTrumpsWarningAsError) {
@ -714,7 +714,7 @@ TEST(DiagnosticsTest, RecursivePreamble) {
)cpp");
TU.Filename = "foo.h";
EXPECT_THAT(*TU.build().getDiagnostics(),
ElementsAre(DiagName("pp_including_mainfile_in_preamble")));
ElementsAre(diagName("pp_including_mainfile_in_preamble")));
EXPECT_THAT(TU.build().getLocalTopLevelDecls(), SizeIs(1));
}
@ -743,7 +743,7 @@ TEST(DiagnosticsTest, RecursivePreambleIfndefGuard) {
TU.Filename = "foo.h";
// FIXME: should be no errors here.
EXPECT_THAT(*TU.build().getDiagnostics(),
ElementsAre(DiagName("pp_including_mainfile_in_preamble")));
ElementsAre(diagName("pp_including_mainfile_in_preamble")));
EXPECT_THAT(TU.build().getLocalTopLevelDecls(), SizeIs(1));
}
@ -777,7 +777,7 @@ TEST(DiagnosticsTest, NoFixItInMacro) {
auto TU = TestTU::withCode(Test.code());
EXPECT_THAT(*TU.build().getDiagnostics(),
ElementsAre(AllOf(Diag(Test.range(), "'main' must return 'int'"),
Not(WithFix(_)))));
Not(withFix(_)))));
}
TEST(DiagnosticsTest, PragmaSystemHeader) {
@ -875,8 +875,8 @@ main.cpp:2:3: error: something terrible happened)";
EXPECT_THAT(
LSPDiags,
ElementsAre(Pair(EqualToLSPDiag(MainLSP), ElementsAre(EqualToFix(F))),
Pair(EqualToLSPDiag(NoteInMainLSP), IsEmpty())));
ElementsAre(Pair(equalToLSPDiag(MainLSP), ElementsAre(equalToFix(F))),
Pair(equalToLSPDiag(NoteInMainLSP), IsEmpty())));
EXPECT_EQ(LSPDiags[0].first.code, "undeclared_var_use");
EXPECT_EQ(LSPDiags[0].first.source, "clang");
EXPECT_EQ(LSPDiags[1].first.code, "");
@ -902,8 +902,8 @@ main.cpp:2:3: error: something terrible happened)";
NoteInHeaderDRI.location.range = NoteInHeader.Range;
NoteInHeaderDRI.location.uri = HeaderFile;
MainLSP.relatedInformation = {NoteInMainDRI, NoteInHeaderDRI};
EXPECT_THAT(LSPDiags, ElementsAre(Pair(EqualToLSPDiag(MainLSP),
ElementsAre(EqualToFix(F)))));
EXPECT_THAT(LSPDiags, ElementsAre(Pair(equalToLSPDiag(MainLSP),
ElementsAre(equalToFix(F)))));
}
struct SymbolWithHeader {
@ -967,8 +967,8 @@ TEST(IncludeFixerTest, IncompleteType) {
TU.Code = Main.code().str() + "\n // error-ok";
EXPECT_THAT(
*TU.build().getDiagnostics(),
ElementsAre(AllOf(DiagName(Case.first), HasRange(Main.range()),
WithFix(Fix(Range{}, "#include \"x.h\"\n",
ElementsAre(AllOf(diagName(Case.first), hasRange(Main.range()),
withFix(Fix(Range{}, "#include \"x.h\"\n",
"Include \"x.h\" for symbol ns::X")))))
<< Case.second;
}
@ -998,8 +998,8 @@ TEST(IncludeFixerTest, IncompleteEnum) {
Annotations Main(Case.second);
TU.Code = Main.code().str() + "\n // error-ok";
EXPECT_THAT(*TU.build().getDiagnostics(),
Contains(AllOf(DiagName(Case.first), HasRange(Main.range()),
WithFix(Fix(Range{}, "#include \"x.h\"\n",
Contains(AllOf(diagName(Case.first), hasRange(Main.range()),
withFix(Fix(Range{}, "#include \"x.h\"\n",
"Include \"x.h\" for symbol X")))))
<< Case.second;
}
@ -1065,29 +1065,29 @@ using Type = ns::$template[[Foo]]<int>;
*TU.build().getDiagnostics(),
UnorderedElementsAre(
AllOf(Diag(Test.range("unqualified1"), "unknown type name 'X'"),
DiagName("unknown_typename"),
WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
diagName("unknown_typename"),
withFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
"Include \"x.h\" for symbol ns::X"))),
Diag(Test.range("unqualified2"), "use of undeclared identifier 'X'"),
AllOf(Diag(Test.range("qualified1"),
"no type named 'X' in namespace 'ns'"),
DiagName("typename_nested_not_found"),
WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
diagName("typename_nested_not_found"),
withFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
"Include \"x.h\" for symbol ns::X"))),
AllOf(Diag(Test.range("qualified2"),
"no member named 'X' in namespace 'ns'"),
DiagName("no_member"),
WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
diagName("no_member"),
withFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
"Include \"x.h\" for symbol ns::X"))),
AllOf(Diag(Test.range("global"),
"no type named 'Global' in the global namespace"),
DiagName("typename_nested_not_found"),
WithFix(Fix(Test.range("insert"), "#include \"global.h\"\n",
diagName("typename_nested_not_found"),
withFix(Fix(Test.range("insert"), "#include \"global.h\"\n",
"Include \"global.h\" for symbol Global"))),
AllOf(Diag(Test.range("template"),
"no template named 'Foo' in namespace 'ns'"),
DiagName("no_member_template"),
WithFix(Fix(Test.range("insert"), "#include \"foo.h\"\n",
diagName("no_member_template"),
withFix(Fix(Test.range("insert"), "#include \"foo.h\"\n",
"Include \"foo.h\" for symbol ns::Foo")))));
}
@ -1110,8 +1110,8 @@ void foo() {
EXPECT_THAT(*TU.build().getDiagnostics(),
UnorderedElementsAre(AllOf(
Diag(Test.range("unqualified"), "unknown type name 'X'"),
DiagName("unknown_typename"),
WithFix(Fix(Test.range("insert"), "#include \"a.h\"\n",
diagName("unknown_typename"),
withFix(Fix(Test.range("insert"), "#include \"a.h\"\n",
"Include \"a.h\" for symbol na::X"),
Fix(Test.range("insert"), "#include \"b.h\"\n",
"Include \"b.h\" for symbol na::nb::X")))));
@ -1190,8 +1190,8 @@ void g() { ns::$[[scope]]::X_Y(); }
*TU.build().getDiagnostics(),
UnorderedElementsAre(
AllOf(Diag(Test.range(), "no member named 'scope' in namespace 'ns'"),
DiagName("no_member"),
WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
diagName("no_member"),
withFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
"Include \"x.h\" for symbol ns::scope::X_Y")))));
}
@ -1219,25 +1219,25 @@ void f() {
UnorderedElementsAre(
AllOf(Diag(Test.range("q1"), "use of undeclared identifier 'clangd'; "
"did you mean 'clang'?"),
DiagName("undeclared_var_use_suggest"),
WithFix(_, // change clangd to clang
diagName("undeclared_var_use_suggest"),
withFix(_, // change clangd to clang
Fix(Test.range("insert"), "#include \"x.h\"\n",
"Include \"x.h\" for symbol clang::clangd::X"))),
AllOf(Diag(Test.range("x"), "no type named 'X' in namespace 'clang'"),
DiagName("typename_nested_not_found"),
WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
diagName("typename_nested_not_found"),
withFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
"Include \"x.h\" for symbol clang::clangd::X"))),
AllOf(
Diag(Test.range("q2"), "use of undeclared identifier 'clangd'; "
"did you mean 'clang'?"),
DiagName("undeclared_var_use_suggest"),
WithFix(_, // change clangd to clang
diagName("undeclared_var_use_suggest"),
withFix(_, // change clangd to clang
Fix(Test.range("insert"), "#include \"y.h\"\n",
"Include \"y.h\" for symbol clang::clangd::ns::Y"))),
AllOf(Diag(Test.range("ns"),
"no member named 'ns' in namespace 'clang'"),
DiagName("no_member"),
WithFix(
diagName("no_member"),
withFix(
Fix(Test.range("insert"), "#include \"y.h\"\n",
"Include \"y.h\" for symbol clang::clangd::ns::Y")))));
}
@ -1258,8 +1258,8 @@ namespace c {
EXPECT_THAT(*TU.build().getDiagnostics(),
UnorderedElementsAre(AllOf(
Diag(Test.range(), "no type named 'X' in namespace 'a'"),
DiagName("typename_nested_not_found"),
WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
diagName("typename_nested_not_found"),
withFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
"Include \"x.h\" for symbol a::X")))));
}
@ -1301,7 +1301,7 @@ TEST(IncludeFixerTest, HeaderNamedInDiag) {
ElementsAre(AllOf(
Diag(Test.range(), "implicitly declaring library function 'printf' "
"with type 'int (const char *, ...)'"),
WithFix(Fix(Test.range("insert"), "#include <stdio.h>\n",
withFix(Fix(Test.range("insert"), "#include <stdio.h>\n",
"Include <stdio.h> for symbol printf")))));
}
@ -1326,7 +1326,7 @@ TEST(IncludeFixerTest, CImplicitFunctionDecl) {
ElementsAre(AllOf(
Diag(Test.range(),
"implicit declaration of function 'foo' is invalid in C99"),
WithFix(Fix(Range{}, "#include \"foo.h\"\n",
withFix(Fix(Range{}, "#include \"foo.h\"\n",
"Include \"foo.h\" for symbol foo")))));
}
@ -1341,7 +1341,7 @@ TEST(DiagsInHeaders, DiagInsideHeader) {
UnorderedElementsAre(AllOf(
Diag(Main.range(), "in included file: C++ requires a "
"type specifier for all declarations"),
WithNote(Diag(Header.range(), "error occurred here")))));
withNote(Diag(Header.range(), "error occurred here")))));
}
TEST(DiagsInHeaders, DiagInTransitiveInclude) {
@ -1448,7 +1448,7 @@ TEST(DiagsInHeaders, OnlyErrorOrFatal) {
UnorderedElementsAre(AllOf(
Diag(Main.range(), "in included file: C++ requires "
"a type specifier for all declarations"),
WithNote(Diag(Header.range(), "error occurred here")))));
withNote(Diag(Header.range(), "error occurred here")))));
}
TEST(DiagsInHeaders, OnlyDefaultErrorOrFatal) {
@ -1479,7 +1479,7 @@ TEST(DiagsInHeaders, FromNonWrittenSources) {
UnorderedElementsAre(AllOf(
Diag(Main.range(),
"in included file: use of undeclared identifier 'NOOO'"),
WithNote(Diag(Header.range(), "error occurred here")))));
withNote(Diag(Header.range(), "error occurred here")))));
}
TEST(DiagsInHeaders, ErrorFromMacroExpansion) {
@ -1606,9 +1606,9 @@ TEST(Diagnostics, Tags) {
EXPECT_THAT(*TU.build().getDiagnostics(),
UnorderedElementsAre(
AllOf(Diag(Test.range("unused"), "unused variable 'x'"),
WithTag(DiagnosticTag::Unnecessary)),
withTag(DiagnosticTag::Unnecessary)),
AllOf(Diag(Test.range("deprecated"), "'bar' is deprecated"),
WithTag(DiagnosticTag::Deprecated))));
withTag(DiagnosticTag::Deprecated))));
}
TEST(DiagnosticsTest, IncludeCleaner) {
@ -1644,8 +1644,8 @@ $fix[[ $diag[[#include "unused.h"]]
*TU.build().getDiagnostics(),
UnorderedElementsAre(AllOf(
Diag(Test.range("diag"), "included header unused.h is not used"),
WithTag(DiagnosticTag::Unnecessary), DiagSource(Diag::Clangd),
WithFix(Fix(Test.range("fix"), "", "remove #include directive")))));
withTag(DiagnosticTag::Unnecessary), diagSource(Diag::Clangd),
withFix(Fix(Test.range("fix"), "", "remove #include directive")))));
Cfg.Diagnostics.SuppressAll = true;
WithContextValue SuppressAllWithCfg(Config::Key, std::move(Cfg));
EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());

View File

@ -20,7 +20,7 @@ using testing::Contains;
using testing::Not;
using testing::SizeIs;
MATCHER_P(WithDetail, str, "") { return arg.detail == str; }
MATCHER_P(withDetail, str, "") { return arg.detail == str; }
TEST(DumpASTTests, BasicInfo) {
std::pair</*Code=*/std::string, /*Expected=*/std::string> Cases[] = {
@ -168,8 +168,8 @@ TEST(DumpASTTests, NoRange) {
auto Node = dumpAST(
DynTypedNode::create(*AST.getASTContext().getTranslationUnitDecl()),
AST.getTokens(), AST.getASTContext());
ASSERT_THAT(Node.children, Contains(WithDetail("varFromSource")));
ASSERT_THAT(Node.children, Not(Contains(WithDetail("funcFromHeader"))));
ASSERT_THAT(Node.children, Contains(withDetail("varFromSource")));
ASSERT_THAT(Node.children, Not(Contains(withDetail("funcFromHeader"))));
EXPECT_THAT(Node.arcana, testing::StartsWith("TranslationUnitDecl "));
ASSERT_FALSE(Node.range.hasValue())
<< "Expected no range for translation unit";

View File

@ -41,7 +41,7 @@ protected:
/// An overload for convenience.
llvm::Optional<OpaqueType> fromCompletionResult(const NamedDecl *D) {
return OpaqueType::fromCompletionResult(
ASTCtx(), CodeCompletionResult(D, CCP_Declaration));
astCtx(), CodeCompletionResult(D, CCP_Declaration));
}
/// A set of DeclNames whose type match each other computed by
@ -49,7 +49,7 @@ protected:
using EquivClass = std::set<std::string>;
Matcher<std::map<std::string, EquivClass>>
ClassesAre(llvm::ArrayRef<EquivClass> Classes) {
classesAre(llvm::ArrayRef<EquivClass> Classes) {
using MapEntry = std::map<std::string, EquivClass>::value_type;
std::vector<Matcher<MapEntry>> Elements;
@ -65,13 +65,13 @@ protected:
buildEquivClasses(llvm::ArrayRef<llvm::StringRef> DeclNames) {
std::map<std::string, EquivClass> Classes;
for (llvm::StringRef Name : DeclNames) {
auto Type = OpaqueType::fromType(ASTCtx(), typeOf(Name));
auto Type = OpaqueType::fromType(astCtx(), typeOf(Name));
Classes[std::string(Type->raw())].insert(std::string(Name));
}
return Classes;
}
ASTContext &ASTCtx() { return AST->getASTContext(); }
ASTContext &astCtx() { return AST->getASTContext(); }
private:
// Set after calling build().
@ -101,7 +101,7 @@ TEST_F(ExpectedTypeConversionTest, BasicTypes) {
EXPECT_THAT(buildEquivClasses({"b", "i", "ui", "ll", "f", "d", "iptr", "bptr",
"user_type"}),
ClassesAre({{"b"},
classesAre({{"b"},
{"i", "ui", "ll"},
{"f", "d"},
{"iptr"},
@ -140,10 +140,10 @@ TEST_F(ExpectedTypeConversionTest, FunctionReturns) {
int* int_ptr;
)cpp");
OpaqueType IntTy = *OpaqueType::fromType(ASTCtx(), typeOf("int_"));
OpaqueType IntTy = *OpaqueType::fromType(astCtx(), typeOf("int_"));
EXPECT_EQ(fromCompletionResult(decl("returns_int")), IntTy);
OpaqueType IntPtrTy = *OpaqueType::fromType(ASTCtx(), typeOf("int_ptr"));
OpaqueType IntPtrTy = *OpaqueType::fromType(astCtx(), typeOf("int_ptr"));
EXPECT_EQ(fromCompletionResult(decl("returns_ptr")), IntPtrTy);
}
@ -162,7 +162,7 @@ T* var_dependent = nullptr;
int* int_ptr_;
)cpp");
auto IntPtrTy = *OpaqueType::fromType(ASTCtx(), typeOf("int_ptr_"));
auto IntPtrTy = *OpaqueType::fromType(astCtx(), typeOf("int_ptr_"));
EXPECT_EQ(fromCompletionResult(decl("returns_not_dependent")), IntPtrTy);
EXPECT_EQ(fromCompletionResult(decl("returns_dependent")), llvm::None);

View File

@ -46,28 +46,28 @@ using ::testing::IsEmpty;
using ::testing::Pair;
using ::testing::UnorderedElementsAre;
MATCHER_P(RefRange, Range, "") {
MATCHER_P(refRange, Range, "") {
return std::make_tuple(arg.Location.Start.line(), arg.Location.Start.column(),
arg.Location.End.line(), arg.Location.End.column()) ==
std::make_tuple(Range.start.line, Range.start.character,
Range.end.line, Range.end.character);
}
MATCHER_P(FileURI, F, "") { return llvm::StringRef(arg.Location.FileURI) == F; }
MATCHER_P(DeclURI, U, "") {
MATCHER_P(fileURI, F, "") { return llvm::StringRef(arg.Location.FileURI) == F; }
MATCHER_P(declURI, U, "") {
return llvm::StringRef(arg.CanonicalDeclaration.FileURI) == U;
}
MATCHER_P(DefURI, U, "") {
MATCHER_P(defURI, U, "") {
return llvm::StringRef(arg.Definition.FileURI) == U;
}
MATCHER_P(QName, N, "") { return (arg.Scope + arg.Name).str() == N; }
MATCHER_P(NumReferences, N, "") { return arg.References == N; }
MATCHER_P(qName, N, "") { return (arg.Scope + arg.Name).str() == N; }
MATCHER_P(numReferences, N, "") { return arg.References == N; }
MATCHER_P(hasOrign, O, "") { return bool(arg.Origin & O); }
namespace clang {
namespace clangd {
namespace {
::testing::Matcher<const RefSlab &>
RefsAre(std::vector<::testing::Matcher<Ref>> Matchers) {
refsAre(std::vector<::testing::Matcher<Ref>> Matchers) {
return ElementsAre(::testing::Pair(_, UnorderedElementsAreArray(Matchers)));
}
@ -80,8 +80,8 @@ Symbol symbol(llvm::StringRef ID) {
std::unique_ptr<SymbolSlab> numSlab(int Begin, int End) {
SymbolSlab::Builder Slab;
for (int i = Begin; i <= End; i++)
Slab.insert(symbol(std::to_string(i)));
for (int I = Begin; I <= End; I++)
Slab.insert(symbol(std::to_string(I)));
return std::make_unique<SymbolSlab>(std::move(Slab).build());
}
@ -108,9 +108,9 @@ TEST(FileSymbolsTest, UpdateAndGet) {
FS.update("f1", numSlab(1, 3), refSlab(SymbolID("1"), "f1.cc"), nullptr,
false);
EXPECT_THAT(runFuzzyFind(*FS.buildIndex(IndexType::Light), ""),
UnorderedElementsAre(QName("1"), QName("2"), QName("3")));
UnorderedElementsAre(qName("1"), qName("2"), qName("3")));
EXPECT_THAT(getRefs(*FS.buildIndex(IndexType::Light), SymbolID("1")),
RefsAre({FileURI("f1.cc")}));
refsAre({fileURI("f1.cc")}));
}
TEST(FileSymbolsTest, Overlap) {
@ -119,8 +119,8 @@ TEST(FileSymbolsTest, Overlap) {
FS.update("f2", numSlab(3, 5), nullptr, nullptr, false);
for (auto Type : {IndexType::Light, IndexType::Heavy})
EXPECT_THAT(runFuzzyFind(*FS.buildIndex(Type), ""),
UnorderedElementsAre(QName("1"), QName("2"), QName("3"),
QName("4"), QName("5")));
UnorderedElementsAre(qName("1"), qName("2"), qName("3"),
qName("4"), qName("5")));
}
TEST(FileSymbolsTest, MergeOverlap) {
@ -141,7 +141,7 @@ TEST(FileSymbolsTest, MergeOverlap) {
EXPECT_THAT(
runFuzzyFind(*FS.buildIndex(Type, DuplicateHandling::Merge), "x"),
UnorderedElementsAre(
AllOf(QName("x"), DeclURI("file:///x1"), DefURI("file:///x2"))));
AllOf(qName("x"), declURI("file:///x1"), defURI("file:///x2"))));
}
TEST(FileSymbolsTest, SnapshotAliveAfterRemove) {
@ -152,8 +152,8 @@ TEST(FileSymbolsTest, SnapshotAliveAfterRemove) {
auto Symbols = FS.buildIndex(IndexType::Light);
EXPECT_THAT(runFuzzyFind(*Symbols, ""),
UnorderedElementsAre(QName("1"), QName("2"), QName("3")));
EXPECT_THAT(getRefs(*Symbols, ID), RefsAre({FileURI("f1.cc")}));
UnorderedElementsAre(qName("1"), qName("2"), qName("3")));
EXPECT_THAT(getRefs(*Symbols, ID), refsAre({fileURI("f1.cc")}));
FS.update("f1", nullptr, nullptr, nullptr, false);
auto Empty = FS.buildIndex(IndexType::Light);
@ -161,8 +161,8 @@ TEST(FileSymbolsTest, SnapshotAliveAfterRemove) {
EXPECT_THAT(getRefs(*Empty, ID), ElementsAre());
EXPECT_THAT(runFuzzyFind(*Symbols, ""),
UnorderedElementsAre(QName("1"), QName("2"), QName("3")));
EXPECT_THAT(getRefs(*Symbols, ID), RefsAre({FileURI("f1.cc")}));
UnorderedElementsAre(qName("1"), qName("2"), qName("3")));
EXPECT_THAT(getRefs(*Symbols, ID), refsAre({fileURI("f1.cc")}));
}
// Adds Basename.cpp, which includes Basename.h, which contains Code.
@ -181,7 +181,7 @@ TEST(FileIndexTest, CustomizedURIScheme) {
FileIndex M;
update(M, "f", "class string {};");
EXPECT_THAT(runFuzzyFind(M, ""), ElementsAre(DeclURI("unittest:///f.h")));
EXPECT_THAT(runFuzzyFind(M, ""), ElementsAre(declURI("unittest:///f.h")));
}
TEST(FileIndexTest, IndexAST) {
@ -192,7 +192,7 @@ TEST(FileIndexTest, IndexAST) {
Req.Query = "";
Req.Scopes = {"ns::"};
EXPECT_THAT(runFuzzyFind(M, Req),
UnorderedElementsAre(QName("ns::f"), QName("ns::X")));
UnorderedElementsAre(qName("ns::f"), qName("ns::X")));
}
TEST(FileIndexTest, NoLocal) {
@ -201,7 +201,7 @@ TEST(FileIndexTest, NoLocal) {
EXPECT_THAT(
runFuzzyFind(M, ""),
UnorderedElementsAre(QName("ns"), QName("ns::f"), QName("ns::X")));
UnorderedElementsAre(qName("ns"), qName("ns::f"), qName("ns::X")));
}
TEST(FileIndexTest, IndexMultiASTAndDeduplicate) {
@ -213,7 +213,7 @@ TEST(FileIndexTest, IndexMultiASTAndDeduplicate) {
Req.Scopes = {"ns::"};
EXPECT_THAT(
runFuzzyFind(M, Req),
UnorderedElementsAre(QName("ns::f"), QName("ns::X"), QName("ns::ff")));
UnorderedElementsAre(qName("ns::f"), qName("ns::X"), qName("ns::ff")));
}
TEST(FileIndexTest, ClassMembers) {
@ -221,8 +221,8 @@ TEST(FileIndexTest, ClassMembers) {
update(M, "f1", "class X { static int m1; int m2; static void f(); };");
EXPECT_THAT(runFuzzyFind(M, ""),
UnorderedElementsAre(QName("X"), QName("X::m1"), QName("X::m2"),
QName("X::f")));
UnorderedElementsAre(qName("X"), qName("X::m1"), qName("X::m2"),
qName("X::f")));
}
TEST(FileIndexTest, IncludeCollected) {
@ -263,7 +263,7 @@ vector<Ty> make_vector(Arg A) {}
auto Symbols = runFuzzyFind(M, "");
EXPECT_THAT(Symbols,
UnorderedElementsAre(QName("vector"), QName("make_vector")));
UnorderedElementsAre(qName("vector"), qName("make_vector")));
auto It = Symbols.begin();
Symbol Vector = *It++;
Symbol MakeVector = *It++;
@ -327,8 +327,8 @@ TEST(FileIndexTest, RebuildWithPreamble) {
Req.Scopes = {"", "ns_in_header::"};
EXPECT_THAT(runFuzzyFind(Index, Req),
UnorderedElementsAre(QName("ns_in_header"),
QName("ns_in_header::func_in_header")));
UnorderedElementsAre(qName("ns_in_header"),
qName("ns_in_header::func_in_header")));
}
TEST(FileIndexTest, Refs) {
@ -362,10 +362,10 @@ TEST(FileIndexTest, Refs) {
Index.updateMain(testPath(Test2.Filename), AST);
EXPECT_THAT(getRefs(Index, Foo.ID),
RefsAre({AllOf(RefRange(MainCode.range("foo")),
FileURI("unittest:///test.cc")),
AllOf(RefRange(MainCode.range("foo")),
FileURI("unittest:///test2.cc"))}));
refsAre({AllOf(refRange(MainCode.range("foo")),
fileURI("unittest:///test.cc")),
AllOf(refRange(MainCode.range("foo")),
fileURI("unittest:///test2.cc"))}));
}
TEST(FileIndexTest, MacroRefs) {
@ -391,21 +391,21 @@ TEST(FileIndexTest, MacroRefs) {
auto HeaderMacro = findSymbol(Test.headerSymbols(), "HEADER_MACRO");
EXPECT_THAT(getRefs(Index, HeaderMacro.ID),
RefsAre({AllOf(RefRange(MainCode.range("ref1")),
FileURI("unittest:///test.cc"))}));
refsAre({AllOf(refRange(MainCode.range("ref1")),
fileURI("unittest:///test.cc"))}));
auto MainFileMacro = findSymbol(Test.headerSymbols(), "MAINFILE_MACRO");
EXPECT_THAT(getRefs(Index, MainFileMacro.ID),
RefsAre({AllOf(RefRange(MainCode.range("def2")),
FileURI("unittest:///test.cc")),
AllOf(RefRange(MainCode.range("ref2")),
FileURI("unittest:///test.cc"))}));
refsAre({AllOf(refRange(MainCode.range("def2")),
fileURI("unittest:///test.cc")),
AllOf(refRange(MainCode.range("ref2")),
fileURI("unittest:///test.cc"))}));
}
TEST(FileIndexTest, CollectMacros) {
FileIndex M;
update(M, "f", "#define CLANGD 1");
EXPECT_THAT(runFuzzyFind(M, ""), Contains(QName("CLANGD")));
EXPECT_THAT(runFuzzyFind(M, ""), Contains(qName("CLANGD")));
}
TEST(FileIndexTest, Relations) {
@ -470,7 +470,7 @@ TEST(FileIndexTest, ReferencesInMainFileWithPreamble) {
// Expect to see references in main file, references in headers are excluded
// because we only index main AST.
EXPECT_THAT(getRefs(Index, findSymbol(TU.headerSymbols(), "Foo").ID),
RefsAre({RefRange(Main.range())}));
refsAre({refRange(Main.range())}));
}
TEST(FileIndexTest, MergeMainFileSymbols) {
@ -489,8 +489,8 @@ TEST(FileIndexTest, MergeMainFileSymbols) {
auto Symbols = runFuzzyFind(Index, "");
// Check foo is merged, foo in Cpp wins (as we see the definition there).
EXPECT_THAT(Symbols, ElementsAre(AllOf(DeclURI("unittest:///foo.h"),
DefURI("unittest:///foo.cpp"),
EXPECT_THAT(Symbols, ElementsAre(AllOf(declURI("unittest:///foo.h"),
defURI("unittest:///foo.cpp"),
hasOrign(SymbolOrigin::Merge))));
}
@ -501,9 +501,9 @@ TEST(FileSymbolsTest, CountReferencesNoRefSlabs) {
EXPECT_THAT(
runFuzzyFind(*FS.buildIndex(IndexType::Light, DuplicateHandling::Merge),
""),
UnorderedElementsAre(AllOf(QName("1"), NumReferences(0u)),
AllOf(QName("2"), NumReferences(0u)),
AllOf(QName("3"), NumReferences(0u))));
UnorderedElementsAre(AllOf(qName("1"), numReferences(0u)),
AllOf(qName("2"), numReferences(0u)),
AllOf(qName("3"), numReferences(0u))));
}
TEST(FileSymbolsTest, CountReferencesWithRefSlabs) {
@ -523,9 +523,9 @@ TEST(FileSymbolsTest, CountReferencesWithRefSlabs) {
EXPECT_THAT(
runFuzzyFind(*FS.buildIndex(IndexType::Light, DuplicateHandling::Merge),
""),
UnorderedElementsAre(AllOf(QName("1"), NumReferences(1u)),
AllOf(QName("2"), NumReferences(1u)),
AllOf(QName("3"), NumReferences(1u))));
UnorderedElementsAre(AllOf(qName("1"), numReferences(1u)),
AllOf(qName("2"), numReferences(1u)),
AllOf(qName("3"), numReferences(1u))));
}
TEST(FileIndexTest, StalePreambleSymbolsDeleted) {
@ -539,7 +539,7 @@ TEST(FileIndexTest, StalePreambleSymbolsDeleted) {
M.updatePreamble(testPath(File.Filename), /*Version=*/"null",
AST.getASTContext(), AST.getPreprocessor(),
AST.getCanonicalIncludes());
EXPECT_THAT(runFuzzyFind(M, ""), UnorderedElementsAre(QName("a")));
EXPECT_THAT(runFuzzyFind(M, ""), UnorderedElementsAre(qName("a")));
File.Filename = "f2.cpp";
File.HeaderCode = "int b;";
@ -547,7 +547,7 @@ TEST(FileIndexTest, StalePreambleSymbolsDeleted) {
M.updatePreamble(testPath(File.Filename), /*Version=*/"null",
AST.getASTContext(), AST.getPreprocessor(),
AST.getCanonicalIncludes());
EXPECT_THAT(runFuzzyFind(M, ""), UnorderedElementsAre(QName("b")));
EXPECT_THAT(runFuzzyFind(M, ""), UnorderedElementsAre(qName("b")));
}
// Verifies that concurrent calls to updateMain don't "lose" any updates.
@ -644,7 +644,7 @@ TEST(FileShardedIndexTest, Sharding) {
{
auto Shard = ShardedIndex.getShard(AHeaderUri);
ASSERT_TRUE(Shard);
EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(QName("1")));
EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(qName("1")));
EXPECT_THAT(*Shard->Refs, IsEmpty());
EXPECT_THAT(
*Shard->Relations,
@ -658,7 +658,7 @@ TEST(FileShardedIndexTest, Sharding) {
{
auto Shard = ShardedIndex.getShard(BHeaderUri);
ASSERT_TRUE(Shard);
EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(QName("2")));
EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(qName("2")));
EXPECT_THAT(*Shard->Refs, IsEmpty());
EXPECT_THAT(
*Shard->Relations,
@ -673,7 +673,7 @@ TEST(FileShardedIndexTest, Sharding) {
{
auto Shard = ShardedIndex.getShard(BSourceUri);
ASSERT_TRUE(Shard);
EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(QName("2")));
EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(qName("2")));
EXPECT_THAT(*Shard->Refs, UnorderedElementsAre(Pair(Sym1.ID, _)));
EXPECT_THAT(*Shard->Relations, IsEmpty());
ASSERT_THAT(Shard->Sources->keys(),

View File

@ -28,20 +28,20 @@ using ::testing::IsEmpty;
using ::testing::UnorderedElementsAre;
// GMock helpers for matching SymbolInfos items.
MATCHER_P(QName, Name, "") {
MATCHER_P(qName, Name, "") {
if (arg.containerName.empty())
return arg.name == Name;
return (arg.containerName + "::" + arg.name) == Name;
}
MATCHER_P(WithName, N, "") { return arg.name == N; }
MATCHER_P(WithKind, Kind, "") { return arg.kind == Kind; }
MATCHER_P(WithDetail, Detail, "") { return arg.detail == Detail; }
MATCHER_P(SymRange, Range, "") { return arg.range == Range; }
MATCHER_P(withName, N, "") { return arg.name == N; }
MATCHER_P(withKind, Kind, "") { return arg.kind == Kind; }
MATCHER_P(withDetail, Detail, "") { return arg.detail == Detail; }
MATCHER_P(symRange, Range, "") { return arg.range == Range; }
// GMock helpers for matching DocumentSymbol.
MATCHER_P(SymNameRange, Range, "") { return arg.selectionRange == Range; }
MATCHER_P(symNameRange, Range, "") { return arg.selectionRange == Range; }
template <class... ChildMatchers>
::testing::Matcher<DocumentSymbol> Children(ChildMatchers... ChildrenM) {
::testing::Matcher<DocumentSymbol> children(ChildMatchers... ChildrenM) {
return Field(&DocumentSymbol::children, UnorderedElementsAre(ChildrenM...));
}
@ -63,7 +63,7 @@ TEST(WorkspaceSymbols, Macros) {
// indexSymbolKindToSymbolKind() currently maps macros
// to SymbolKind::String.
EXPECT_THAT(getSymbols(TU, "macro"),
ElementsAre(AllOf(QName("MACRO"), WithKind(SymbolKind::String))));
ElementsAre(AllOf(qName("MACRO"), withKind(SymbolKind::String))));
}
TEST(WorkspaceSymbols, NoLocals) {
@ -73,7 +73,7 @@ TEST(WorkspaceSymbols, NoLocals) {
struct LocalClass {};
int local_var;
})cpp";
EXPECT_THAT(getSymbols(TU, "l"), ElementsAre(QName("LocalClass")));
EXPECT_THAT(getSymbols(TU, "l"), ElementsAre(qName("LocalClass")));
EXPECT_THAT(getSymbols(TU, "p"), IsEmpty());
}
@ -90,9 +90,9 @@ TEST(WorkspaceSymbols, Globals) {
)cpp";
EXPECT_THAT(getSymbols(TU, "global"),
UnorderedElementsAre(
AllOf(QName("GlobalStruct"), WithKind(SymbolKind::Struct)),
AllOf(QName("global_func"), WithKind(SymbolKind::Function)),
AllOf(QName("global_var"), WithKind(SymbolKind::Variable))));
AllOf(qName("GlobalStruct"), withKind(SymbolKind::Struct)),
AllOf(qName("global_func"), withKind(SymbolKind::Function)),
AllOf(qName("global_var"), withKind(SymbolKind::Variable))));
}
TEST(WorkspaceSymbols, Unnamed) {
@ -105,11 +105,11 @@ TEST(WorkspaceSymbols, Unnamed) {
#include "foo.h"
)cpp";
EXPECT_THAT(getSymbols(TU, "UnnamedStruct"),
ElementsAre(AllOf(QName("UnnamedStruct"),
WithKind(SymbolKind::Variable))));
ElementsAre(AllOf(qName("UnnamedStruct"),
withKind(SymbolKind::Variable))));
EXPECT_THAT(getSymbols(TU, "InUnnamed"),
ElementsAre(AllOf(QName("(anonymous struct)::InUnnamed"),
WithKind(SymbolKind::Field))));
ElementsAre(AllOf(qName("(anonymous struct)::InUnnamed"),
withKind(SymbolKind::Field))));
}
TEST(WorkspaceSymbols, InMainFile) {
@ -119,7 +119,7 @@ TEST(WorkspaceSymbols, InMainFile) {
static void test2() {}
)cpp";
EXPECT_THAT(getSymbols(TU, "test"),
ElementsAre(QName("test"), QName("test2")));
ElementsAre(qName("test"), qName("test2")));
}
TEST(WorkspaceSymbols, Namespaces) {
@ -140,30 +140,30 @@ TEST(WorkspaceSymbols, Namespaces) {
)cpp";
EXPECT_THAT(getSymbols(TU, "a"),
UnorderedElementsAre(
QName("ans1"), QName("ans1::ai1"), QName("ans1::ans2"),
QName("ans1::ans2::ai2"), QName("ans1::ans2::ans3"),
QName("ans1::ans2::ans3::ai3")));
EXPECT_THAT(getSymbols(TU, "::"), ElementsAre(QName("ans1")));
EXPECT_THAT(getSymbols(TU, "::a"), ElementsAre(QName("ans1")));
qName("ans1"), qName("ans1::ai1"), qName("ans1::ans2"),
qName("ans1::ans2::ai2"), qName("ans1::ans2::ans3"),
qName("ans1::ans2::ans3::ai3")));
EXPECT_THAT(getSymbols(TU, "::"), ElementsAre(qName("ans1")));
EXPECT_THAT(getSymbols(TU, "::a"), ElementsAre(qName("ans1")));
EXPECT_THAT(getSymbols(TU, "ans1::"),
UnorderedElementsAre(QName("ans1::ai1"), QName("ans1::ans2"),
QName("ans1::ans2::ai2"),
QName("ans1::ans2::ans3"),
QName("ans1::ans2::ans3::ai3")));
UnorderedElementsAre(qName("ans1::ai1"), qName("ans1::ans2"),
qName("ans1::ans2::ai2"),
qName("ans1::ans2::ans3"),
qName("ans1::ans2::ans3::ai3")));
EXPECT_THAT(getSymbols(TU, "ans2::"),
UnorderedElementsAre(QName("ans1::ans2::ai2"),
QName("ans1::ans2::ans3"),
QName("ans1::ans2::ans3::ai3")));
EXPECT_THAT(getSymbols(TU, "::ans1"), ElementsAre(QName("ans1")));
UnorderedElementsAre(qName("ans1::ans2::ai2"),
qName("ans1::ans2::ans3"),
qName("ans1::ans2::ans3::ai3")));
EXPECT_THAT(getSymbols(TU, "::ans1"), ElementsAre(qName("ans1")));
EXPECT_THAT(getSymbols(TU, "::ans1::"),
UnorderedElementsAre(QName("ans1::ai1"), QName("ans1::ans2")));
EXPECT_THAT(getSymbols(TU, "::ans1::ans2"), ElementsAre(QName("ans1::ans2")));
UnorderedElementsAre(qName("ans1::ai1"), qName("ans1::ans2")));
EXPECT_THAT(getSymbols(TU, "::ans1::ans2"), ElementsAre(qName("ans1::ans2")));
EXPECT_THAT(getSymbols(TU, "::ans1::ans2::"),
ElementsAre(QName("ans1::ans2::ai2"), QName("ans1::ans2::ans3")));
ElementsAre(qName("ans1::ans2::ai2"), qName("ans1::ans2::ans3")));
// Ensure sub-sequence matching works.
EXPECT_THAT(getSymbols(TU, "ans1::ans3::ai"),
UnorderedElementsAre(QName("ans1::ans2::ans3::ai3")));
UnorderedElementsAre(qName("ans1::ans2::ans3::ai3")));
}
TEST(WorkspaceSymbols, AnonymousNamespace) {
@ -173,7 +173,7 @@ TEST(WorkspaceSymbols, AnonymousNamespace) {
void test() {}
}
)cpp";
EXPECT_THAT(getSymbols(TU, "test"), ElementsAre(QName("test")));
EXPECT_THAT(getSymbols(TU, "test"), ElementsAre(qName("test")));
}
TEST(WorkspaceSymbols, MultiFile) {
@ -191,7 +191,7 @@ TEST(WorkspaceSymbols, MultiFile) {
#include "foo2.h"
)cpp";
EXPECT_THAT(getSymbols(TU, "foo"),
UnorderedElementsAre(QName("foo"), QName("foo2")));
UnorderedElementsAre(qName("foo"), qName("foo2")));
}
TEST(WorkspaceSymbols, GlobalNamespaceQueries) {
@ -212,13 +212,13 @@ TEST(WorkspaceSymbols, GlobalNamespaceQueries) {
)cpp";
EXPECT_THAT(getSymbols(TU, "::"),
UnorderedElementsAre(
AllOf(QName("Foo"), WithKind(SymbolKind::Class)),
AllOf(QName("foo"), WithKind(SymbolKind::Function)),
AllOf(QName("ns"), WithKind(SymbolKind::Namespace))));
AllOf(qName("Foo"), withKind(SymbolKind::Class)),
AllOf(qName("foo"), withKind(SymbolKind::Function)),
AllOf(qName("ns"), withKind(SymbolKind::Namespace))));
EXPECT_THAT(getSymbols(TU, ":"), IsEmpty());
EXPECT_THAT(getSymbols(TU, ""),
UnorderedElementsAre(QName("foo"), QName("Foo"), QName("Foo::a"),
QName("ns"), QName("ns::foo2")));
UnorderedElementsAre(qName("foo"), qName("Foo"), qName("Foo::a"),
qName("ns"), qName("ns::foo2")));
}
TEST(WorkspaceSymbols, Enums) {
@ -248,18 +248,18 @@ TEST(WorkspaceSymbols, Enums) {
TU.Code = R"cpp(
#include "foo.h"
)cpp";
EXPECT_THAT(getSymbols(TU, "Red"), ElementsAre(QName("Red")));
EXPECT_THAT(getSymbols(TU, "::Red"), ElementsAre(QName("Red")));
EXPECT_THAT(getSymbols(TU, "Green"), ElementsAre(QName("Green")));
EXPECT_THAT(getSymbols(TU, "Green"), ElementsAre(QName("Green")));
EXPECT_THAT(getSymbols(TU, "Red"), ElementsAre(qName("Red")));
EXPECT_THAT(getSymbols(TU, "::Red"), ElementsAre(qName("Red")));
EXPECT_THAT(getSymbols(TU, "Green"), ElementsAre(qName("Green")));
EXPECT_THAT(getSymbols(TU, "Green"), ElementsAre(qName("Green")));
EXPECT_THAT(getSymbols(TU, "Color2::Yellow"),
ElementsAre(QName("Color2::Yellow")));
EXPECT_THAT(getSymbols(TU, "Yellow"), ElementsAre(QName("Color2::Yellow")));
ElementsAre(qName("Color2::Yellow")));
EXPECT_THAT(getSymbols(TU, "Yellow"), ElementsAre(qName("Color2::Yellow")));
EXPECT_THAT(getSymbols(TU, "ns::Black"), ElementsAre(QName("ns::Black")));
EXPECT_THAT(getSymbols(TU, "ns::Blue"), ElementsAre(QName("ns::Blue")));
EXPECT_THAT(getSymbols(TU, "ns::Black"), ElementsAre(qName("ns::Black")));
EXPECT_THAT(getSymbols(TU, "ns::Blue"), ElementsAre(qName("ns::Blue")));
EXPECT_THAT(getSymbols(TU, "ns::Color4::White"),
ElementsAre(QName("ns::Color4::White")));
ElementsAre(qName("ns::Color4::White")));
}
TEST(WorkspaceSymbols, Ranking) {
@ -271,7 +271,7 @@ TEST(WorkspaceSymbols, Ranking) {
TU.Code = R"cpp(
#include "foo.h"
)cpp";
EXPECT_THAT(getSymbols(TU, "::"), ElementsAre(QName("func"), QName("ns")));
EXPECT_THAT(getSymbols(TU, "::"), ElementsAre(qName("func"), qName("ns")));
}
TEST(WorkspaceSymbols, RankingPartialNamespace) {
@ -282,7 +282,7 @@ TEST(WorkspaceSymbols, RankingPartialNamespace) {
}
namespace ns2 { struct FooB {}; })cpp";
EXPECT_THAT(getSymbols(TU, "ns2::f"),
ElementsAre(QName("ns2::FooB"), QName("ns1::ns2::Foo")));
ElementsAre(qName("ns2::FooB"), qName("ns1::ns2::Foo")));
}
TEST(WorkspaceSymbols, WithLimit) {
@ -297,10 +297,10 @@ TEST(WorkspaceSymbols, WithLimit) {
// Foo is higher ranked because of exact name match.
EXPECT_THAT(getSymbols(TU, "foo"),
UnorderedElementsAre(
AllOf(QName("foo"), WithKind(SymbolKind::Variable)),
AllOf(QName("foo2"), WithKind(SymbolKind::Variable))));
AllOf(qName("foo"), withKind(SymbolKind::Variable)),
AllOf(qName("foo2"), withKind(SymbolKind::Variable))));
EXPECT_THAT(getSymbols(TU, "foo", 1), ElementsAre(QName("foo")));
EXPECT_THAT(getSymbols(TU, "foo", 1), ElementsAre(qName("foo")));
}
TEST(WorkspaceSymbols, TempSpecs) {
@ -316,10 +316,10 @@ TEST(WorkspaceSymbols, TempSpecs) {
EXPECT_THAT(
getSymbols(TU, "Foo"),
UnorderedElementsAre(
AllOf(QName("Foo"), WithKind(SymbolKind::Class)),
AllOf(QName("Foo<int, T>"), WithKind(SymbolKind::Class)),
AllOf(QName("Foo<bool, int>"), WithKind(SymbolKind::Class)),
AllOf(QName("Foo<bool, int, 3>"), WithKind(SymbolKind::Class))));
AllOf(qName("Foo"), withKind(SymbolKind::Class)),
AllOf(qName("Foo<int, T>"), withKind(SymbolKind::Class)),
AllOf(qName("Foo<bool, int>"), withKind(SymbolKind::Class)),
AllOf(qName("Foo<bool, int, 3>"), withKind(SymbolKind::Class))));
}
std::vector<DocumentSymbol> getSymbols(ParsedAST AST) {
@ -377,55 +377,55 @@ TEST(DocumentSymbols, BasicSymbols) {
EXPECT_THAT(
getSymbols(TU.build()),
ElementsAreArray(
{AllOf(WithName("Foo"), WithKind(SymbolKind::Class),
WithDetail("class"), Children()),
AllOf(WithName("Foo"), WithKind(SymbolKind::Class),
WithDetail("class"),
Children(
AllOf(WithName("Foo"), WithKind(SymbolKind::Constructor),
WithDetail("()"), Children()),
AllOf(WithName("Foo"), WithKind(SymbolKind::Constructor),
WithDetail("(int)"), Children()),
AllOf(WithName("f"), WithKind(SymbolKind::Method),
WithDetail("void ()"), Children()),
AllOf(WithName("operator="), WithKind(SymbolKind::Method),
WithDetail("Foo &(const Foo &)"), Children()),
AllOf(WithName("~Foo"), WithKind(SymbolKind::Constructor),
WithDetail(""), Children()),
AllOf(WithName("Nested"), WithKind(SymbolKind::Class),
WithDetail("class"),
Children(AllOf(
WithName("f"), WithKind(SymbolKind::Method),
WithDetail("void ()"), Children()))))),
AllOf(WithName("Friend"), WithKind(SymbolKind::Class),
WithDetail("class"), Children()),
AllOf(WithName("f1"), WithKind(SymbolKind::Function),
WithDetail("void ()"), Children()),
AllOf(WithName("f2"), WithKind(SymbolKind::Function),
WithDetail("void ()"), Children()),
AllOf(WithName("KInt"), WithKind(SymbolKind::Variable),
WithDetail("const int"), Children()),
AllOf(WithName("kStr"), WithKind(SymbolKind::Variable),
WithDetail("const char *"), Children()),
AllOf(WithName("f1"), WithKind(SymbolKind::Function),
WithDetail("void ()"), Children()),
{AllOf(withName("Foo"), withKind(SymbolKind::Class),
withDetail("class"), children()),
AllOf(withName("Foo"), withKind(SymbolKind::Class),
withDetail("class"),
children(
AllOf(withName("Foo"), withKind(SymbolKind::Constructor),
withDetail("()"), children()),
AllOf(withName("Foo"), withKind(SymbolKind::Constructor),
withDetail("(int)"), children()),
AllOf(withName("f"), withKind(SymbolKind::Method),
withDetail("void ()"), children()),
AllOf(withName("operator="), withKind(SymbolKind::Method),
withDetail("Foo &(const Foo &)"), children()),
AllOf(withName("~Foo"), withKind(SymbolKind::Constructor),
withDetail(""), children()),
AllOf(withName("Nested"), withKind(SymbolKind::Class),
withDetail("class"),
children(AllOf(
withName("f"), withKind(SymbolKind::Method),
withDetail("void ()"), children()))))),
AllOf(withName("Friend"), withKind(SymbolKind::Class),
withDetail("class"), children()),
AllOf(withName("f1"), withKind(SymbolKind::Function),
withDetail("void ()"), children()),
AllOf(withName("f2"), withKind(SymbolKind::Function),
withDetail("void ()"), children()),
AllOf(withName("KInt"), withKind(SymbolKind::Variable),
withDetail("const int"), children()),
AllOf(withName("kStr"), withKind(SymbolKind::Variable),
withDetail("const char *"), children()),
AllOf(withName("f1"), withKind(SymbolKind::Function),
withDetail("void ()"), children()),
AllOf(
WithName("foo"), WithKind(SymbolKind::Namespace), WithDetail(""),
Children(AllOf(WithName("int32"), WithKind(SymbolKind::Class),
WithDetail("type alias"), Children()),
AllOf(WithName("int32_t"), WithKind(SymbolKind::Class),
WithDetail("type alias"), Children()),
AllOf(WithName("v1"), WithKind(SymbolKind::Variable),
WithDetail("int"), Children()),
AllOf(WithName("bar"), WithKind(SymbolKind::Namespace),
WithDetail(""),
Children(AllOf(WithName("v2"),
WithKind(SymbolKind::Variable),
WithDetail("int"), Children()))),
AllOf(WithName("baz"), WithKind(SymbolKind::Namespace),
WithDetail(""), Children()),
AllOf(WithName("v2"), WithKind(SymbolKind::Namespace),
WithDetail(""))))}));
withName("foo"), withKind(SymbolKind::Namespace), withDetail(""),
children(AllOf(withName("int32"), withKind(SymbolKind::Class),
withDetail("type alias"), children()),
AllOf(withName("int32_t"), withKind(SymbolKind::Class),
withDetail("type alias"), children()),
AllOf(withName("v1"), withKind(SymbolKind::Variable),
withDetail("int"), children()),
AllOf(withName("bar"), withKind(SymbolKind::Namespace),
withDetail(""),
children(AllOf(withName("v2"),
withKind(SymbolKind::Variable),
withDetail("int"), children()))),
AllOf(withName("baz"), withKind(SymbolKind::Namespace),
withDetail(""), children()),
AllOf(withName("v2"), withKind(SymbolKind::Namespace),
withDetail(""))))}));
}
TEST(DocumentSymbols, DeclarationDefinition) {
@ -442,13 +442,13 @@ TEST(DocumentSymbols, DeclarationDefinition) {
EXPECT_THAT(
getSymbols(TU.build()),
ElementsAre(
AllOf(WithName("Foo"), WithKind(SymbolKind::Class),
WithDetail("class"),
Children(AllOf(WithName("f"), WithKind(SymbolKind::Method),
WithDetail("void ()"),
SymNameRange(Main.range("decl"))))),
AllOf(WithName("Foo::f"), WithKind(SymbolKind::Method),
WithDetail("void ()"), SymNameRange(Main.range("def")))));
AllOf(withName("Foo"), withKind(SymbolKind::Class),
withDetail("class"),
children(AllOf(withName("f"), withKind(SymbolKind::Method),
withDetail("void ()"),
symNameRange(Main.range("decl"))))),
AllOf(withName("Foo::f"), withKind(SymbolKind::Method),
withDetail("void ()"), symNameRange(Main.range("def")))));
}
TEST(DocumentSymbols, Concepts) {
@ -457,7 +457,7 @@ TEST(DocumentSymbols, Concepts) {
TU.Code = "template <typename T> concept C = requires(T t) { t.foo(); };";
EXPECT_THAT(getSymbols(TU.build()),
ElementsAre(AllOf(WithName("C"), WithDetail("concept"))));
ElementsAre(AllOf(withName("C"), withDetail("concept"))));
}
TEST(DocumentSymbols, ExternSymbol) {
@ -487,9 +487,9 @@ TEST(DocumentSymbols, ExternContext) {
})cpp";
EXPECT_THAT(getSymbols(TU.build()),
ElementsAre(WithName("foo"), WithName("Foo"),
AllOf(WithName("ns"),
Children(WithName("bar"), WithName("Bar")))));
ElementsAre(withName("foo"), withName("Foo"),
AllOf(withName("ns"),
children(withName("bar"), withName("Bar")))));
}
TEST(DocumentSymbols, ExportContext) {
@ -503,7 +503,7 @@ TEST(DocumentSymbols, ExportContext) {
})cpp";
EXPECT_THAT(getSymbols(TU.build()),
ElementsAre(WithName("foo"), WithName("Foo")));
ElementsAre(withName("foo"), withName("Foo")));
}
TEST(DocumentSymbols, NoLocals) {
@ -513,7 +513,7 @@ TEST(DocumentSymbols, NoLocals) {
struct LocalClass {};
int local_var;
})cpp";
EXPECT_THAT(getSymbols(TU.build()), ElementsAre(WithName("test")));
EXPECT_THAT(getSymbols(TU.build()), ElementsAre(withName("test")));
}
TEST(DocumentSymbols, Unnamed) {
@ -525,14 +525,14 @@ TEST(DocumentSymbols, Unnamed) {
)cpp";
EXPECT_THAT(
getSymbols(TU.build()),
ElementsAre(AllOf(WithName("(anonymous struct)"),
WithKind(SymbolKind::Struct), WithDetail("struct"),
Children(AllOf(WithName("InUnnamed"),
WithKind(SymbolKind::Field),
WithDetail("int"), Children()))),
AllOf(WithName("UnnamedStruct"),
WithKind(SymbolKind::Variable),
WithDetail("struct (unnamed)"), Children())));
ElementsAre(AllOf(withName("(anonymous struct)"),
withKind(SymbolKind::Struct), withDetail("struct"),
children(AllOf(withName("InUnnamed"),
withKind(SymbolKind::Field),
withDetail("int"), children()))),
AllOf(withName("UnnamedStruct"),
withKind(SymbolKind::Variable),
withDetail("struct (unnamed)"), children())));
}
TEST(DocumentSymbols, InHeaderFile) {
@ -548,7 +548,7 @@ TEST(DocumentSymbols, InHeaderFile) {
}
)cpp";
EXPECT_THAT(getSymbols(TU.build()),
ElementsAre(WithName("i"), WithName("test")));
ElementsAre(withName("i"), withName("test")));
}
TEST(DocumentSymbols, Template) {
@ -574,23 +574,23 @@ TEST(DocumentSymbols, Template) {
EXPECT_THAT(
getSymbols(TU.build()),
ElementsAre(
AllOf(WithName("Tmpl"), WithKind(SymbolKind::Struct),
WithDetail("template struct"),
Children(AllOf(WithName("x"), WithKind(SymbolKind::Field),
WithDetail("T")))),
AllOf(WithName("Tmpl<int>"), WithKind(SymbolKind::Struct),
WithDetail("struct"),
Children(AllOf(WithName("y"), WithDetail("int")))),
AllOf(WithName("Tmpl<float>"), WithKind(SymbolKind::Struct),
WithDetail("struct"), Children()),
AllOf(WithName("Tmpl<double>"), WithKind(SymbolKind::Struct),
WithDetail("struct"), Children()),
AllOf(WithName("funcTmpl"), WithDetail("template int (U)"),
Children()),
AllOf(WithName("funcTmpl<int>"), WithDetail("int (double)"),
Children()),
AllOf(WithName("varTmpl"), WithDetail("template int"), Children()),
AllOf(WithName("varTmpl<int>"), WithDetail("double"), Children())));
AllOf(withName("Tmpl"), withKind(SymbolKind::Struct),
withDetail("template struct"),
children(AllOf(withName("x"), withKind(SymbolKind::Field),
withDetail("T")))),
AllOf(withName("Tmpl<int>"), withKind(SymbolKind::Struct),
withDetail("struct"),
children(AllOf(withName("y"), withDetail("int")))),
AllOf(withName("Tmpl<float>"), withKind(SymbolKind::Struct),
withDetail("struct"), children()),
AllOf(withName("Tmpl<double>"), withKind(SymbolKind::Struct),
withDetail("struct"), children()),
AllOf(withName("funcTmpl"), withDetail("template int (U)"),
children()),
AllOf(withName("funcTmpl<int>"), withDetail("int (double)"),
children()),
AllOf(withName("varTmpl"), withDetail("template int"), children()),
AllOf(withName("varTmpl<int>"), withDetail("double"), children())));
}
TEST(DocumentSymbols, Namespaces) {
@ -621,14 +621,14 @@ TEST(DocumentSymbols, Namespaces) {
EXPECT_THAT(
getSymbols(TU.build()),
ElementsAreArray<::testing::Matcher<DocumentSymbol>>(
{AllOf(WithName("ans1"),
Children(AllOf(WithName("ai1"), Children()),
AllOf(WithName("ans2"), Children(WithName("ai2"))))),
AllOf(WithName("(anonymous namespace)"), Children(WithName("test"))),
AllOf(WithName("na"),
Children(AllOf(WithName("nb"), Children(WithName("Foo"))))),
AllOf(WithName("na"),
Children(AllOf(WithName("nb"), Children(WithName("Bar")))))}));
{AllOf(withName("ans1"),
children(AllOf(withName("ai1"), children()),
AllOf(withName("ans2"), children(withName("ai2"))))),
AllOf(withName("(anonymous namespace)"), children(withName("test"))),
AllOf(withName("na"),
children(AllOf(withName("nb"), children(withName("Foo"))))),
AllOf(withName("na"),
children(AllOf(withName("nb"), children(withName("Bar")))))}));
}
TEST(DocumentSymbols, Enums) {
@ -652,16 +652,16 @@ TEST(DocumentSymbols, Enums) {
EXPECT_THAT(
getSymbols(TU.build()),
ElementsAre(
AllOf(WithName("(anonymous enum)"), WithDetail("enum"),
Children(AllOf(WithName("Red"), WithDetail("(unnamed)")))),
AllOf(WithName("Color"), WithDetail("enum"),
Children(AllOf(WithName("Green"), WithDetail("Color")))),
AllOf(WithName("Color2"), WithDetail("enum"),
Children(AllOf(WithName("Yellow"), WithDetail("Color2")))),
AllOf(WithName("ns"),
Children(AllOf(WithName("(anonymous enum)"), WithDetail("enum"),
Children(AllOf(WithName("Black"),
WithDetail("(unnamed)"))))))));
AllOf(withName("(anonymous enum)"), withDetail("enum"),
children(AllOf(withName("Red"), withDetail("(unnamed)")))),
AllOf(withName("Color"), withDetail("enum"),
children(AllOf(withName("Green"), withDetail("Color")))),
AllOf(withName("Color2"), withDetail("enum"),
children(AllOf(withName("Yellow"), withDetail("Color2")))),
AllOf(withName("ns"),
children(AllOf(withName("(anonymous enum)"), withDetail("enum"),
children(AllOf(withName("Black"),
withDetail("(unnamed)"))))))));
}
TEST(DocumentSymbols, Macro) {
@ -675,8 +675,8 @@ TEST(DocumentSymbols, Macro) {
#define DEFINE_FLAG(X) bool FLAGS_##X; bool FLAGS_no##X
DEFINE_FLAG(pretty);
)cpp",
AllOf(WithName("DEFINE_FLAG"), WithDetail("(pretty)"),
Children(WithName("FLAGS_pretty"), WithName("FLAGS_nopretty"))),
AllOf(withName("DEFINE_FLAG"), withDetail("(pretty)"),
children(withName("FLAGS_pretty"), withName("FLAGS_nopretty"))),
},
{
R"cpp(
@ -684,10 +684,10 @@ TEST(DocumentSymbols, Macro) {
#define ID(X) X
namespace ID(ns) { int ID(y); }
)cpp",
AllOf(WithName("ID"), WithDetail("(ns)"),
Children(AllOf(WithName("ns"),
Children(AllOf(WithName("ID"), WithDetail("(y)"),
Children(WithName("y"))))))),
AllOf(withName("ID"), withDetail("(ns)"),
children(AllOf(withName("ns"),
children(AllOf(withName("ID"), withDetail("(y)"),
children(withName("y"))))))),
},
{
R"cpp(
@ -695,10 +695,10 @@ TEST(DocumentSymbols, Macro) {
#define TEST(A, B) class A##_##B { void go(); }; void A##_##B::go()
TEST(DocumentSymbols, Macro) { }
)cpp",
AllOf(WithName("TEST"), WithDetail("(DocumentSymbols, Macro)"),
Children(AllOf(WithName("DocumentSymbols_Macro"),
Children(WithName("go"))),
WithName("DocumentSymbols_Macro::go"))),
AllOf(withName("TEST"), withDetail("(DocumentSymbols, Macro)"),
children(AllOf(withName("DocumentSymbols_Macro"),
children(withName("go"))),
withName("DocumentSymbols_Macro::go"))),
},
{
R"cpp(
@ -707,14 +707,14 @@ TEST(DocumentSymbols, Macro) {
NAMESPACE(a, NAMESPACE(b, int x;))
)cpp",
AllOf(
WithName("NAMESPACE"), WithDetail("(a, NAMESPACE(b, int x;))"),
Children(AllOf(
WithName("a"),
Children(AllOf(WithName("NAMESPACE"),
withName("NAMESPACE"), withDetail("(a, NAMESPACE(b, int x;))"),
children(AllOf(
withName("a"),
children(AllOf(withName("NAMESPACE"),
// FIXME: nested expansions not in TokenBuffer
WithDetail(""),
Children(AllOf(WithName("b"),
Children(WithName("x"))))))))),
withDetail(""),
children(AllOf(withName("b"),
children(withName("x"))))))))),
},
{
R"cpp(
@ -723,8 +723,8 @@ TEST(DocumentSymbols, Macro) {
#define OUTER(X) INNER(X)
OUTER(foo);
)cpp",
AllOf(WithName("OUTER"), WithDetail("(foo)"),
Children(WithName("foo"))),
AllOf(withName("OUTER"), withDetail("(foo)"),
children(withName("foo"))),
},
};
for (const Test &T : Tests) {
@ -757,18 +757,18 @@ TEST(DocumentSymbols, RangeFromMacro) {
EXPECT_THAT(
getSymbols(TU.build()),
ElementsAre(
AllOf(WithName("FF"), WithDetail("(abc)"),
Children(AllOf(WithName("abc_Test"), WithDetail("class"),
SymNameRange(Main.range("expansion1"))))),
AllOf(WithName("FF2"), WithDetail("()"),
SymNameRange(Main.range("expansion2")),
SymRange(Main.range("expansion2parens")),
Children(AllOf(WithName("Test"), WithDetail("class"),
SymNameRange(Main.range("expansion2"))))),
AllOf(WithName("FF3"), WithDetail("()"),
SymRange(Main.range("fullDef")),
Children(AllOf(WithName("waldo"), WithDetail("void ()"),
SymRange(Main.range("fullDef")))))));
AllOf(withName("FF"), withDetail("(abc)"),
children(AllOf(withName("abc_Test"), withDetail("class"),
symNameRange(Main.range("expansion1"))))),
AllOf(withName("FF2"), withDetail("()"),
symNameRange(Main.range("expansion2")),
symRange(Main.range("expansion2parens")),
children(AllOf(withName("Test"), withDetail("class"),
symNameRange(Main.range("expansion2"))))),
AllOf(withName("FF3"), withDetail("()"),
symRange(Main.range("fullDef")),
children(AllOf(withName("waldo"), withDetail("void ()"),
symRange(Main.range("fullDef")))))));
}
TEST(DocumentSymbols, FuncTemplates) {
@ -783,9 +783,9 @@ TEST(DocumentSymbols, FuncTemplates) {
TU.Code = Source.code().str();
// Make sure we only see the template declaration, not instantiations.
EXPECT_THAT(getSymbols(TU.build()),
ElementsAre(AllOf(WithName("foo"), WithDetail("template T ()")),
AllOf(WithName("x"), WithDetail("int")),
AllOf(WithName("y"), WithDetail("double"))));
ElementsAre(AllOf(withName("foo"), withDetail("template T ()")),
AllOf(withName("x"), withDetail("int")),
AllOf(withName("y"), withDetail("double"))));
}
TEST(DocumentSymbols, UsingDirectives) {
@ -802,9 +802,9 @@ TEST(DocumentSymbols, UsingDirectives) {
)cpp");
TU.Code = Source.code().str();
EXPECT_THAT(getSymbols(TU.build()),
ElementsAre(WithName("ns"), WithName("ns_alias"),
WithName("using namespace ::ns"),
WithName("using namespace ns_alias")));
ElementsAre(withName("ns"), withName("ns_alias"),
withName("using namespace ::ns"),
withName("using namespace ns_alias")));
}
TEST(DocumentSymbols, TempSpecs) {
@ -818,14 +818,14 @@ TEST(DocumentSymbols, TempSpecs) {
// Foo is higher ranked because of exact name match.
EXPECT_THAT(getSymbols(TU.build()),
UnorderedElementsAre(
AllOf(WithName("Foo"), WithKind(SymbolKind::Class),
WithDetail("template class")),
AllOf(WithName("Foo<int, T>"), WithKind(SymbolKind::Class),
WithDetail("template class")),
AllOf(WithName("Foo<bool, int>"), WithKind(SymbolKind::Class),
WithDetail("class")),
AllOf(WithName("Foo<bool, int, 3>"),
WithKind(SymbolKind::Class), WithDetail("class"))));
AllOf(withName("Foo"), withKind(SymbolKind::Class),
withDetail("template class")),
AllOf(withName("Foo<int, T>"), withKind(SymbolKind::Class),
withDetail("template class")),
AllOf(withName("Foo<bool, int>"), withKind(SymbolKind::Class),
withDetail("class")),
AllOf(withName("Foo<bool, int, 3>"),
withKind(SymbolKind::Class), withDetail("class"))));
}
TEST(DocumentSymbols, Qualifiers) {
@ -855,10 +855,10 @@ TEST(DocumentSymbols, Qualifiers) {
// All the qualifiers should be preserved exactly as written.
EXPECT_THAT(getSymbols(TU.build()),
UnorderedElementsAre(
WithName("foo"), WithName("foo::bar::Cls"),
WithName("foo::bar::func1"), WithName("::foo::bar::func2"),
WithName("using namespace foo"), WithName("bar::func3"),
WithName("alias"), WithName("::alias::func4")));
withName("foo"), withName("foo::bar::Cls"),
withName("foo::bar::func1"), withName("::foo::bar::func2"),
withName("using namespace foo"), withName("bar::func3"),
withName("alias"), withName("::alias::func4")));
}
TEST(DocumentSymbols, QualifiersWithTemplateArgs) {
@ -887,14 +887,14 @@ TEST(DocumentSymbols, QualifiersWithTemplateArgs) {
)cpp";
EXPECT_THAT(getSymbols(TU.build()),
UnorderedElementsAre(
AllOf(WithName("Foo"), WithDetail("template class")),
AllOf(WithName("Foo<int, double>"), WithDetail("class")),
AllOf(WithName("int_type"), WithDetail("type alias")),
AllOf(WithName("Foo<int_type, double>::method1"),
WithDetail("int ()")),
AllOf(WithName("Foo<int>::method2"), WithDetail("int ()")),
AllOf(WithName("Foo_type"), WithDetail("type alias")),
AllOf(WithName("Foo_type::method3"), WithDetail("int ()"))));
AllOf(withName("Foo"), withDetail("template class")),
AllOf(withName("Foo<int, double>"), withDetail("class")),
AllOf(withName("int_type"), withDetail("type alias")),
AllOf(withName("Foo<int_type, double>::method1"),
withDetail("int ()")),
AllOf(withName("Foo<int>::method2"), withDetail("int ()")),
AllOf(withName("Foo_type"), withDetail("type alias")),
AllOf(withName("Foo_type::method3"), withDetail("int ()"))));
}
TEST(DocumentSymbolsTest, Ranges) {
@ -932,39 +932,39 @@ TEST(DocumentSymbolsTest, Ranges) {
EXPECT_THAT(
getSymbols(TU.build()),
UnorderedElementsAre(
AllOf(WithName("foo"), WithKind(SymbolKind::Function),
WithDetail("int (bool)"), SymRange(Main.range("foo"))),
AllOf(WithName("GLOBAL_VARIABLE"), WithKind(SymbolKind::Variable),
WithDetail("char"), SymRange(Main.range("variable"))),
AllOf(withName("foo"), withKind(SymbolKind::Function),
withDetail("int (bool)"), symRange(Main.range("foo"))),
AllOf(withName("GLOBAL_VARIABLE"), withKind(SymbolKind::Variable),
withDetail("char"), symRange(Main.range("variable"))),
AllOf(
WithName("ns"), WithKind(SymbolKind::Namespace),
SymRange(Main.range("ns")),
Children(AllOf(
WithName("Bar"), WithKind(SymbolKind::Class),
WithDetail("class"), SymRange(Main.range("bar")),
Children(
AllOf(WithName("Bar"), WithKind(SymbolKind::Constructor),
WithDetail("()"), SymRange(Main.range("ctor"))),
AllOf(WithName("~Bar"), WithKind(SymbolKind::Constructor),
WithDetail(""), SymRange(Main.range("dtor"))),
AllOf(WithName("Baz"), WithKind(SymbolKind::Field),
WithDetail("unsigned int"),
SymRange(Main.range("field"))),
AllOf(WithName("getBaz"), WithKind(SymbolKind::Method),
WithDetail("unsigned int ()"),
SymRange(Main.range("getbaz"))))))),
AllOf(WithName("ForwardClassDecl"), WithKind(SymbolKind::Class),
WithDetail("class"), SymRange(Main.range("forwardclass"))),
AllOf(WithName("StructDefinition"), WithKind(SymbolKind::Struct),
WithDetail("struct"), SymRange(Main.range("struct")),
Children(AllOf(WithName("Pointer"), WithKind(SymbolKind::Field),
WithDetail("int *"),
SymRange(Main.range("structfield"))))),
AllOf(WithName("StructDeclaration"), WithKind(SymbolKind::Struct),
WithDetail("struct"), SymRange(Main.range("forwardstruct"))),
AllOf(WithName("forwardFunctionDecl"), WithKind(SymbolKind::Function),
WithDetail("void (int)"),
SymRange(Main.range("forwardfunc")))));
withName("ns"), withKind(SymbolKind::Namespace),
symRange(Main.range("ns")),
children(AllOf(
withName("Bar"), withKind(SymbolKind::Class),
withDetail("class"), symRange(Main.range("bar")),
children(
AllOf(withName("Bar"), withKind(SymbolKind::Constructor),
withDetail("()"), symRange(Main.range("ctor"))),
AllOf(withName("~Bar"), withKind(SymbolKind::Constructor),
withDetail(""), symRange(Main.range("dtor"))),
AllOf(withName("Baz"), withKind(SymbolKind::Field),
withDetail("unsigned int"),
symRange(Main.range("field"))),
AllOf(withName("getBaz"), withKind(SymbolKind::Method),
withDetail("unsigned int ()"),
symRange(Main.range("getbaz"))))))),
AllOf(withName("ForwardClassDecl"), withKind(SymbolKind::Class),
withDetail("class"), symRange(Main.range("forwardclass"))),
AllOf(withName("StructDefinition"), withKind(SymbolKind::Struct),
withDetail("struct"), symRange(Main.range("struct")),
children(AllOf(withName("Pointer"), withKind(SymbolKind::Field),
withDetail("int *"),
symRange(Main.range("structfield"))))),
AllOf(withName("StructDeclaration"), withKind(SymbolKind::Struct),
withDetail("struct"), symRange(Main.range("forwardstruct"))),
AllOf(withName("forwardFunctionDecl"), withKind(SymbolKind::Function),
withDetail("void (int)"),
symRange(Main.range("forwardfunc")))));
}
TEST(DocumentSymbolsTest, DependentType) {
@ -982,13 +982,13 @@ TEST(DocumentSymbolsTest, DependentType) {
EXPECT_THAT(
getSymbols(TU.build()),
ElementsAre(
AllOf(WithName("plus"),
WithDetail("template auto (T, T) -> decltype(x + y)")),
AllOf(WithName("Pair"), WithDetail("template class")),
AllOf(WithName("Context"), WithDetail("template struct"),
Children(AllOf(
WithName("Pair<type-parameter-0-0, type-parameter-0-1>"),
WithDetail("<dependent type>"))))));
AllOf(withName("plus"),
withDetail("template auto (T, T) -> decltype(x + y)")),
AllOf(withName("Pair"), withDetail("template class")),
AllOf(withName("Context"), withDetail("template struct"),
children(AllOf(
withName("Pair<type-parameter-0-0, type-parameter-0-1>"),
withDetail("<dependent type>"))))));
}
TEST(DocumentSymbolsTest, ObjCCategoriesAndClassExtensions) {
@ -1013,18 +1013,18 @@ TEST(DocumentSymbolsTest, ObjCCategoriesAndClassExtensions) {
EXPECT_THAT(
getSymbols(TU.build()),
ElementsAre(
AllOf(WithName("Cat"), SymRange(Main.range("Cat")),
Children(AllOf(WithName("+sharedCat"),
WithKind(SymbolKind::Method)))),
AllOf(WithName("Cat(Sneaky)"), SymRange(Main.range("SneakyCat")),
Children(
AllOf(WithName("-sneak:"), WithKind(SymbolKind::Method)))),
AllOf(withName("Cat"), symRange(Main.range("Cat")),
children(AllOf(withName("+sharedCat"),
withKind(SymbolKind::Method)))),
AllOf(withName("Cat(Sneaky)"), symRange(Main.range("SneakyCat")),
children(
AllOf(withName("-sneak:"), withKind(SymbolKind::Method)))),
AllOf(
WithName("Cat()"), SymRange(Main.range("MeowCat")),
Children(AllOf(WithName("-meow"), WithKind(SymbolKind::Method)))),
AllOf(WithName("Cat()"), SymRange(Main.range("PurCat")),
Children(
AllOf(WithName("-pur"), WithKind(SymbolKind::Method))))));
withName("Cat()"), symRange(Main.range("MeowCat")),
children(AllOf(withName("-meow"), withKind(SymbolKind::Method)))),
AllOf(withName("Cat()"), symRange(Main.range("PurCat")),
children(
AllOf(withName("-pur"), withKind(SymbolKind::Method))))));
}
TEST(DocumentSymbolsTest, PragmaMarkGroups) {
@ -1059,21 +1059,21 @@ TEST(DocumentSymbolsTest, PragmaMarkGroups) {
EXPECT_THAT(
getSymbols(TU.build()),
UnorderedElementsAre(
AllOf(WithName("Dog"), SymRange(Main.range("DogDef"))),
AllOf(WithName("Dog"), SymRange(Main.range("DogImpl")),
Children(AllOf(WithName("+sharedDoggo"),
WithKind(SymbolKind::Method)),
AllOf(WithName("Overrides"),
SymRange(Main.range("Overrides")),
Children(AllOf(WithName("-init"),
WithKind(SymbolKind::Method)),
AllOf(WithName("-bark"),
WithKind(SymbolKind::Method)))),
AllOf(WithName("Dog Specifics"),
SymRange(Main.range("Specifics")),
Children(AllOf(WithName("-isAGoodBoy"),
WithKind(SymbolKind::Method)))))),
AllOf(WithName("End"), SymRange(Main.range("End")))));
AllOf(withName("Dog"), symRange(Main.range("DogDef"))),
AllOf(withName("Dog"), symRange(Main.range("DogImpl")),
children(AllOf(withName("+sharedDoggo"),
withKind(SymbolKind::Method)),
AllOf(withName("Overrides"),
symRange(Main.range("Overrides")),
children(AllOf(withName("-init"),
withKind(SymbolKind::Method)),
AllOf(withName("-bark"),
withKind(SymbolKind::Method)))),
AllOf(withName("Dog Specifics"),
symRange(Main.range("Specifics")),
children(AllOf(withName("-isAGoodBoy"),
withKind(SymbolKind::Method)))))),
AllOf(withName("End"), symRange(Main.range("End")))));
}
TEST(DocumentSymbolsTest, PragmaMarkGroupsNesting) {
@ -1093,13 +1093,13 @@ TEST(DocumentSymbolsTest, PragmaMarkGroupsNesting) {
EXPECT_THAT(
getSymbols(TU.build()),
UnorderedElementsAre(AllOf(
WithName("Foo"),
Children(AllOf(WithName("Foo"),
Children(AllOf(WithName("Bar"),
Children(AllOf(WithName("bar"),
Children(WithName(
withName("Foo"),
children(AllOf(withName("Foo"),
children(AllOf(withName("Bar"),
children(AllOf(withName("bar"),
children(withName(
"NotTopDecl"))))))),
WithName("bar")))));
withName("bar")))));
}
TEST(DocumentSymbolsTest, PragmaMarkGroupsNoNesting) {
@ -1116,9 +1116,9 @@ TEST(DocumentSymbolsTest, PragmaMarkGroupsNoNesting) {
)cpp");
TU.Code = Main.code().str();
EXPECT_THAT(getSymbols(TU.build()),
UnorderedElementsAre(WithName("Helpers"), WithName("helpA"),
WithName("(unnamed group)"),
WithName("Core"), WithName("coreMethod")));
UnorderedElementsAre(withName("Helpers"), withName("helpA"),
withName("(unnamed group)"),
withName("Core"), withName("coreMethod")));
}
} // namespace

View File

@ -74,7 +74,7 @@ TEST(HeaderSourceSwitchTest, FileHeuristic) {
EXPECT_FALSE(PathResult.hasValue());
}
MATCHER_P(DeclNamed, Name, "") {
MATCHER_P(declNamed, Name, "") {
if (const NamedDecl *ND = dyn_cast<NamedDecl>(arg))
if (ND->getQualifiedNameAsString() == Name)
return true;
@ -106,8 +106,8 @@ TEST(HeaderSourceSwitchTest, GetLocalDecls) {
auto AST = TU.build();
EXPECT_THAT(getIndexableLocalDecls(AST),
testing::UnorderedElementsAre(
DeclNamed("MainF1"), DeclNamed("Foo"), DeclNamed("ns::Foo"),
DeclNamed("ns::Foo::method"), DeclNamed("ns::Foo::field")));
declNamed("MainF1"), declNamed("Foo"), declNamed("ns::Foo"),
declNamed("ns::Foo::method"), declNamed("ns::Foo::field")));
}
TEST(HeaderSourceSwitchTest, FromHeaderToSource) {

View File

@ -139,11 +139,11 @@ protected:
std::unique_ptr<CompilerInstance> Clang;
};
MATCHER_P(Written, Name, "") { return arg.Written == Name; }
MATCHER_P(Resolved, Name, "") { return arg.Resolved == Name; }
MATCHER_P(IncludeLine, N, "") { return arg.HashLine == N; }
MATCHER_P(Directive, D, "") { return arg.Directive == D; }
MATCHER_P(HasPragmaKeep, H, "") { return arg.BehindPragmaKeep == H; }
MATCHER_P(written, Name, "") { return arg.Written == Name; }
MATCHER_P(resolved, Name, "") { return arg.Resolved == Name; }
MATCHER_P(includeLine, N, "") { return arg.HashLine == N; }
MATCHER_P(directive, D, "") { return arg.Directive == D; }
MATCHER_P(hasPragmaKeep, H, "") { return arg.BehindPragmaKeep == H; }
MATCHER_P2(Distance, File, D, "") {
if (arg.getFirst() != File)
@ -163,7 +163,7 @@ TEST_F(HeadersTest, CollectRewrittenAndResolved) {
auto Includes = collectIncludes();
EXPECT_THAT(Includes.MainFileIncludes,
UnorderedElementsAre(
AllOf(Written("\"sub/bar.h\""), Resolved(BarHeader))));
AllOf(written("\"sub/bar.h\""), resolved(BarHeader))));
EXPECT_THAT(Includes.includeDepth(getID(MainFile, Includes)),
UnorderedElementsAre(Distance(getID(MainFile, Includes), 0u),
Distance(getID(BarHeader, Includes), 1u)));
@ -182,7 +182,7 @@ TEST_F(HeadersTest, OnlyCollectInclusionsInMain) {
auto Includes = collectIncludes();
EXPECT_THAT(
Includes.MainFileIncludes,
UnorderedElementsAre(AllOf(Written("\"bar.h\""), Resolved(BarHeader))));
UnorderedElementsAre(AllOf(written("\"bar.h\""), resolved(BarHeader))));
EXPECT_THAT(Includes.includeDepth(getID(MainFile, Includes)),
UnorderedElementsAre(Distance(getID(MainFile, Includes), 0u),
Distance(getID(BarHeader, Includes), 1u),
@ -206,7 +206,7 @@ TEST_F(HeadersTest, PreambleIncludesPresentOnce) {
)cpp");
TU.HeaderFilename = "a.h"; // suppress "not found".
EXPECT_THAT(TU.build().getIncludeStructure().MainFileIncludes,
ElementsAre(IncludeLine(1), IncludeLine(3), IncludeLine(5)));
ElementsAre(includeLine(1), includeLine(3), includeLine(5)));
}
TEST_F(HeadersTest, UnResolvedInclusion) {
@ -215,7 +215,7 @@ TEST_F(HeadersTest, UnResolvedInclusion) {
)cpp";
EXPECT_THAT(collectIncludes().MainFileIncludes,
UnorderedElementsAre(AllOf(Written("\"foo.h\""), Resolved(""))));
UnorderedElementsAre(AllOf(written("\"foo.h\""), resolved(""))));
EXPECT_THAT(collectIncludes().IncludeChildren, IsEmpty());
}
@ -254,9 +254,9 @@ TEST_F(HeadersTest, IncludeDirective) {
// ms-compatibility changes meaning of #import, make sure it is turned off.
CDB.ExtraClangFlags.push_back("-fno-ms-compatibility");
EXPECT_THAT(collectIncludes().MainFileIncludes,
UnorderedElementsAre(Directive(tok::pp_include),
Directive(tok::pp_import),
Directive(tok::pp_include_next)));
UnorderedElementsAre(directive(tok::pp_include),
directive(tok::pp_import),
directive(tok::pp_include_next)));
}
TEST_F(HeadersTest, IWYUPragmaKeep) {
@ -267,8 +267,8 @@ TEST_F(HeadersTest, IWYUPragmaKeep) {
EXPECT_THAT(
collectIncludes().MainFileIncludes,
UnorderedElementsAre(AllOf(Written("\"foo.h\""), HasPragmaKeep(false)),
AllOf(Written("\"bar.h\""), HasPragmaKeep(true))));
UnorderedElementsAre(AllOf(written("\"foo.h\""), hasPragmaKeep(false)),
AllOf(written("\"bar.h\""), hasPragmaKeep(true))));
}
TEST_F(HeadersTest, InsertInclude) {
@ -369,12 +369,12 @@ TEST_F(HeadersTest, PresumedLocations) {
// Including through non-builtin file has no effects.
FS.Files[MainFile] = "#include \"__preamble_patch__.h\"\n\n";
EXPECT_THAT(collectIncludes().MainFileIncludes,
Not(Contains(Written("<a.h>"))));
Not(Contains(written("<a.h>"))));
// Now include through built-in file.
CDB.ExtraClangFlags = {"-include", testPath(HeaderFile)};
EXPECT_THAT(collectIncludes().MainFileIncludes,
Contains(AllOf(IncludeLine(2), Written("<a.h>"))));
Contains(AllOf(includeLine(2), written("<a.h>"))));
}
TEST_F(HeadersTest, SelfContainedHeaders) {
@ -445,20 +445,20 @@ TEST(StdlibTest, Recognizer) {
)cpp");
auto AST = TU.build();
auto &vector_nonstd = findDecl(AST, "vector");
auto *vec =
auto &VectorNonstd = findDecl(AST, "vector");
auto *Vec =
cast<VarDecl>(findDecl(AST, "vec")).getType()->getAsCXXRecordDecl();
auto *nest =
auto *Nest =
cast<VarDecl>(findDecl(AST, "nest")).getType()->getAsCXXRecordDecl();
auto *sec =
auto *Sec =
cast<VarDecl>(findDecl(AST, "sec")).getType()->getAsCXXRecordDecl();
stdlib::Recognizer recognizer;
stdlib::Recognizer Recognizer;
EXPECT_EQ(recognizer(&vector_nonstd), llvm::None);
EXPECT_EQ(recognizer(vec), stdlib::Symbol::named("std::", "vector"));
EXPECT_EQ(recognizer(nest), stdlib::Symbol::named("std::", "vector"));
EXPECT_EQ(recognizer(sec), llvm::None);
EXPECT_EQ(Recognizer(&VectorNonstd), llvm::None);
EXPECT_EQ(Recognizer(Vec), stdlib::Symbol::named("std::", "vector"));
EXPECT_EQ(Recognizer(Nest), stdlib::Symbol::named("std::", "vector"));
EXPECT_EQ(Recognizer(Sec), llvm::None);
}
} // namespace

View File

@ -272,7 +272,7 @@ TEST(IncludeCleaner, Stdlib) {
}
}
MATCHER_P(WrittenInclusion, Written, "") {
MATCHER_P(writtenInclusion, Written, "") {
if (arg.Written != Written)
*result_listener << arg.Written;
return arg.Written == Written;
@ -302,7 +302,7 @@ TEST(IncludeCleaner, StdlibUnused) {
auto AST = TU.build();
auto Unused = computeUnusedIncludes(AST);
EXPECT_THAT(Unused, ElementsAre(Pointee(WrittenInclusion("<queue>"))));
EXPECT_THAT(Unused, ElementsAre(Pointee(writtenInclusion("<queue>"))));
}
TEST(IncludeCleaner, GetUnusedHeaders) {

View File

@ -27,22 +27,22 @@ using ::testing::UnorderedPointwise;
std::string toUri(llvm::StringRef Path) { return URI::create(Path).toString(); }
MATCHER(IsTU, "") { return arg.Flags & IncludeGraphNode::SourceFlag::IsTU; }
MATCHER(isTU, "") { return arg.Flags & IncludeGraphNode::SourceFlag::IsTU; }
MATCHER_P(HasDigest, Digest, "") { return arg.Digest == Digest; }
MATCHER_P(hasDigest, Digest, "") { return arg.Digest == Digest; }
MATCHER_P(HasName, Name, "") { return arg.Name == Name; }
MATCHER_P(hasName, Name, "") { return arg.Name == Name; }
MATCHER(HasSameURI, "") {
MATCHER(hasSameURI, "") {
llvm::StringRef URI = ::testing::get<0>(arg);
const std::string &Path = ::testing::get<1>(arg);
return toUri(Path) == URI;
}
::testing::Matcher<const IncludeGraphNode &>
IncludesAre(const std::vector<std::string> &Includes) {
includesAre(const std::vector<std::string> &Includes) {
return ::testing::Field(&IncludeGraphNode::DirectIncludes,
UnorderedPointwise(HasSameURI(), Includes));
UnorderedPointwise(hasSameURI(), Includes));
}
void checkNodesAreInitialized(const IndexFileIn &IndexFile,
@ -127,14 +127,14 @@ TEST_F(IndexActionTest, CollectIncludeGraph) {
EXPECT_THAT(Nodes,
UnorderedElementsAre(
Pair(toUri(MainFilePath),
AllOf(IsTU(), IncludesAre({Level1HeaderPath}),
HasDigest(digest(MainCode)))),
AllOf(isTU(), includesAre({Level1HeaderPath}),
hasDigest(digest(MainCode)))),
Pair(toUri(Level1HeaderPath),
AllOf(Not(IsTU()), IncludesAre({Level2HeaderPath}),
HasDigest(digest(Level1HeaderCode)))),
AllOf(Not(isTU()), includesAre({Level2HeaderPath}),
hasDigest(digest(Level1HeaderCode)))),
Pair(toUri(Level2HeaderPath),
AllOf(Not(IsTU()), IncludesAre({}),
HasDigest(digest(Level2HeaderCode))))));
AllOf(Not(isTU()), includesAre({}),
hasDigest(digest(Level2HeaderCode))))));
}
TEST_F(IndexActionTest, IncludeGraphSelfInclude) {
@ -156,10 +156,10 @@ TEST_F(IndexActionTest, IncludeGraphSelfInclude) {
EXPECT_THAT(
Nodes,
UnorderedElementsAre(
Pair(toUri(MainFilePath), AllOf(IsTU(), IncludesAre({HeaderPath}),
HasDigest(digest(MainCode)))),
Pair(toUri(HeaderPath), AllOf(Not(IsTU()), IncludesAre({HeaderPath}),
HasDigest(digest(HeaderCode))))));
Pair(toUri(MainFilePath), AllOf(isTU(), includesAre({HeaderPath}),
hasDigest(digest(MainCode)))),
Pair(toUri(HeaderPath), AllOf(Not(isTU()), includesAre({HeaderPath}),
hasDigest(digest(HeaderCode))))));
}
TEST_F(IndexActionTest, IncludeGraphSkippedFile) {
@ -191,14 +191,14 @@ TEST_F(IndexActionTest, IncludeGraphSkippedFile) {
EXPECT_THAT(
Nodes, UnorderedElementsAre(
Pair(toUri(MainFilePath),
AllOf(IsTU(), IncludesAre({HeaderPath, CommonHeaderPath}),
HasDigest(digest(MainCode)))),
AllOf(isTU(), includesAre({HeaderPath, CommonHeaderPath}),
hasDigest(digest(MainCode)))),
Pair(toUri(HeaderPath),
AllOf(Not(IsTU()), IncludesAre({CommonHeaderPath}),
HasDigest(digest(HeaderCode)))),
AllOf(Not(isTU()), includesAre({CommonHeaderPath}),
hasDigest(digest(HeaderCode)))),
Pair(toUri(CommonHeaderPath),
AllOf(Not(IsTU()), IncludesAre({}),
HasDigest(digest(CommonHeaderCode))))));
AllOf(Not(isTU()), includesAre({}),
hasDigest(digest(CommonHeaderCode))))));
}
TEST_F(IndexActionTest, IncludeGraphDynamicInclude) {
@ -224,10 +224,10 @@ TEST_F(IndexActionTest, IncludeGraphDynamicInclude) {
Nodes,
UnorderedElementsAre(
Pair(toUri(MainFilePath),
AllOf(IsTU(), IncludesAre({MainFilePath, HeaderPath}),
HasDigest(digest(MainCode)))),
Pair(toUri(HeaderPath), AllOf(Not(IsTU()), IncludesAre({}),
HasDigest(digest(HeaderCode))))));
AllOf(isTU(), includesAre({MainFilePath, HeaderPath}),
hasDigest(digest(MainCode)))),
Pair(toUri(HeaderPath), AllOf(Not(isTU()), includesAre({}),
hasDigest(digest(HeaderCode))))));
}
TEST_F(IndexActionTest, NoWarnings) {
@ -248,7 +248,7 @@ TEST_F(IndexActionTest, NoWarnings) {
MainFilePath, {"-ferror-limit=1", "-Wparentheses", "-Werror"});
ASSERT_TRUE(IndexFile.Sources);
ASSERT_NE(0u, IndexFile.Sources->size());
EXPECT_THAT(*IndexFile.Symbols, ElementsAre(HasName("foo"), HasName("bar")));
EXPECT_THAT(*IndexFile.Symbols, ElementsAre(hasName("foo"), hasName("bar")));
}
TEST_F(IndexActionTest, SkipFiles) {
@ -274,8 +274,8 @@ TEST_F(IndexActionTest, SkipFiles) {
};
IndexFileIn IndexFile = runIndexingAction(MainFilePath, {"-std=c++14"});
EXPECT_THAT(*IndexFile.Symbols,
UnorderedElementsAre(HasName("S"), HasName("s"), HasName("f1"),
HasName("unskippable1")));
UnorderedElementsAre(hasName("S"), hasName("s"), hasName("f1"),
hasName("unskippable1")));
for (const auto &Pair : *IndexFile.Refs)
for (const auto &Ref : Pair.second)
EXPECT_THAT(Ref.Location.FileURI, EndsWith("good.h"));
@ -307,9 +307,9 @@ TEST_F(IndexActionTest, SkipNestedSymbols) {
}
})cpp");
IndexFileIn IndexFile = runIndexingAction(MainFilePath, {"-std=c++14"});
EXPECT_THAT(*IndexFile.Symbols, testing::Contains(HasName("foo")));
EXPECT_THAT(*IndexFile.Symbols, testing::Contains(HasName("Bar")));
EXPECT_THAT(*IndexFile.Symbols, Not(testing::Contains(HasName("Baz"))));
EXPECT_THAT(*IndexFile.Symbols, testing::Contains(hasName("foo")));
EXPECT_THAT(*IndexFile.Symbols, testing::Contains(hasName("Bar")));
EXPECT_THAT(*IndexFile.Symbols, Not(testing::Contains(hasName("Baz"))));
}
} // namespace
} // namespace clangd

View File

@ -32,14 +32,14 @@ namespace clang {
namespace clangd {
namespace {
MATCHER_P(Named, N, "") { return arg.Name == N; }
MATCHER_P(RefRange, Range, "") {
MATCHER_P(named, N, "") { return arg.Name == N; }
MATCHER_P(refRange, Range, "") {
return std::make_tuple(arg.Location.Start.line(), arg.Location.Start.column(),
arg.Location.End.line(), arg.Location.End.column()) ==
std::make_tuple(Range.start.line, Range.start.character,
Range.end.line, Range.end.character);
}
MATCHER_P(FileURI, F, "") { return StringRef(arg.Location.FileURI) == F; }
MATCHER_P(fileURI, F, "") { return StringRef(arg.Location.FileURI) == F; }
TEST(SymbolLocation, Position) {
using Position = SymbolLocation::Position;
@ -68,13 +68,13 @@ TEST(SymbolSlab, FindAndIterate) {
B.insert(symbol("X"));
EXPECT_EQ(nullptr, B.find(SymbolID("W")));
for (const char *Sym : {"X", "Y", "Z"})
EXPECT_THAT(B.find(SymbolID(Sym)), Pointee(Named(Sym)));
EXPECT_THAT(B.find(SymbolID(Sym)), Pointee(named(Sym)));
SymbolSlab S = std::move(B).build();
EXPECT_THAT(S, UnorderedElementsAre(Named("X"), Named("Y"), Named("Z")));
EXPECT_THAT(S, UnorderedElementsAre(named("X"), named("Y"), named("Z")));
EXPECT_EQ(S.end(), S.find(SymbolID("W")));
for (const char *Sym : {"X", "Y", "Z"})
EXPECT_THAT(*S.find(SymbolID(Sym)), Named(Sym));
EXPECT_THAT(*S.find(SymbolID(Sym)), named(Sym));
}
TEST(RelationSlab, Lookup) {
@ -488,10 +488,10 @@ TEST(MergeIndexTest, Refs) {
EXPECT_THAT(
std::move(Results).build(),
ElementsAre(Pair(
_, UnorderedElementsAre(AllOf(RefRange(Test1Code.range("Foo")),
FileURI("unittest:///test.cc")),
AllOf(RefRange(Test2Code.range("Foo")),
FileURI("unittest:///test2.cc"))))));
_, UnorderedElementsAre(AllOf(refRange(Test1Code.range("Foo")),
fileURI("unittest:///test.cc")),
AllOf(refRange(Test2Code.range("Foo")),
fileURI("unittest:///test2.cc"))))));
Request.Limit = 1;
RefSlab::Builder Results2;
@ -510,8 +510,8 @@ TEST(MergeIndexTest, Refs) {
Merge.refs(Request, [&](const Ref &O) { Results3.insert(Foo.ID, O); }));
EXPECT_THAT(std::move(Results3).build(),
ElementsAre(Pair(_, UnorderedElementsAre(AllOf(
RefRange(Test2Code.range("Foo")),
FileURI("unittest:///test2.cc"))))));
refRange(Test2Code.range("Foo")),
fileURI("unittest:///test2.cc"))))));
}
TEST(MergeIndexTest, IndexedFiles) {

View File

@ -40,7 +40,7 @@ protected:
std::string input() const { return InBuf; }
std::string output() { return Out.str(); }
std::string input_mirror() { return Mirror.str(); }
std::string inputMirror() { return Mirror.str(); }
};
// Echo is a simple server running on a transport:
@ -129,7 +129,7 @@ Notification exit: null
"Content-Length: 77\r\n\r\n"
R"({"error":{"code":88,"message":"trouble at mill"},"id":"wxyz","jsonrpc":"2.0"})";
EXPECT_EQ(output(), WantOutput);
EXPECT_EQ(trim(input_mirror()), trim(input()));
EXPECT_EQ(trim(inputMirror()), trim(input()));
}
// Runs an Echo session using the "delimited" input and pretty-printed output
@ -185,7 +185,7 @@ Notification exit: null
"jsonrpc": "2.0"
})";
EXPECT_EQ(output(), WantOutput);
EXPECT_EQ(trim(input_mirror()), trim(input()));
EXPECT_EQ(trim(inputMirror()), trim(input()));
}
// IO errors such as EOF ane reported.
@ -199,7 +199,7 @@ TEST_F(JSONTransportTest, EndOfFile) {
EXPECT_EQ(trim(E.log()), "Notification call: 1234");
EXPECT_TRUE(bool(Err)); // Ran into EOF with no handler signalling done.
consumeError(std::move(Err));
EXPECT_EQ(trim(input_mirror()), trim(input()));
EXPECT_EQ(trim(inputMirror()), trim(input()));
}
#endif

View File

@ -50,7 +50,7 @@ using ::testing::ElementsAreArray;
using ::testing::IsEmpty;
using ::testing::UnorderedElementsAreArray;
MATCHER_P(DeclNamed, Name, "") {
MATCHER_P(declNamed, Name, "") {
if (NamedDecl *ND = dyn_cast<NamedDecl>(arg))
if (ND->getName() == Name)
return true;
@ -61,7 +61,7 @@ MATCHER_P(DeclNamed, Name, "") {
return false;
}
MATCHER_P(DeclKind, Kind, "") {
MATCHER_P(declKind, Kind, "") {
if (NamedDecl *ND = dyn_cast<NamedDecl>(arg))
if (ND->getDeclKindName() == llvm::StringRef(Kind))
return true;
@ -74,7 +74,7 @@ MATCHER_P(DeclKind, Kind, "") {
// Matches if the Decl has template args equal to ArgName. If the decl is a
// NamedDecl and ArgName is an empty string it also matches.
MATCHER_P(WithTemplateArgs, ArgName, "") {
MATCHER_P(withTemplateArgs, ArgName, "") {
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(arg)) {
if (const auto *Args = FD->getTemplateSpecializationArgs()) {
std::string SpecializationArgs;
@ -97,13 +97,13 @@ MATCHER_P(WithTemplateArgs, ArgName, "") {
return false;
}
MATCHER_P(RangeIs, R, "") {
MATCHER_P(rangeIs, R, "") {
return arg.beginOffset() == R.Begin && arg.endOffset() == R.End;
}
MATCHER_P(PragmaTrivia, P, "") { return arg.Trivia == P; }
MATCHER_P(pragmaTrivia, P, "") { return arg.Trivia == P; }
MATCHER(EqInc, "") {
MATCHER(eqInc, "") {
Inclusion Actual = testing::get<0>(arg);
Inclusion Expected = testing::get<1>(arg);
return std::tie(Actual.HashLine, Actual.Written) ==
@ -123,8 +123,8 @@ TEST(ParsedASTTest, TopLevelDecls) {
auto AST = TU.build();
EXPECT_THAT(AST.getLocalTopLevelDecls(),
testing::UnorderedElementsAreArray(
{AllOf(DeclNamed("main"), DeclKind("Function")),
AllOf(DeclNamed("X"), DeclKind("VarTemplate"))}));
{AllOf(declNamed("main"), declKind("Function")),
AllOf(declNamed("X"), declKind("VarTemplate"))}));
}
TEST(ParsedASTTest, DoesNotGetIncludedTopDecls) {
@ -144,7 +144,7 @@ TEST(ParsedASTTest, DoesNotGetIncludedTopDecls) {
}
)cpp";
auto AST = TU.build();
EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(DeclNamed("main")));
EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(declNamed("main")));
}
TEST(ParsedASTTest, DoesNotGetImplicitTemplateTopDecls) {
@ -159,7 +159,7 @@ TEST(ParsedASTTest, DoesNotGetImplicitTemplateTopDecls) {
auto AST = TU.build();
EXPECT_THAT(AST.getLocalTopLevelDecls(),
ElementsAre(DeclNamed("f"), DeclNamed("s")));
ElementsAre(declNamed("f"), declNamed("s")));
}
TEST(ParsedASTTest,
@ -193,17 +193,17 @@ TEST(ParsedASTTest,
auto AST = TU.build();
EXPECT_THAT(
AST.getLocalTopLevelDecls(),
ElementsAreArray({AllOf(DeclNamed("f"), WithTemplateArgs("")),
AllOf(DeclNamed("f"), WithTemplateArgs("<bool>")),
AllOf(DeclNamed("f"), WithTemplateArgs("<double>")),
AllOf(DeclNamed("V"), WithTemplateArgs("")),
AllOf(DeclNamed("V"), WithTemplateArgs("<T *>")),
AllOf(DeclNamed("V"), WithTemplateArgs("<bool>")),
AllOf(DeclNamed("foo"), WithTemplateArgs("")),
AllOf(DeclNamed("i"), WithTemplateArgs("")),
AllOf(DeclNamed("d"), WithTemplateArgs("")),
AllOf(DeclNamed("foo"), WithTemplateArgs("<T *>")),
AllOf(DeclNamed("foo"), WithTemplateArgs("<bool>"))}));
ElementsAreArray({AllOf(declNamed("f"), withTemplateArgs("")),
AllOf(declNamed("f"), withTemplateArgs("<bool>")),
AllOf(declNamed("f"), withTemplateArgs("<double>")),
AllOf(declNamed("V"), withTemplateArgs("")),
AllOf(declNamed("V"), withTemplateArgs("<T *>")),
AllOf(declNamed("V"), withTemplateArgs("<bool>")),
AllOf(declNamed("foo"), withTemplateArgs("")),
AllOf(declNamed("i"), withTemplateArgs("")),
AllOf(declNamed("d"), withTemplateArgs("")),
AllOf(declNamed("foo"), withTemplateArgs("<T *>")),
AllOf(declNamed("foo"), withTemplateArgs("<bool>"))}));
}
TEST(ParsedASTTest, IgnoresDelayedTemplateParsing) {
@ -351,7 +351,7 @@ TEST(ParsedASTTest, CollectsMainFileMacroExpansions) {
testing::UnorderedElementsAreArray(TestCase.points()));
}
MATCHER_P(WithFileName, Inc, "") { return arg.FileName == Inc; }
MATCHER_P(withFileName, Inc, "") { return arg.FileName == Inc; }
TEST(ParsedASTTest, ReplayPreambleForTidyCheckers) {
struct Inclusion {
@ -447,7 +447,7 @@ TEST(ParsedASTTest, ReplayPreambleForTidyCheckers) {
EXPECT_EQ(Inc.HashOffset, HashLocs[I]);
auto IncRange = IncludeRanges[I];
EXPECT_THAT(Inc.IncTok.range(SM), RangeIs(IncRange));
EXPECT_THAT(Inc.IncTok.range(SM), rangeIs(IncRange));
EXPECT_EQ(Inc.IncTok.kind(), tok::identifier);
EXPECT_EQ(Inc.IncDirective,
Code.substr(IncRange.Begin, IncRange.End - IncRange.Begin));
@ -512,7 +512,7 @@ TEST(ParsedASTTest, PatchesAdditionalIncludes) {
// Ensure source location information is correct, including resolved paths.
EXPECT_THAT(PatchedAST->getIncludeStructure().MainFileIncludes,
testing::Pointwise(
EqInc(), ExpectedAST.getIncludeStructure().MainFileIncludes));
eqInc(), ExpectedAST.getIncludeStructure().MainFileIncludes));
// Ensure file proximity signals are correct.
auto &SM = PatchedAST->getSourceManager();
auto &FM = SM.getFileManager();
@ -556,7 +556,7 @@ TEST(ParsedASTTest, PatchesDeletedIncludes) {
// Ensure source location information is correct.
EXPECT_THAT(PatchedAST->getIncludeStructure().MainFileIncludes,
testing::Pointwise(
EqInc(), ExpectedAST.getIncludeStructure().MainFileIncludes));
eqInc(), ExpectedAST.getIncludeStructure().MainFileIncludes));
// Ensure file proximity signals are correct.
auto &SM = ExpectedAST.getSourceManager();
auto &FM = SM.getFileManager();
@ -594,7 +594,7 @@ bool mainIsGuarded(const ParsedAST &AST) {
.isFileMultipleIncludeGuarded(MainFE);
}
MATCHER_P(Diag, Desc, "") {
MATCHER_P(diag, Desc, "") {
return llvm::StringRef(arg.Message).contains(Desc);
}
@ -649,7 +649,7 @@ TEST(ParsedASTTest, HeaderGuardsSelfInclude) {
)cpp";
auto AST = TU.build();
EXPECT_THAT(*AST.getDiagnostics(),
ElementsAre(Diag("recursively when building a preamble")));
ElementsAre(diag("recursively when building a preamble")));
EXPECT_FALSE(mainIsGuarded(AST));
TU.Code = R"cpp(
@ -657,7 +657,7 @@ TEST(ParsedASTTest, HeaderGuardsSelfInclude) {
#include "self.h" // error-ok
)cpp";
AST = TU.build();
EXPECT_THAT(*AST.getDiagnostics(), ElementsAre(Diag("nested too deeply")));
EXPECT_THAT(*AST.getDiagnostics(), ElementsAre(diag("nested too deeply")));
EXPECT_FALSE(mainIsGuarded(AST));
TU.Code = R"cpp(
@ -696,7 +696,7 @@ TEST(ParsedASTTest, HeaderGuardsSelfInclude) {
)cpp";
AST = TU.build();
EXPECT_THAT(*AST.getDiagnostics(),
ElementsAre(Diag("recursively when building a preamble")));
ElementsAre(diag("recursively when building a preamble")));
EXPECT_TRUE(mainIsGuarded(AST));
TU.Code = R"cpp(
@ -720,7 +720,7 @@ TEST(ParsedASTTest, HeaderGuardsSelfInclude) {
)cpp";
AST = TU.build();
EXPECT_THAT(*AST.getDiagnostics(),
ElementsAre(Diag("recursively when building a preamble")));
ElementsAre(diag("recursively when building a preamble")));
EXPECT_FALSE(mainIsGuarded(AST));
TU.Code = R"cpp(
@ -732,7 +732,7 @@ TEST(ParsedASTTest, HeaderGuardsSelfInclude) {
)cpp";
AST = TU.build();
EXPECT_THAT(*AST.getDiagnostics(),
ElementsAre(Diag("recursively when building a preamble")));
ElementsAre(diag("recursively when building a preamble")));
EXPECT_FALSE(mainIsGuarded(AST));
TU.Code = R"cpp(
@ -753,7 +753,7 @@ TEST(ParsedASTTest, HeaderGuardsSelfInclude) {
)cpp";
AST = TU.build();
EXPECT_THAT(*AST.getDiagnostics(),
ElementsAre(Diag("recursively when building a preamble")));
ElementsAre(diag("recursively when building a preamble")));
EXPECT_TRUE(mainIsGuarded(AST));
TU.Code = R"cpp(
@ -763,7 +763,7 @@ TEST(ParsedASTTest, HeaderGuardsSelfInclude) {
)cpp";
AST = TU.build();
EXPECT_THAT(*AST.getDiagnostics(),
ElementsAre(Diag("recursively when building a preamble")));
ElementsAre(diag("recursively when building a preamble")));
EXPECT_TRUE(mainIsGuarded(AST));
}
@ -814,14 +814,14 @@ TEST(ParsedASTTest, HeaderGuardsImplIface) {
// The diagnostic is unfortunate in this case, but correct per our model.
// Ultimately the include is skipped and the code is parsed correctly though.
EXPECT_THAT(*AST.getDiagnostics(),
ElementsAre(Diag("in included file: main file cannot be included "
ElementsAre(diag("in included file: main file cannot be included "
"recursively when building a preamble")));
EXPECT_FALSE(mainIsGuarded(AST));
// Interface is pragma once guarded, same thing.
TU.AdditionalFiles = {{"iface.h", once(Interface)}};
AST = TU.build();
EXPECT_THAT(*AST.getDiagnostics(),
ElementsAre(Diag("in included file: main file cannot be included "
ElementsAre(diag("in included file: main file cannot be included "
"recursively when building a preamble")));
EXPECT_FALSE(mainIsGuarded(AST));
}
@ -842,9 +842,9 @@ TEST(ParsedASTTest, DiscoversPragmaMarks) {
)cpp";
auto AST = TU.build();
EXPECT_THAT(AST.getMarks(), ElementsAre(PragmaTrivia(" In Preamble"),
PragmaTrivia(" - Something Impl"),
PragmaTrivia(" End")));
EXPECT_THAT(AST.getMarks(), ElementsAre(pragmaTrivia(" In Preamble"),
pragmaTrivia(" - Something Impl"),
pragmaTrivia(" End")));
}
} // namespace

View File

@ -139,7 +139,7 @@ TEST(QualityTests, SymbolRelevanceSignalExtraction) {
EXPECT_FLOAT_EQ(Relevance.SemaFileProximityScore, 1.0f)
<< "Current file and header";
auto constructShadowDeclCompletionResult = [&](const std::string DeclName) {
auto ConstructShadowDeclCompletionResult = [&](const std::string DeclName) {
auto *Shadow =
*dyn_cast<UsingDecl>(&findDecl(AST, [&](const NamedDecl &ND) {
if (const UsingDecl *Using = dyn_cast<UsingDecl>(&ND))
@ -154,10 +154,10 @@ TEST(QualityTests, SymbolRelevanceSignalExtraction) {
};
Relevance = {};
Relevance.merge(constructShadowDeclCompletionResult("Bar"));
Relevance.merge(ConstructShadowDeclCompletionResult("Bar"));
EXPECT_FLOAT_EQ(Relevance.SemaFileProximityScore, 1.0f)
<< "Using declaration in main file";
Relevance.merge(constructShadowDeclCompletionResult("FLAGS_FOO"));
Relevance.merge(ConstructShadowDeclCompletionResult("FLAGS_FOO"));
EXPECT_FLOAT_EQ(Relevance.SemaFileProximityScore, 1.0f)
<< "Using declaration in main file";

View File

@ -114,8 +114,8 @@ DirectIncludes:
...
)";
MATCHER_P(ID, I, "") { return arg.ID == cantFail(SymbolID::fromStr(I)); }
MATCHER_P(QName, Name, "") { return (arg.Scope + arg.Name).str() == Name; }
MATCHER_P(id, I, "") { return arg.ID == cantFail(SymbolID::fromStr(I)); }
MATCHER_P(qName, Name, "") { return (arg.Scope + arg.Name).str() == Name; }
MATCHER_P2(IncludeHeaderWithRef, IncludeHeader, References, "") {
return (arg.IncludeHeader == IncludeHeader) && (arg.References == References);
}
@ -134,14 +134,14 @@ TEST(SerializationTest, YAMLConversions) {
ASSERT_TRUE(bool(ParsedYAML->Symbols));
EXPECT_THAT(
*ParsedYAML->Symbols,
UnorderedElementsAre(ID("057557CEBF6E6B2D"), ID("057557CEBF6E6B2E")));
UnorderedElementsAre(id("057557CEBF6E6B2D"), id("057557CEBF6E6B2E")));
auto Sym1 = *ParsedYAML->Symbols->find(
cantFail(SymbolID::fromStr("057557CEBF6E6B2D")));
auto Sym2 = *ParsedYAML->Symbols->find(
cantFail(SymbolID::fromStr("057557CEBF6E6B2E")));
EXPECT_THAT(Sym1, QName("clang::Foo1"));
EXPECT_THAT(Sym1, qName("clang::Foo1"));
EXPECT_EQ(Sym1.Signature, "");
EXPECT_EQ(Sym1.Documentation, "Foo doc");
EXPECT_EQ(Sym1.ReturnType, "int");
@ -154,7 +154,7 @@ TEST(SerializationTest, YAMLConversions) {
UnorderedElementsAre(IncludeHeaderWithRef("include1", 7u),
IncludeHeaderWithRef("include2", 3u)));
EXPECT_THAT(Sym2, QName("clang::Foo2"));
EXPECT_THAT(Sym2, qName("clang::Foo2"));
EXPECT_EQ(Sym2.Signature, "-sig");
EXPECT_EQ(Sym2.ReturnType, "");
EXPECT_EQ(llvm::StringRef(Sym2.CanonicalDeclaration.FileURI),
@ -194,20 +194,20 @@ TEST(SerializationTest, YAMLConversions) {
EXPECT_EQ(IGNDeserialized.Flags, IncludeGraphNode::SourceFlag(1));
}
std::vector<std::string> YAMLFromSymbols(const SymbolSlab &Slab) {
std::vector<std::string> yamlFromSymbols(const SymbolSlab &Slab) {
std::vector<std::string> Result;
for (const auto &Sym : Slab)
Result.push_back(toYAML(Sym));
return Result;
}
std::vector<std::string> YAMLFromRefs(const RefSlab &Slab) {
std::vector<std::string> yamlFromRefs(const RefSlab &Slab) {
std::vector<std::string> Result;
for (const auto &Refs : Slab)
Result.push_back(toYAML(Refs));
return Result;
}
std::vector<std::string> YAMLFromRelations(const RelationSlab &Slab) {
std::vector<std::string> yamlFromRelations(const RelationSlab &Slab) {
std::vector<std::string> Result;
for (const auto &Rel : Slab)
Result.push_back(toYAML(Rel));
@ -230,12 +230,12 @@ TEST(SerializationTest, BinaryConversions) {
ASSERT_TRUE(In2->Relations);
// Assert the YAML serializations match, for nice comparisons and diffs.
EXPECT_THAT(YAMLFromSymbols(*In2->Symbols),
UnorderedElementsAreArray(YAMLFromSymbols(*In->Symbols)));
EXPECT_THAT(YAMLFromRefs(*In2->Refs),
UnorderedElementsAreArray(YAMLFromRefs(*In->Refs)));
EXPECT_THAT(YAMLFromRelations(*In2->Relations),
UnorderedElementsAreArray(YAMLFromRelations(*In->Relations)));
EXPECT_THAT(yamlFromSymbols(*In2->Symbols),
UnorderedElementsAreArray(yamlFromSymbols(*In->Symbols)));
EXPECT_THAT(yamlFromRefs(*In2->Refs),
UnorderedElementsAreArray(yamlFromRefs(*In->Refs)));
EXPECT_THAT(yamlFromRelations(*In2->Relations),
UnorderedElementsAreArray(yamlFromRelations(*In->Relations)));
}
TEST(SerializationTest, SrcsTest) {
@ -265,10 +265,10 @@ TEST(SerializationTest, SrcsTest) {
ASSERT_TRUE(In->Sources);
ASSERT_TRUE(In->Sources->count(IGN.URI));
// Assert the YAML serializations match, for nice comparisons and diffs.
EXPECT_THAT(YAMLFromSymbols(*In->Symbols),
UnorderedElementsAreArray(YAMLFromSymbols(*In->Symbols)));
EXPECT_THAT(YAMLFromRefs(*In->Refs),
UnorderedElementsAreArray(YAMLFromRefs(*In->Refs)));
EXPECT_THAT(yamlFromSymbols(*In->Symbols),
UnorderedElementsAreArray(yamlFromSymbols(*In->Symbols)));
EXPECT_THAT(yamlFromRefs(*In->Refs),
UnorderedElementsAreArray(yamlFromRefs(*In->Refs)));
auto IGNDeserialized = In->Sources->lookup(IGN.URI);
EXPECT_EQ(IGNDeserialized.Digest, IGN.Digest);
EXPECT_EQ(IGNDeserialized.DirectIncludes, IGN.DirectIncludes);

View File

@ -34,7 +34,7 @@ MATCHER_P2(Pos, Line, Col, "") {
return arg.line == int(Line) && arg.character == int(Col);
}
MATCHER_P(MacroName, Name, "") { return arg.Name == Name; }
MATCHER_P(macroName, Name, "") { return arg.Name == Name; }
/// A helper to make tests easier to read.
Position position(int Line, int Character) {
@ -542,7 +542,7 @@ TEST(SourceCodeTests, GetMacros) {
ASSERT_TRUE(Id);
auto Result = locateMacroAt(*Id, AST.getPreprocessor());
ASSERT_TRUE(Result);
EXPECT_THAT(*Result, MacroName("MACRO"));
EXPECT_THAT(*Result, macroName("MACRO"));
}
TEST(SourceCodeTests, WorksAtBeginOfFile) {
@ -556,7 +556,7 @@ TEST(SourceCodeTests, WorksAtBeginOfFile) {
ASSERT_TRUE(Id);
auto Result = locateMacroAt(*Id, AST.getPreprocessor());
ASSERT_TRUE(Result);
EXPECT_THAT(*Result, MacroName("MACRO"));
EXPECT_THAT(*Result, macroName("MACRO"));
}
TEST(SourceCodeTests, IsInsideMainFile) {

View File

@ -45,30 +45,30 @@ using ::testing::UnorderedElementsAre;
using ::testing::UnorderedElementsAreArray;
// GMock helpers for matching Symbol.
MATCHER_P(Labeled, Label, "") {
MATCHER_P(labeled, Label, "") {
return (arg.Name + arg.Signature).str() == Label;
}
MATCHER_P(ReturnType, D, "") { return arg.ReturnType == D; }
MATCHER_P(Doc, D, "") { return arg.Documentation == D; }
MATCHER_P(Snippet, S, "") {
MATCHER_P(returnType, D, "") { return arg.ReturnType == D; }
MATCHER_P(doc, D, "") { return arg.Documentation == D; }
MATCHER_P(snippet, S, "") {
return (arg.Name + arg.CompletionSnippetSuffix).str() == S;
}
MATCHER_P(QName, Name, "") { return (arg.Scope + arg.Name).str() == Name; }
MATCHER_P(HasName, Name, "") { return arg.Name == Name; }
MATCHER_P(TemplateArgs, TemplArgs, "") {
MATCHER_P(qName, Name, "") { return (arg.Scope + arg.Name).str() == Name; }
MATCHER_P(hasName, Name, "") { return arg.Name == Name; }
MATCHER_P(templateArgs, TemplArgs, "") {
return arg.TemplateSpecializationArgs == TemplArgs;
}
MATCHER_P(DeclURI, P, "") {
MATCHER_P(declURI, P, "") {
return StringRef(arg.CanonicalDeclaration.FileURI) == P;
}
MATCHER_P(DefURI, P, "") { return StringRef(arg.Definition.FileURI) == P; }
MATCHER(IncludeHeader, "") { return !arg.IncludeHeaders.empty(); }
MATCHER_P(IncludeHeader, P, "") {
MATCHER_P(defURI, P, "") { return StringRef(arg.Definition.FileURI) == P; }
MATCHER(includeHeader, "") { return !arg.IncludeHeaders.empty(); }
MATCHER_P(includeHeader, P, "") {
return (arg.IncludeHeaders.size() == 1) &&
(arg.IncludeHeaders.begin()->IncludeHeader == P);
}
MATCHER_P2(IncludeHeaderWithRef, IncludeHeader, References, "") {
return (arg.IncludeHeader == IncludeHeader) && (arg.References == References);
MATCHER_P2(IncludeHeaderWithRef, includeHeader, References, "") {
return (arg.IncludeHeader == includeHeader) && (arg.References == References);
}
bool rangesMatch(const SymbolLocation &Loc, const Range &R) {
return std::make_tuple(Loc.Start.line(), Loc.Start.column(), Loc.End.line(),
@ -76,23 +76,23 @@ bool rangesMatch(const SymbolLocation &Loc, const Range &R) {
std::make_tuple(R.start.line, R.start.character, R.end.line,
R.end.character);
}
MATCHER_P(DeclRange, Pos, "") {
MATCHER_P(declRange, Pos, "") {
return rangesMatch(arg.CanonicalDeclaration, Pos);
}
MATCHER_P(DefRange, Pos, "") { return rangesMatch(arg.Definition, Pos); }
MATCHER_P(RefCount, R, "") { return int(arg.References) == R; }
MATCHER_P(ForCodeCompletion, IsIndexedForCodeCompletion, "") {
MATCHER_P(defRange, Pos, "") { return rangesMatch(arg.Definition, Pos); }
MATCHER_P(refCount, R, "") { return int(arg.References) == R; }
MATCHER_P(forCodeCompletion, IsIndexedForCodeCompletion, "") {
return static_cast<bool>(arg.Flags & Symbol::IndexedForCodeCompletion) ==
IsIndexedForCodeCompletion;
}
MATCHER(Deprecated, "") { return arg.Flags & Symbol::Deprecated; }
MATCHER(ImplementationDetail, "") {
MATCHER(deprecated, "") { return arg.Flags & Symbol::Deprecated; }
MATCHER(implementationDetail, "") {
return arg.Flags & Symbol::ImplementationDetail;
}
MATCHER(VisibleOutsideFile, "") {
MATCHER(visibleOutsideFile, "") {
return static_cast<bool>(arg.Flags & Symbol::VisibleOutsideFile);
}
MATCHER(RefRange, "") {
MATCHER(refRange, "") {
const Ref &Pos = ::testing::get<0>(arg);
const Range &Range = ::testing::get<1>(arg);
return rangesMatch(Pos.Location, Range);
@ -101,8 +101,8 @@ MATCHER_P2(OverriddenBy, Subject, Object, "") {
return arg == Relation{Subject.ID, RelationKind::OverriddenBy, Object.ID};
}
::testing::Matcher<const std::vector<Ref> &>
HaveRanges(const std::vector<Range> Ranges) {
return ::testing::UnorderedPointwise(RefRange(), Ranges);
haveRanges(const std::vector<Range> Ranges) {
return ::testing::UnorderedPointwise(refRange(), Ranges);
}
class ShouldCollectSymbolTest : public ::testing::Test {
@ -378,28 +378,28 @@ TEST_F(SymbolCollectorTest, CollectSymbols) {
runSymbolCollector(Header, /*Main=*/"");
EXPECT_THAT(Symbols,
UnorderedElementsAreArray(
{AllOf(QName("Foo"), ForCodeCompletion(true)),
AllOf(QName("Foo::Foo"), ForCodeCompletion(false)),
AllOf(QName("Foo::Foo"), ForCodeCompletion(false)),
AllOf(QName("Foo::f"), ForCodeCompletion(false)),
AllOf(QName("Foo::~Foo"), ForCodeCompletion(false)),
AllOf(QName("Foo::operator="), ForCodeCompletion(false)),
AllOf(QName("Foo::Nested"), ForCodeCompletion(false)),
AllOf(QName("Foo::Nested::f"), ForCodeCompletion(false)),
AllOf(QName("ClassInLambda"), ForCodeCompletion(false)),
AllOf(QName("Friend"), ForCodeCompletion(true)),
AllOf(QName("f1"), ForCodeCompletion(true)),
AllOf(QName("f2"), ForCodeCompletion(true)),
AllOf(QName("KInt"), ForCodeCompletion(true)),
AllOf(QName("kStr"), ForCodeCompletion(true)),
AllOf(QName("foo"), ForCodeCompletion(true)),
AllOf(QName("foo::bar"), ForCodeCompletion(true)),
AllOf(QName("foo::int32"), ForCodeCompletion(true)),
AllOf(QName("foo::int32_t"), ForCodeCompletion(true)),
AllOf(QName("foo::v1"), ForCodeCompletion(true)),
AllOf(QName("foo::bar::v2"), ForCodeCompletion(true)),
AllOf(QName("foo::v2"), ForCodeCompletion(true)),
AllOf(QName("foo::baz"), ForCodeCompletion(true))}));
{AllOf(qName("Foo"), forCodeCompletion(true)),
AllOf(qName("Foo::Foo"), forCodeCompletion(false)),
AllOf(qName("Foo::Foo"), forCodeCompletion(false)),
AllOf(qName("Foo::f"), forCodeCompletion(false)),
AllOf(qName("Foo::~Foo"), forCodeCompletion(false)),
AllOf(qName("Foo::operator="), forCodeCompletion(false)),
AllOf(qName("Foo::Nested"), forCodeCompletion(false)),
AllOf(qName("Foo::Nested::f"), forCodeCompletion(false)),
AllOf(qName("ClassInLambda"), forCodeCompletion(false)),
AllOf(qName("Friend"), forCodeCompletion(true)),
AllOf(qName("f1"), forCodeCompletion(true)),
AllOf(qName("f2"), forCodeCompletion(true)),
AllOf(qName("KInt"), forCodeCompletion(true)),
AllOf(qName("kStr"), forCodeCompletion(true)),
AllOf(qName("foo"), forCodeCompletion(true)),
AllOf(qName("foo::bar"), forCodeCompletion(true)),
AllOf(qName("foo::int32"), forCodeCompletion(true)),
AllOf(qName("foo::int32_t"), forCodeCompletion(true)),
AllOf(qName("foo::v1"), forCodeCompletion(true)),
AllOf(qName("foo::bar::v2"), forCodeCompletion(true)),
AllOf(qName("foo::v2"), forCodeCompletion(true)),
AllOf(qName("foo::baz"), forCodeCompletion(true))}));
}
TEST_F(SymbolCollectorTest, FileLocal) {
@ -422,13 +422,13 @@ TEST_F(SymbolCollectorTest, FileLocal) {
runSymbolCollector(Header, Main);
EXPECT_THAT(Symbols,
UnorderedElementsAre(
AllOf(QName("Foo"), VisibleOutsideFile()),
AllOf(QName("bar"), VisibleOutsideFile()),
AllOf(QName("a"), Not(VisibleOutsideFile())),
AllOf(QName("B"), Not(VisibleOutsideFile())),
AllOf(QName("c"), Not(VisibleOutsideFile())),
AllOf(qName("Foo"), visibleOutsideFile()),
AllOf(qName("bar"), visibleOutsideFile()),
AllOf(qName("a"), Not(visibleOutsideFile())),
AllOf(qName("B"), Not(visibleOutsideFile())),
AllOf(qName("c"), Not(visibleOutsideFile())),
// FIXME: ForwardDecl likely *is* visible outside.
AllOf(QName("ForwardDecl"), Not(VisibleOutsideFile()))));
AllOf(qName("ForwardDecl"), Not(visibleOutsideFile()))));
}
TEST_F(SymbolCollectorTest, Template) {
@ -444,17 +444,17 @@ TEST_F(SymbolCollectorTest, Template) {
runSymbolCollector(Header.code(), /*Main=*/"");
EXPECT_THAT(Symbols,
UnorderedElementsAre(
AllOf(QName("Tmpl"), DeclRange(Header.range()),
ForCodeCompletion(true)),
AllOf(QName("Tmpl"), DeclRange(Header.range("specdecl")),
ForCodeCompletion(false)),
AllOf(QName("Tmpl"), DeclRange(Header.range("partspecdecl")),
ForCodeCompletion(false)),
AllOf(QName("Tmpl::x"), DeclRange(Header.range("xdecl")),
ForCodeCompletion(false))));
AllOf(qName("Tmpl"), declRange(Header.range()),
forCodeCompletion(true)),
AllOf(qName("Tmpl"), declRange(Header.range("specdecl")),
forCodeCompletion(false)),
AllOf(qName("Tmpl"), declRange(Header.range("partspecdecl")),
forCodeCompletion(false)),
AllOf(qName("Tmpl::x"), declRange(Header.range("xdecl")),
forCodeCompletion(false))));
}
TEST_F(SymbolCollectorTest, TemplateArgs) {
TEST_F(SymbolCollectorTest, templateArgs) {
Annotations Header(R"(
template <class X> class $barclasstemp[[Bar]] {};
template <class T, class U, template<typename> class Z, int Q>
@ -493,30 +493,30 @@ TEST_F(SymbolCollectorTest, TemplateArgs) {
EXPECT_THAT(
Symbols,
AllOf(
Contains(AllOf(QName("Tmpl"), TemplateArgs("<int, bool, Bar, 3>"),
DeclRange(Header.range("specdecl")),
ForCodeCompletion(false))),
Contains(AllOf(QName("Tmpl"), TemplateArgs("<bool, U, Bar, T>"),
DeclRange(Header.range("partspecdecl")),
ForCodeCompletion(false))),
Contains(AllOf(QName("Foo"), TemplateArgs("<Bar<int>, int, double>"),
DeclRange(Header.range("parampack")),
ForCodeCompletion(false))),
Contains(AllOf(QName("Foo"), TemplateArgs("<T, T>"),
DeclRange(Header.range("parampackpartial")),
ForCodeCompletion(false))),
Contains(AllOf(QName("Baz"), TemplateArgs("<3, 5, 8>"),
DeclRange(Header.range("parampacknontype")),
ForCodeCompletion(false))),
Contains(AllOf(QName("Baz"), TemplateArgs("<T, T>"),
DeclRange(Header.range("parampacknontypepartial")),
ForCodeCompletion(false))),
Contains(AllOf(QName("Foz"), TemplateArgs("<Bar, Bar>"),
DeclRange(Header.range("parampacktempltempl")),
ForCodeCompletion(false))),
Contains(AllOf(QName("Foz"), TemplateArgs("<T, T>"),
DeclRange(Header.range("parampacktempltemplpartial")),
ForCodeCompletion(false)))));
Contains(AllOf(qName("Tmpl"), templateArgs("<int, bool, Bar, 3>"),
declRange(Header.range("specdecl")),
forCodeCompletion(false))),
Contains(AllOf(qName("Tmpl"), templateArgs("<bool, U, Bar, T>"),
declRange(Header.range("partspecdecl")),
forCodeCompletion(false))),
Contains(AllOf(qName("Foo"), templateArgs("<Bar<int>, int, double>"),
declRange(Header.range("parampack")),
forCodeCompletion(false))),
Contains(AllOf(qName("Foo"), templateArgs("<T, T>"),
declRange(Header.range("parampackpartial")),
forCodeCompletion(false))),
Contains(AllOf(qName("Baz"), templateArgs("<3, 5, 8>"),
declRange(Header.range("parampacknontype")),
forCodeCompletion(false))),
Contains(AllOf(qName("Baz"), templateArgs("<T, T>"),
declRange(Header.range("parampacknontypepartial")),
forCodeCompletion(false))),
Contains(AllOf(qName("Foz"), templateArgs("<Bar, Bar>"),
declRange(Header.range("parampacktempltempl")),
forCodeCompletion(false))),
Contains(AllOf(qName("Foz"), templateArgs("<T, T>"),
declRange(Header.range("parampacktempltemplpartial")),
forCodeCompletion(false)))));
}
TEST_F(SymbolCollectorTest, ObjCSymbols) {
@ -550,10 +550,10 @@ TEST_F(SymbolCollectorTest, ObjCSymbols) {
runSymbolCollector(Header, /*Main=*/"", {"-fblocks", "-xobjective-c++"});
EXPECT_THAT(Symbols,
UnorderedElementsAre(
QName("Person"), QName("Person::someMethodName:lastName:"),
AllOf(QName("MyCategory"), ForCodeCompletion(false)),
QName("Person::someMethodName2:"), QName("MyProtocol"),
QName("MyProtocol::someMethodName3:")));
qName("Person"), qName("Person::someMethodName:lastName:"),
AllOf(qName("MyCategory"), forCodeCompletion(false)),
qName("Person::someMethodName2:"), qName("MyProtocol"),
qName("MyProtocol::someMethodName3:")));
}
TEST_F(SymbolCollectorTest, ObjCPropertyImpl) {
@ -567,8 +567,8 @@ TEST_F(SymbolCollectorTest, ObjCPropertyImpl) {
)";
TestFileName = testPath("test.m");
runSymbolCollector(Header, /*Main=*/"", {"-xobjective-c++"});
EXPECT_THAT(Symbols, Contains(QName("Container")));
EXPECT_THAT(Symbols, Contains(QName("Container::magic")));
EXPECT_THAT(Symbols, Contains(qName("Container")));
EXPECT_THAT(Symbols, Contains(qName("Container::magic")));
// FIXME: Results also contain Container::_magic on some platforms.
// Figure out why it's platform-dependent.
}
@ -599,14 +599,14 @@ TEST_F(SymbolCollectorTest, ObjCLocations) {
{"-xobjective-c++", "-Wno-objc-root-class"});
EXPECT_THAT(Symbols,
UnorderedElementsAre(
AllOf(QName("Dog"), DeclRange(Header.range("dogdecl")),
DefRange(Main.range("dogdef"))),
AllOf(QName("Fluffy"), DeclRange(Header.range("fluffydecl")),
DefRange(Main.range("fluffydef"))),
AllOf(QName("CatDog"), DeclRange(Main.range("catdog")),
DefRange(Main.range("catdog"))),
AllOf(QName("Ruff"), DeclRange(Main.range("ruff")),
DefRange(Main.range("ruff")))));
AllOf(qName("Dog"), declRange(Header.range("dogdecl")),
defRange(Main.range("dogdef"))),
AllOf(qName("Fluffy"), declRange(Header.range("fluffydecl")),
defRange(Main.range("fluffydef"))),
AllOf(qName("CatDog"), declRange(Main.range("catdog")),
defRange(Main.range("catdog"))),
AllOf(qName("Ruff"), declRange(Main.range("ruff")),
defRange(Main.range("ruff")))));
}
TEST_F(SymbolCollectorTest, ObjCForwardDecls) {
@ -634,12 +634,12 @@ TEST_F(SymbolCollectorTest, ObjCForwardDecls) {
{"-xobjective-c++", "-Wno-objc-root-class"});
EXPECT_THAT(Symbols,
UnorderedElementsAre(
AllOf(QName("CatDog"), DeclRange(Header.range("catdogdecl")),
DefRange(Main.range("catdogdef"))),
AllOf(QName("Dog"), DeclRange(Main.range("dogdecl")),
DefRange(Main.range("dogdef"))),
AllOf(QName("Barker"), DeclRange(Main.range("barkerdecl"))),
QName("Barker::woof"), QName("Dog::woof")));
AllOf(qName("CatDog"), declRange(Header.range("catdogdecl")),
defRange(Main.range("catdogdef"))),
AllOf(qName("Dog"), declRange(Main.range("dogdecl")),
defRange(Main.range("dogdef"))),
AllOf(qName("Barker"), declRange(Main.range("barkerdecl"))),
qName("Barker::woof"), qName("Dog::woof")));
}
TEST_F(SymbolCollectorTest, ObjCClassExtensions) {
@ -659,8 +659,8 @@ TEST_F(SymbolCollectorTest, ObjCClassExtensions) {
{"-xobjective-c++", "-Wno-objc-root-class"});
EXPECT_THAT(Symbols,
UnorderedElementsAre(
AllOf(QName("Cat"), DeclRange(Header.range("catdecl"))),
QName("Cat::meow"), QName("Cat::pur")));
AllOf(qName("Cat"), declRange(Header.range("catdecl"))),
qName("Cat::meow"), qName("Cat::pur")));
}
TEST_F(SymbolCollectorTest, Locations) {
@ -687,15 +687,15 @@ o]]();
runSymbolCollector(Header.code(), Main.code());
EXPECT_THAT(Symbols,
UnorderedElementsAre(
AllOf(QName("X"), DeclRange(Header.range("xdecl")),
DefRange(Main.range("xdef"))),
AllOf(QName("Cls"), DeclRange(Header.range("clsdecl")),
DefRange(Main.range("clsdef"))),
AllOf(QName("print"), DeclRange(Header.range("printdecl")),
DefRange(Main.range("printdef"))),
AllOf(QName("Z"), DeclRange(Header.range("zdecl"))),
AllOf(QName("foo"), DeclRange(Header.range("foodecl"))),
AllOf(QName("Y"), DeclRange(Main.range("ydecl")))));
AllOf(qName("X"), declRange(Header.range("xdecl")),
defRange(Main.range("xdef"))),
AllOf(qName("Cls"), declRange(Header.range("clsdecl")),
defRange(Main.range("clsdef"))),
AllOf(qName("print"), declRange(Header.range("printdecl")),
defRange(Main.range("printdef"))),
AllOf(qName("Z"), declRange(Header.range("zdecl"))),
AllOf(qName("foo"), declRange(Header.range("foodecl"))),
AllOf(qName("Y"), declRange(Main.range("ydecl")))));
}
TEST_F(SymbolCollectorTest, Refs) {
@ -737,14 +737,14 @@ TEST_F(SymbolCollectorTest, Refs) {
runSymbolCollector(Header.code(),
(Main.code() + SymbolsOnlyInMainCode.code()).str());
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Foo").ID,
HaveRanges(Main.ranges("foo")))));
haveRanges(Main.ranges("foo")))));
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Bar").ID,
HaveRanges(Main.ranges("bar")))));
haveRanges(Main.ranges("bar")))));
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "func").ID,
HaveRanges(Main.ranges("func")))));
haveRanges(Main.ranges("func")))));
EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(Symbols, "NS").ID, _))));
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "MACRO").ID,
HaveRanges(Main.ranges("macro")))));
haveRanges(Main.ranges("macro")))));
// - (a, b) externally visible and should have refs.
// - (c, FUNC) externally invisible and had no refs collected.
auto MainSymbols =
@ -872,18 +872,18 @@ TEST_F(SymbolCollectorTest, MacroRefInHeader) {
runSymbolCollector(Header.code(), "");
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "FOO").ID,
HaveRanges(Header.ranges("foo")))));
haveRanges(Header.ranges("foo")))));
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "BAR").ID,
HaveRanges(Header.ranges("bar")))));
haveRanges(Header.ranges("bar")))));
// No unique ID for multiple symbols named UD. Check for ranges only.
EXPECT_THAT(Refs, Contains(Pair(_, HaveRanges(Header.ranges("ud1")))));
EXPECT_THAT(Refs, Contains(Pair(_, HaveRanges(Header.ranges("ud2")))));
EXPECT_THAT(Refs, Contains(Pair(_, haveRanges(Header.ranges("ud1")))));
EXPECT_THAT(Refs, Contains(Pair(_, haveRanges(Header.ranges("ud2")))));
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "CONCAT").ID,
HaveRanges(Header.ranges("concat")))));
haveRanges(Header.ranges("concat")))));
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "PREPEND").ID,
HaveRanges(Header.ranges("prepend")))));
haveRanges(Header.ranges("prepend")))));
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "MACROA").ID,
HaveRanges(Header.ranges("macroa")))));
haveRanges(Header.ranges("macroa")))));
}
TEST_F(SymbolCollectorTest, MacroRefWithoutCollectingSymbol) {
@ -895,7 +895,7 @@ TEST_F(SymbolCollectorTest, MacroRefWithoutCollectingSymbol) {
CollectorOpts.RefsInHeaders = true;
CollectorOpts.CollectMacro = false;
runSymbolCollector(Header.code(), "");
EXPECT_THAT(Refs, Contains(Pair(_, HaveRanges(Header.ranges("foo")))));
EXPECT_THAT(Refs, Contains(Pair(_, haveRanges(Header.ranges("foo")))));
}
TEST_F(SymbolCollectorTest, MacrosWithRefFilter) {
@ -966,9 +966,9 @@ TEST_F(SymbolCollectorTest, SpelledReferences) {
const auto SpelledRefs = std::move(SpelledSlabBuilder).build(),
ImplicitRefs = std::move(ImplicitSlabBuilder).build();
EXPECT_THAT(SpelledRefs,
Contains(Pair(TargetID, HaveRanges(SpelledRanges))));
Contains(Pair(TargetID, haveRanges(SpelledRanges))));
EXPECT_THAT(ImplicitRefs,
Contains(Pair(TargetID, HaveRanges(ImplicitRanges))));
Contains(Pair(TargetID, haveRanges(ImplicitRanges))));
}
}
@ -987,7 +987,7 @@ TEST_F(SymbolCollectorTest, NameReferences) {
// When we find references for class Foo, we expect to see all
// constructor/destructor references.
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Foo").ID,
HaveRanges(Header.ranges()))));
haveRanges(Header.ranges()))));
}
TEST_F(SymbolCollectorTest, RefsOnMacros) {
@ -1010,7 +1010,7 @@ TEST_F(SymbolCollectorTest, RefsOnMacros) {
CollectorOpts.RefFilter = RefKind::All;
runSymbolCollector(Header.code(), "");
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Foo").ID,
HaveRanges(Header.ranges()))));
haveRanges(Header.ranges()))));
}
TEST_F(SymbolCollectorTest, HeaderAsMainFile) {
@ -1029,30 +1029,30 @@ TEST_F(SymbolCollectorTest, HeaderAsMainFile) {
runSymbolCollector("", Header.code());
EXPECT_THAT(Refs,
UnorderedElementsAre(Pair(findSymbol(Symbols, "Foo").ID,
HaveRanges(Header.ranges("Foo"))),
haveRanges(Header.ranges("Foo"))),
Pair(findSymbol(Symbols, "Func").ID,
HaveRanges(Header.ranges("Func")))));
haveRanges(Header.ranges("Func")))));
// 2. Run the .h file as main file.
TestFileName = testPath("foo.h");
runSymbolCollector("", Header.code(),
/*ExtraArgs=*/{"-xobjective-c++-header"});
EXPECT_THAT(Symbols, UnorderedElementsAre(QName("Foo"), QName("Func")));
EXPECT_THAT(Symbols, UnorderedElementsAre(qName("Foo"), qName("Func")));
EXPECT_THAT(Refs,
UnorderedElementsAre(Pair(findSymbol(Symbols, "Foo").ID,
HaveRanges(Header.ranges("Foo"))),
haveRanges(Header.ranges("Foo"))),
Pair(findSymbol(Symbols, "Func").ID,
HaveRanges(Header.ranges("Func")))));
haveRanges(Header.ranges("Func")))));
// 3. Run the .hh file as main file (without "-x c++-header").
TestFileName = testPath("foo.hh");
runSymbolCollector("", Header.code());
EXPECT_THAT(Symbols, UnorderedElementsAre(QName("Foo"), QName("Func")));
EXPECT_THAT(Symbols, UnorderedElementsAre(qName("Foo"), qName("Func")));
EXPECT_THAT(Refs,
UnorderedElementsAre(Pair(findSymbol(Symbols, "Foo").ID,
HaveRanges(Header.ranges("Foo"))),
haveRanges(Header.ranges("Foo"))),
Pair(findSymbol(Symbols, "Func").ID,
HaveRanges(Header.ranges("Func")))));
haveRanges(Header.ranges("Func")))));
}
TEST_F(SymbolCollectorTest, RefsInHeaders) {
@ -1065,9 +1065,9 @@ TEST_F(SymbolCollectorTest, RefsInHeaders) {
)");
runSymbolCollector(Header.code(), "");
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Foo").ID,
HaveRanges(Header.ranges("foo")))));
haveRanges(Header.ranges("foo")))));
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "MACRO").ID,
HaveRanges(Header.ranges("macro")))));
haveRanges(Header.ranges("macro")))));
}
TEST_F(SymbolCollectorTest, BaseOfRelations) {
@ -1176,18 +1176,18 @@ TEST_F(SymbolCollectorTest, CountReferences) {
EXPECT_THAT(
Symbols,
UnorderedElementsAreArray(
{AllOf(QName("W"), RefCount(1)), AllOf(QName("X"), RefCount(1)),
AllOf(QName("Y"), RefCount(0)), AllOf(QName("Z"), RefCount(0)),
AllOf(QName("y"), RefCount(0)), AllOf(QName("z"), RefCount(0)),
AllOf(QName("x"), RefCount(0)), AllOf(QName("w"), RefCount(0)),
AllOf(QName("w2"), RefCount(0)), AllOf(QName("V"), RefCount(1)),
AllOf(QName("v"), RefCount(0))}));
{AllOf(qName("W"), refCount(1)), AllOf(qName("X"), refCount(1)),
AllOf(qName("Y"), refCount(0)), AllOf(qName("Z"), refCount(0)),
AllOf(qName("y"), refCount(0)), AllOf(qName("z"), refCount(0)),
AllOf(qName("x"), refCount(0)), AllOf(qName("w"), refCount(0)),
AllOf(qName("w2"), refCount(0)), AllOf(qName("V"), refCount(1)),
AllOf(qName("v"), refCount(0))}));
}
TEST_F(SymbolCollectorTest, SymbolRelativeNoFallback) {
runSymbolCollector("class Foo {};", /*Main=*/"");
EXPECT_THAT(Symbols, UnorderedElementsAre(
AllOf(QName("Foo"), DeclURI(TestHeaderURI))));
AllOf(qName("Foo"), declURI(TestHeaderURI))));
}
TEST_F(SymbolCollectorTest, SymbolRelativeWithFallback) {
@ -1197,7 +1197,7 @@ TEST_F(SymbolCollectorTest, SymbolRelativeWithFallback) {
CollectorOpts.FallbackDir = testRoot();
runSymbolCollector("class Foo {};", /*Main=*/"");
EXPECT_THAT(Symbols, UnorderedElementsAre(
AllOf(QName("Foo"), DeclURI(TestHeaderURI))));
AllOf(qName("Foo"), declURI(TestHeaderURI))));
}
TEST_F(SymbolCollectorTest, UnittestURIScheme) {
@ -1206,7 +1206,7 @@ TEST_F(SymbolCollectorTest, UnittestURIScheme) {
TestFileName = testPath("x.cpp");
runSymbolCollector("class Foo {};", /*Main=*/"");
EXPECT_THAT(Symbols, UnorderedElementsAre(
AllOf(QName("Foo"), DeclURI("unittest:///x.h"))));
AllOf(qName("Foo"), declURI("unittest:///x.h"))));
}
TEST_F(SymbolCollectorTest, IncludeEnums) {
@ -1229,13 +1229,13 @@ TEST_F(SymbolCollectorTest, IncludeEnums) {
runSymbolCollector(Header, /*Main=*/"");
EXPECT_THAT(Symbols,
UnorderedElementsAre(
AllOf(QName("Red"), ForCodeCompletion(true)),
AllOf(QName("Color"), ForCodeCompletion(true)),
AllOf(QName("Green"), ForCodeCompletion(true)),
AllOf(QName("Color2"), ForCodeCompletion(true)),
AllOf(QName("Color2::Yellow"), ForCodeCompletion(false)),
AllOf(QName("ns"), ForCodeCompletion(true)),
AllOf(QName("ns::Black"), ForCodeCompletion(true))));
AllOf(qName("Red"), forCodeCompletion(true)),
AllOf(qName("Color"), forCodeCompletion(true)),
AllOf(qName("Green"), forCodeCompletion(true)),
AllOf(qName("Color2"), forCodeCompletion(true)),
AllOf(qName("Color2::Yellow"), forCodeCompletion(false)),
AllOf(qName("ns"), forCodeCompletion(true)),
AllOf(qName("ns::Black"), forCodeCompletion(true))));
}
TEST_F(SymbolCollectorTest, NamelessSymbols) {
@ -1245,8 +1245,8 @@ TEST_F(SymbolCollectorTest, NamelessSymbols) {
} Foo;
)";
runSymbolCollector(Header, /*Main=*/"");
EXPECT_THAT(Symbols, UnorderedElementsAre(QName("Foo"),
QName("(anonymous struct)::a")));
EXPECT_THAT(Symbols, UnorderedElementsAre(qName("Foo"),
qName("(anonymous struct)::a")));
}
TEST_F(SymbolCollectorTest, SymbolFormedFromRegisteredSchemeFromMacro) {
@ -1266,10 +1266,10 @@ TEST_F(SymbolCollectorTest, SymbolFormedFromRegisteredSchemeFromMacro) {
runSymbolCollector(Header.code(), /*Main=*/"");
EXPECT_THAT(Symbols,
UnorderedElementsAre(
AllOf(QName("abc_Test"), DeclRange(Header.range("expansion")),
DeclURI(TestHeaderURI)),
AllOf(QName("Test"), DeclRange(Header.range("spelling")),
DeclURI(TestHeaderURI))));
AllOf(qName("abc_Test"), declRange(Header.range("expansion")),
declURI(TestHeaderURI)),
AllOf(qName("Test"), declRange(Header.range("spelling")),
declURI(TestHeaderURI))));
}
TEST_F(SymbolCollectorTest, SymbolFormedByCLI) {
@ -1280,8 +1280,8 @@ TEST_F(SymbolCollectorTest, SymbolFormedByCLI) {
)");
runSymbolCollector(Header.code(), /*Main=*/"", /*ExtraArgs=*/{"-DNAME=name"});
EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(
QName("name"), DeclRange(Header.range("expansion")),
DeclURI(TestHeaderURI))));
qName("name"), declRange(Header.range("expansion")),
declURI(TestHeaderURI))));
}
TEST_F(SymbolCollectorTest, SymbolsInMainFile) {
@ -1303,15 +1303,15 @@ TEST_F(SymbolCollectorTest, SymbolsInMainFile) {
)";
runSymbolCollector(/*Header=*/"", Main);
EXPECT_THAT(Symbols, UnorderedElementsAre(
QName("Foo"), QName("f1"), QName("f2"), QName("ff"),
QName("foo"), QName("foo::Bar"), QName("main_f")));
qName("Foo"), qName("f1"), qName("f2"), qName("ff"),
qName("foo"), qName("foo::Bar"), qName("main_f")));
}
TEST_F(SymbolCollectorTest, Documentation) {
const std::string Header = R"(
// Doc Foo
// doc Foo
class Foo {
// Doc f
// doc f
int f();
};
)";
@ -1319,17 +1319,17 @@ TEST_F(SymbolCollectorTest, Documentation) {
runSymbolCollector(Header, /* Main */ "");
EXPECT_THAT(Symbols,
UnorderedElementsAre(
AllOf(QName("Foo"), Doc("Doc Foo"), ForCodeCompletion(true)),
AllOf(QName("Foo::f"), Doc(""), ReturnType(""),
ForCodeCompletion(false))));
AllOf(qName("Foo"), doc("doc Foo"), forCodeCompletion(true)),
AllOf(qName("Foo::f"), doc(""), returnType(""),
forCodeCompletion(false))));
CollectorOpts.StoreAllDocumentation = true;
runSymbolCollector(Header, /* Main */ "");
EXPECT_THAT(Symbols,
UnorderedElementsAre(
AllOf(QName("Foo"), Doc("Doc Foo"), ForCodeCompletion(true)),
AllOf(QName("Foo::f"), Doc("Doc f"), ReturnType(""),
ForCodeCompletion(false))));
AllOf(qName("Foo"), doc("doc Foo"), forCodeCompletion(true)),
AllOf(qName("Foo::f"), doc("doc f"), returnType(""),
forCodeCompletion(false))));
}
TEST_F(SymbolCollectorTest, ClassMembers) {
@ -1350,12 +1350,12 @@ TEST_F(SymbolCollectorTest, ClassMembers) {
EXPECT_THAT(
Symbols,
UnorderedElementsAre(
QName("Foo"),
AllOf(QName("Foo::f"), ReturnType(""), ForCodeCompletion(false)),
AllOf(QName("Foo::g"), ReturnType(""), ForCodeCompletion(false)),
AllOf(QName("Foo::sf"), ReturnType(""), ForCodeCompletion(false)),
AllOf(QName("Foo::ssf"), ReturnType(""), ForCodeCompletion(false)),
AllOf(QName("Foo::x"), ReturnType(""), ForCodeCompletion(false))));
qName("Foo"),
AllOf(qName("Foo::f"), returnType(""), forCodeCompletion(false)),
AllOf(qName("Foo::g"), returnType(""), forCodeCompletion(false)),
AllOf(qName("Foo::sf"), returnType(""), forCodeCompletion(false)),
AllOf(qName("Foo::ssf"), returnType(""), forCodeCompletion(false)),
AllOf(qName("Foo::x"), returnType(""), forCodeCompletion(false))));
}
TEST_F(SymbolCollectorTest, Scopes) {
@ -1369,8 +1369,8 @@ TEST_F(SymbolCollectorTest, Scopes) {
)";
runSymbolCollector(Header, /*Main=*/"");
EXPECT_THAT(Symbols,
UnorderedElementsAre(QName("na"), QName("na::nb"),
QName("na::Foo"), QName("na::nb::Bar")));
UnorderedElementsAre(qName("na"), qName("na::nb"),
qName("na::Foo"), qName("na::nb::Bar")));
}
TEST_F(SymbolCollectorTest, ExternC) {
@ -1381,8 +1381,8 @@ TEST_F(SymbolCollectorTest, ExternC) {
}
)";
runSymbolCollector(Header, /*Main=*/"");
EXPECT_THAT(Symbols, UnorderedElementsAre(QName("na"), QName("Foo"),
QName("na::Bar")));
EXPECT_THAT(Symbols, UnorderedElementsAre(qName("na"), qName("Foo"),
qName("na::Bar")));
}
TEST_F(SymbolCollectorTest, SkipInlineNamespace) {
@ -1401,8 +1401,8 @@ TEST_F(SymbolCollectorTest, SkipInlineNamespace) {
)";
runSymbolCollector(Header, /*Main=*/"");
EXPECT_THAT(Symbols,
UnorderedElementsAre(QName("na"), QName("na::nb"),
QName("na::Foo"), QName("na::Bar")));
UnorderedElementsAre(qName("na"), qName("na::nb"),
qName("na::Foo"), qName("na::Bar")));
}
TEST_F(SymbolCollectorTest, SymbolWithDocumentation) {
@ -1416,11 +1416,11 @@ TEST_F(SymbolCollectorTest, SymbolWithDocumentation) {
EXPECT_THAT(
Symbols,
UnorderedElementsAre(
QName("nx"), AllOf(QName("nx::ff"), Labeled("ff(int x, double y)"),
ReturnType("int"), Doc("Foo comment."))));
qName("nx"), AllOf(qName("nx::ff"), labeled("ff(int x, double y)"),
returnType("int"), doc("Foo comment."))));
}
TEST_F(SymbolCollectorTest, Snippet) {
TEST_F(SymbolCollectorTest, snippet) {
const std::string Header = R"(
namespace nx {
void f() {}
@ -1430,17 +1430,17 @@ TEST_F(SymbolCollectorTest, Snippet) {
runSymbolCollector(Header, /*Main=*/"");
EXPECT_THAT(Symbols,
UnorderedElementsAre(
QName("nx"),
AllOf(QName("nx::f"), Labeled("f()"), Snippet("f()")),
AllOf(QName("nx::ff"), Labeled("ff(int x, double y)"),
Snippet("ff(${1:int x}, ${2:double y})"))));
qName("nx"),
AllOf(qName("nx::f"), labeled("f()"), snippet("f()")),
AllOf(qName("nx::ff"), labeled("ff(int x, double y)"),
snippet("ff(${1:int x}, ${2:double y})"))));
}
TEST_F(SymbolCollectorTest, IncludeHeaderSameAsFileURI) {
CollectorOpts.CollectIncludePath = true;
runSymbolCollector("#pragma once\nclass Foo {};", /*Main=*/"");
EXPECT_THAT(Symbols, UnorderedElementsAre(
AllOf(QName("Foo"), DeclURI(TestHeaderURI))));
AllOf(qName("Foo"), declURI(TestHeaderURI))));
EXPECT_THAT(Symbols.begin()->IncludeHeaders,
UnorderedElementsAre(IncludeHeaderWithRef(TestHeaderURI, 1u)));
}
@ -1465,12 +1465,12 @@ TEST_F(SymbolCollectorTest, CanonicalSTLHeader) {
EXPECT_THAT(
Symbols,
UnorderedElementsAre(
QName("std"),
AllOf(QName("std::string"), DeclURI(TestHeaderURI),
IncludeHeader("<string>")),
qName("std"),
AllOf(qName("std::string"), declURI(TestHeaderURI),
includeHeader("<string>")),
// Parameter names are demangled.
AllOf(Labeled("move(T &&value)"), IncludeHeader("<utility>")),
AllOf(Labeled("move(I, I, O)"), IncludeHeader("<algorithm>"))));
AllOf(labeled("move(T &&value)"), includeHeader("<utility>")),
AllOf(labeled("move(I, I, O)"), includeHeader("<algorithm>"))));
}
TEST_F(SymbolCollectorTest, IWYUPragma) {
@ -1484,8 +1484,8 @@ TEST_F(SymbolCollectorTest, IWYUPragma) {
)";
runSymbolCollector(Header, /*Main=*/"");
EXPECT_THAT(Symbols, UnorderedElementsAre(
AllOf(QName("Foo"), DeclURI(TestHeaderURI),
IncludeHeader("\"the/good/header.h\""))));
AllOf(qName("Foo"), declURI(TestHeaderURI),
includeHeader("\"the/good/header.h\""))));
}
TEST_F(SymbolCollectorTest, IWYUPragmaWithDoubleQuotes) {
@ -1499,8 +1499,8 @@ TEST_F(SymbolCollectorTest, IWYUPragmaWithDoubleQuotes) {
)";
runSymbolCollector(Header, /*Main=*/"");
EXPECT_THAT(Symbols, UnorderedElementsAre(
AllOf(QName("Foo"), DeclURI(TestHeaderURI),
IncludeHeader("\"the/good/header.h\""))));
AllOf(qName("Foo"), declURI(TestHeaderURI),
includeHeader("\"the/good/header.h\""))));
}
TEST_F(SymbolCollectorTest, SkipIncFileWhenCanonicalizeHeaders) {
@ -1515,10 +1515,10 @@ TEST_F(SymbolCollectorTest, SkipIncFileWhenCanonicalizeHeaders) {
runSymbolCollector("#include \"test.inc\"\nclass Y {};", /*Main=*/"",
/*ExtraArgs=*/{"-I", testRoot()});
EXPECT_THAT(Symbols,
UnorderedElementsAre(AllOf(QName("X"), DeclURI(IncURI),
IncludeHeader("<canonical>")),
AllOf(QName("Y"), DeclURI(TestHeaderURI),
IncludeHeader("<canonical>"))));
UnorderedElementsAre(AllOf(qName("X"), declURI(IncURI),
includeHeader("<canonical>")),
AllOf(qName("Y"), declURI(TestHeaderURI),
includeHeader("<canonical>"))));
}
TEST_F(SymbolCollectorTest, MainFileIsHeaderWhenSkipIncFile) {
@ -1539,8 +1539,8 @@ TEST_F(SymbolCollectorTest, MainFileIsHeaderWhenSkipIncFile) {
#endif
)cpp",
/*ExtraArgs=*/{"-I", testRoot()});
EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(QName("X"), DeclURI(IncURI),
IncludeHeader(TestFileURI))));
EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(qName("X"), declURI(IncURI),
includeHeader(TestFileURI))));
}
TEST_F(SymbolCollectorTest, IncFileInNonHeader) {
@ -1555,8 +1555,8 @@ TEST_F(SymbolCollectorTest, IncFileInNonHeader) {
#include "test.inc"
)cpp",
/*ExtraArgs=*/{"-I", testRoot()});
EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(QName("X"), DeclURI(IncURI),
Not(IncludeHeader()))));
EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(qName("X"), declURI(IncURI),
Not(includeHeader()))));
}
// Features that depend on header-guards are fragile. Header guards are only
@ -1575,17 +1575,17 @@ TEST_F(SymbolCollectorTest, HeaderGuardDetected) {
#endif // Header guard is recognized here.
)cpp",
"");
EXPECT_THAT(Symbols, Not(Contains(QName("HEADER_GUARD_"))));
EXPECT_THAT(Symbols, Each(IncludeHeader()));
EXPECT_THAT(Symbols, Not(Contains(qName("HEADER_GUARD_"))));
EXPECT_THAT(Symbols, Each(includeHeader()));
}
TEST_F(SymbolCollectorTest, NonModularHeader) {
auto TU = TestTU::withHeaderCode("int x();");
EXPECT_THAT(TU.headerSymbols(), ElementsAre(IncludeHeader()));
EXPECT_THAT(TU.headerSymbols(), ElementsAre(includeHeader()));
// Files missing include guards aren't eligible for insertion.
TU.ImplicitHeaderGuard = false;
EXPECT_THAT(TU.headerSymbols(), ElementsAre(Not(IncludeHeader())));
EXPECT_THAT(TU.headerSymbols(), ElementsAre(Not(includeHeader())));
// We recognize some patterns of trying to prevent insertion.
TU = TestTU::withHeaderCode(R"cpp(
@ -1595,7 +1595,7 @@ TEST_F(SymbolCollectorTest, NonModularHeader) {
int x();
)cpp");
TU.ExtraArgs.push_back("-DSECRET"); // *we're* able to include it.
EXPECT_THAT(TU.headerSymbols(), ElementsAre(Not(IncludeHeader())));
EXPECT_THAT(TU.headerSymbols(), ElementsAre(Not(includeHeader())));
}
TEST_F(SymbolCollectorTest, AvoidUsingFwdDeclsAsCanonicalDecls) {
@ -1616,21 +1616,21 @@ TEST_F(SymbolCollectorTest, AvoidUsingFwdDeclsAsCanonicalDecls) {
EXPECT_THAT(
Symbols,
UnorderedElementsAre(
AllOf(QName("C"), DeclURI(TestHeaderURI),
DeclRange(Header.range("cdecl")), IncludeHeader(TestHeaderURI),
DefURI(TestHeaderURI), DefRange(Header.range("cdecl"))),
AllOf(QName("S"), DeclURI(TestHeaderURI),
DeclRange(Header.range("sdecl")), IncludeHeader(TestHeaderURI),
DefURI(TestHeaderURI), DefRange(Header.range("sdecl"))),
AllOf(QName("U"), DeclURI(TestHeaderURI),
DeclRange(Header.range("udecl")), IncludeHeader(TestHeaderURI),
DefURI(TestHeaderURI), DefRange(Header.range("udecl"))),
AllOf(QName("U::x"), DeclURI(TestHeaderURI),
DeclRange(Header.range("xdecl")), DefURI(TestHeaderURI),
DefRange(Header.range("xdecl"))),
AllOf(QName("U::y"), DeclURI(TestHeaderURI),
DeclRange(Header.range("ydecl")), DefURI(TestHeaderURI),
DefRange(Header.range("ydecl")))));
AllOf(qName("C"), declURI(TestHeaderURI),
declRange(Header.range("cdecl")), includeHeader(TestHeaderURI),
defURI(TestHeaderURI), defRange(Header.range("cdecl"))),
AllOf(qName("S"), declURI(TestHeaderURI),
declRange(Header.range("sdecl")), includeHeader(TestHeaderURI),
defURI(TestHeaderURI), defRange(Header.range("sdecl"))),
AllOf(qName("U"), declURI(TestHeaderURI),
declRange(Header.range("udecl")), includeHeader(TestHeaderURI),
defURI(TestHeaderURI), defRange(Header.range("udecl"))),
AllOf(qName("U::x"), declURI(TestHeaderURI),
declRange(Header.range("xdecl")), defURI(TestHeaderURI),
defRange(Header.range("xdecl"))),
AllOf(qName("U::y"), declURI(TestHeaderURI),
declRange(Header.range("ydecl")), defURI(TestHeaderURI),
defRange(Header.range("ydecl")))));
}
TEST_F(SymbolCollectorTest, ClassForwardDeclarationIsCanonical) {
@ -1638,8 +1638,8 @@ TEST_F(SymbolCollectorTest, ClassForwardDeclarationIsCanonical) {
runSymbolCollector(/*Header=*/"#pragma once\nclass X;",
/*Main=*/"class X {};");
EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(
QName("X"), DeclURI(TestHeaderURI),
IncludeHeader(TestHeaderURI), DefURI(TestFileURI))));
qName("X"), declURI(TestHeaderURI),
includeHeader(TestHeaderURI), defURI(TestFileURI))));
}
TEST_F(SymbolCollectorTest, UTF16Character) {
@ -1647,7 +1647,7 @@ TEST_F(SymbolCollectorTest, UTF16Character) {
Annotations Header(/*Header=*/"class [[pörk]] {};");
runSymbolCollector(Header.code(), /*Main=*/"");
EXPECT_THAT(Symbols, UnorderedElementsAre(
AllOf(QName("pörk"), DeclRange(Header.range()))));
AllOf(qName("pörk"), declRange(Header.range()))));
}
TEST_F(SymbolCollectorTest, DoNotIndexSymbolsInFriendDecl) {
@ -1668,11 +1668,11 @@ TEST_F(SymbolCollectorTest, DoNotIndexSymbolsInFriendDecl) {
EXPECT_THAT(Symbols,
UnorderedElementsAre(
QName("nx"), QName("nx::X"),
AllOf(QName("nx::Y"), DeclRange(Header.range("y"))),
AllOf(QName("nx::Z"), DeclRange(Header.range("z"))),
AllOf(QName("nx::foo"), DeclRange(Header.range("foo"))),
AllOf(QName("nx::bar"), DeclRange(Header.range("bar")))));
qName("nx"), qName("nx::X"),
AllOf(qName("nx::Y"), declRange(Header.range("y"))),
AllOf(qName("nx::Z"), declRange(Header.range("z"))),
AllOf(qName("nx::foo"), declRange(Header.range("foo"))),
AllOf(qName("nx::bar"), declRange(Header.range("bar")))));
}
TEST_F(SymbolCollectorTest, ReferencesInFriendDecl) {
@ -1688,9 +1688,9 @@ TEST_F(SymbolCollectorTest, ReferencesInFriendDecl) {
)";
CollectorOpts.CountReferences = true;
runSymbolCollector(Header, Main);
EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(QName("X"), RefCount(1)),
AllOf(QName("Y"), RefCount(1)),
AllOf(QName("C"), RefCount(0))));
EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(qName("X"), refCount(1)),
AllOf(qName("Y"), refCount(1)),
AllOf(qName("C"), refCount(0))));
}
TEST_F(SymbolCollectorTest, Origin) {
@ -1724,16 +1724,16 @@ TEST_F(SymbolCollectorTest, CollectMacros) {
EXPECT_THAT(
Symbols,
UnorderedElementsAre(
QName("p"), QName("t"),
AllOf(QName("X"), DeclURI(TestHeaderURI),
IncludeHeader(TestHeaderURI)),
AllOf(Labeled("MAC(x)"), RefCount(0),
qName("p"), qName("t"),
AllOf(qName("X"), declURI(TestHeaderURI),
includeHeader(TestHeaderURI)),
AllOf(labeled("MAC(x)"), refCount(0),
DeclRange(Header.range("mac")), VisibleOutsideFile()),
AllOf(Labeled("USED(y)"), RefCount(1),
DeclRange(Header.range("used")), VisibleOutsideFile()),
AllOf(Labeled("MAIN"), RefCount(0), DeclRange(Main.range("main")),
Not(VisibleOutsideFile()))));
declRange(Header.range("mac")), visibleOutsideFile()),
AllOf(labeled("USED(y)"), refCount(1),
declRange(Header.range("used")), visibleOutsideFile()),
AllOf(labeled("MAIN"), refCount(0), declRange(Main.range("main")),
Not(visibleOutsideFile()))));
}
TEST_F(SymbolCollectorTest, DeprecatedSymbols) {
@ -1743,11 +1743,11 @@ TEST_F(SymbolCollectorTest, DeprecatedSymbols) {
)";
runSymbolCollector(Header, /**/ "");
EXPECT_THAT(Symbols, UnorderedElementsAre(
AllOf(QName("TestClangc"), Deprecated()),
AllOf(QName("TestClangd"), Not(Deprecated()))));
AllOf(qName("TestClangc"), deprecated()),
AllOf(qName("TestClangd"), Not(deprecated()))));
}
TEST_F(SymbolCollectorTest, ImplementationDetail) {
TEST_F(SymbolCollectorTest, implementationDetail) {
const std::string Header = R"(
#define DECL_NAME(x, y) x##_##y##_Decl
#define DECL(x, y) class DECL_NAME(x, y) {};
@ -1758,8 +1758,8 @@ TEST_F(SymbolCollectorTest, ImplementationDetail) {
runSymbolCollector(Header, /**/ "");
EXPECT_THAT(Symbols,
UnorderedElementsAre(
AllOf(QName("X_Y_Decl"), ImplementationDetail()),
AllOf(QName("Public"), Not(ImplementationDetail()))));
AllOf(qName("X_Y_Decl"), implementationDetail()),
AllOf(qName("Public"), Not(implementationDetail()))));
}
TEST_F(SymbolCollectorTest, UsingDecl) {
@ -1769,7 +1769,7 @@ TEST_F(SymbolCollectorTest, UsingDecl) {
using ::foo;
})";
runSymbolCollector(Header, /**/ "");
EXPECT_THAT(Symbols, Contains(QName("std::foo")));
EXPECT_THAT(Symbols, Contains(qName("std::foo")));
}
TEST_F(SymbolCollectorTest, CBuiltins) {
@ -1778,7 +1778,7 @@ TEST_F(SymbolCollectorTest, CBuiltins) {
extern int printf(const char*, ...);
)";
runSymbolCollector(Header, /**/ "", {"-xc"});
EXPECT_THAT(Symbols, Contains(QName("printf")));
EXPECT_THAT(Symbols, Contains(qName("printf")));
}
TEST_F(SymbolCollectorTest, InvalidSourceLoc) {
@ -1786,7 +1786,7 @@ TEST_F(SymbolCollectorTest, InvalidSourceLoc) {
void operator delete(void*)
__attribute__((__externally_visible__));)";
runSymbolCollector(Header, /**/ "");
EXPECT_THAT(Symbols, Contains(QName("operator delete")));
EXPECT_THAT(Symbols, Contains(qName("operator delete")));
}
TEST_F(SymbolCollectorTest, BadUTF8) {
@ -1797,8 +1797,8 @@ TEST_F(SymbolCollectorTest, BadUTF8) {
CollectorOpts.RefFilter = RefKind::All;
CollectorOpts.RefsInHeaders = true;
runSymbolCollector(Header, "");
EXPECT_THAT(Symbols, Contains(AllOf(QName("types"), Doc("\xef\xbf\xbd "))));
EXPECT_THAT(Symbols, Contains(QName("PUNCT")));
EXPECT_THAT(Symbols, Contains(AllOf(qName("types"), doc("\xef\xbf\xbd "))));
EXPECT_THAT(Symbols, Contains(qName("PUNCT")));
// Reference is stored, although offset within line is not reliable.
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "PUNCT").ID, _)));
}
@ -1808,7 +1808,7 @@ TEST_F(SymbolCollectorTest, MacrosInHeaders) {
TestFileName = testPath("test.h");
runSymbolCollector("", "#define X");
EXPECT_THAT(Symbols,
UnorderedElementsAre(AllOf(QName("X"), ForCodeCompletion(true))));
UnorderedElementsAre(AllOf(qName("X"), forCodeCompletion(true))));
}
// Regression test for a crash-bug we used to have.
@ -1832,7 +1832,7 @@ TEST_F(SymbolCollectorTest, UndefOfModuleMacro) {
TU.build();
// We mostly care about not crashing, but verify that we didn't insert garbage
// about X too.
EXPECT_THAT(TU.headerSymbols(), Not(Contains(QName("X"))));
EXPECT_THAT(TU.headerSymbols(), Not(Contains(qName("X"))));
}
TEST_F(SymbolCollectorTest, NoCrashOnObjCMethodCStyleParam) {
@ -1846,7 +1846,7 @@ TEST_F(SymbolCollectorTest, NoCrashOnObjCMethodCStyleParam) {
TU.build();
// We mostly care about not crashing.
EXPECT_THAT(TU.headerSymbols(),
UnorderedElementsAre(QName("Foo"), QName("Foo::fun:")));
UnorderedElementsAre(qName("Foo"), qName("Foo::fun:")));
}
TEST_F(SymbolCollectorTest, Reserved) {
@ -1857,8 +1857,8 @@ TEST_F(SymbolCollectorTest, Reserved) {
CollectorOpts.CollectReserved = true;
runSymbolCollector("", Header);
EXPECT_THAT(Symbols, UnorderedElementsAre(QName("__foo"), QName("_X"),
QName("_X::secret")));
EXPECT_THAT(Symbols, UnorderedElementsAre(qName("__foo"), qName("_X"),
qName("_X::secret")));
CollectorOpts.CollectReserved = false;
runSymbolCollector("", Header); //

View File

@ -26,10 +26,10 @@ namespace {
using ::testing::UnorderedElementsAreArray;
auto CreateExpectedSymbolDetails = [](const std::string &name,
const std::string &container,
auto CreateExpectedSymbolDetails = [](const std::string &Name,
const std::string &Container,
const std::string &USR) {
return SymbolDetails{name, container, USR, SymbolID(USR)};
return SymbolDetails{Name, Container, USR, SymbolID(USR)};
};
TEST(SymbolInfoTests, All) {

View File

@ -86,8 +86,8 @@ SymbolSlab generateSymbols(std::vector<std::string> QualifiedNames) {
SymbolSlab generateNumSymbols(int Begin, int End) {
std::vector<std::string> Names;
for (int i = Begin; i <= End; i++)
Names.push_back(std::to_string(i));
for (int I = Begin; I <= End; I++)
Names.push_back(std::to_string(I));
return generateSymbols(Names);
}

View File

@ -35,22 +35,22 @@ using ::testing::Matcher;
using ::testing::UnorderedElementsAre;
// GMock helpers for matching TypeHierarchyItem.
MATCHER_P(WithName, N, "") { return arg.name == N; }
MATCHER_P(WithKind, Kind, "") { return arg.kind == Kind; }
MATCHER_P(SelectionRangeIs, R, "") { return arg.selectionRange == R; }
MATCHER_P(withName, N, "") { return arg.name == N; }
MATCHER_P(withKind, Kind, "") { return arg.kind == Kind; }
MATCHER_P(selectionRangeIs, R, "") { return arg.selectionRange == R; }
template <class... ParentMatchers>
::testing::Matcher<TypeHierarchyItem> Parents(ParentMatchers... ParentsM) {
::testing::Matcher<TypeHierarchyItem> parents(ParentMatchers... ParentsM) {
return Field(&TypeHierarchyItem::parents,
HasValue(UnorderedElementsAre(ParentsM...)));
}
template <class... ChildMatchers>
::testing::Matcher<TypeHierarchyItem> Children(ChildMatchers... ChildrenM) {
::testing::Matcher<TypeHierarchyItem> children(ChildMatchers... ChildrenM) {
return Field(&TypeHierarchyItem::children,
HasValue(UnorderedElementsAre(ChildrenM...)));
}
// Note: "not resolved" is different from "resolved but empty"!
MATCHER(ParentsNotResolved, "") { return !arg.parents; }
MATCHER(ChildrenNotResolved, "") { return !arg.children; }
MATCHER(parentsNotResolved, "") { return !arg.parents; }
MATCHER(childrenNotResolved, "") { return !arg.children; }
TEST(FindRecordTypeAt, TypeOrVariable) {
Annotations Source(R"cpp(
@ -206,7 +206,7 @@ struct Child : Parent {};
EXPECT_THAT(typeParents(Child), ElementsAre(Parent));
}
MATCHER_P(ImplicitSpecOf, ClassTemplate, "") {
MATCHER_P(implicitSpecOf, ClassTemplate, "") {
const ClassTemplateSpecializationDecl *CTS =
dyn_cast<ClassTemplateSpecializationDecl>(arg);
return CTS &&
@ -255,7 +255,7 @@ struct Child2 : Parent<int> {};
const CXXRecordDecl *Child2 =
dyn_cast<CXXRecordDecl>(&findDecl(AST, "Child2"));
EXPECT_THAT(typeParents(Child1), ElementsAre(ImplicitSpecOf(Parent)));
EXPECT_THAT(typeParents(Child1), ElementsAre(implicitSpecOf(Parent)));
EXPECT_THAT(typeParents(Child2), ElementsAre(ParentSpec));
}
@ -371,16 +371,16 @@ int main() {
EXPECT_THAT(
*Result,
AllOf(
WithName("Child"), WithKind(SymbolKind::Struct),
Parents(AllOf(WithName("Parent1"), WithKind(SymbolKind::Struct),
SelectionRangeIs(Source.range("Parent1Def")),
Parents()),
AllOf(WithName("Parent3"), WithKind(SymbolKind::Struct),
SelectionRangeIs(Source.range("Parent3Def")),
Parents(AllOf(
WithName("Parent2"), WithKind(SymbolKind::Struct),
SelectionRangeIs(Source.range("Parent2Def")),
Parents()))))));
withName("Child"), withKind(SymbolKind::Struct),
parents(AllOf(withName("Parent1"), withKind(SymbolKind::Struct),
selectionRangeIs(Source.range("Parent1Def")),
parents()),
AllOf(withName("Parent3"), withKind(SymbolKind::Struct),
selectionRangeIs(Source.range("Parent3Def")),
parents(AllOf(
withName("Parent2"), withKind(SymbolKind::Struct),
selectionRangeIs(Source.range("Parent2Def")),
parents()))))));
}
}
@ -409,13 +409,13 @@ TEST(TypeHierarchy, RecursiveHierarchyUnbounded) {
ASSERT_TRUE(bool(Result));
EXPECT_THAT(
*Result,
AllOf(WithName("S<0>"), WithKind(SymbolKind::Struct),
Parents(
AllOf(WithName("S"), WithKind(SymbolKind::Struct),
SelectionRangeIs(Source.range("SDef")),
Parents(AllOf(WithName("S"), WithKind(SymbolKind::Struct),
SelectionRangeIs(Source.range("SDef")),
Parents()))))));
AllOf(withName("S<0>"), withKind(SymbolKind::Struct),
parents(
AllOf(withName("S"), withKind(SymbolKind::Struct),
selectionRangeIs(Source.range("SDef")),
parents(AllOf(withName("S"), withKind(SymbolKind::Struct),
selectionRangeIs(Source.range("SDef")),
parents()))))));
}
TEST(TypeHierarchy, RecursiveHierarchyBounded) {
@ -443,20 +443,20 @@ TEST(TypeHierarchy, RecursiveHierarchyBounded) {
ASSERT_TRUE(bool(Result));
EXPECT_THAT(
*Result,
AllOf(WithName("S<2>"), WithKind(SymbolKind::Struct),
Parents(AllOf(
WithName("S<1>"), WithKind(SymbolKind::Struct),
SelectionRangeIs(Source.range("SDef")),
Parents(AllOf(WithName("S<0>"), WithKind(SymbolKind::Struct),
Parents()))))));
AllOf(withName("S<2>"), withKind(SymbolKind::Struct),
parents(AllOf(
withName("S<1>"), withKind(SymbolKind::Struct),
selectionRangeIs(Source.range("SDef")),
parents(AllOf(withName("S<0>"), withKind(SymbolKind::Struct),
parents()))))));
Result = getTypeHierarchy(AST, Source.point("SRefDependent"), 0,
TypeHierarchyDirection::Parents);
ASSERT_TRUE(bool(Result));
EXPECT_THAT(
*Result,
AllOf(WithName("S"), WithKind(SymbolKind::Struct),
Parents(AllOf(WithName("S"), WithKind(SymbolKind::Struct),
SelectionRangeIs(Source.range("SDef")), Parents()))));
AllOf(withName("S"), withKind(SymbolKind::Struct),
parents(AllOf(withName("S"), withKind(SymbolKind::Struct),
selectionRangeIs(Source.range("SDef")), parents()))));
}
TEST(TypeHierarchy, DeriveFromImplicitSpec) {
@ -480,11 +480,11 @@ TEST(TypeHierarchy, DeriveFromImplicitSpec) {
testPath(TU.Filename));
ASSERT_TRUE(bool(Result));
EXPECT_THAT(*Result,
AllOf(WithName("Parent"), WithKind(SymbolKind::Struct),
Children(AllOf(WithName("Child1"),
WithKind(SymbolKind::Struct), Children()),
AllOf(WithName("Child2"),
WithKind(SymbolKind::Struct), Children()))));
AllOf(withName("Parent"), withKind(SymbolKind::Struct),
children(AllOf(withName("Child1"),
withKind(SymbolKind::Struct), children()),
AllOf(withName("Child2"),
withKind(SymbolKind::Struct), children()))));
}
TEST(TypeHierarchy, DeriveFromPartialSpec) {
@ -505,8 +505,8 @@ TEST(TypeHierarchy, DeriveFromPartialSpec) {
AST, Source.points()[0], 2, TypeHierarchyDirection::Children, Index.get(),
testPath(TU.Filename));
ASSERT_TRUE(bool(Result));
EXPECT_THAT(*Result, AllOf(WithName("Parent"), WithKind(SymbolKind::Struct),
Children()));
EXPECT_THAT(*Result, AllOf(withName("Parent"), withKind(SymbolKind::Struct),
children()));
}
TEST(TypeHierarchy, DeriveFromTemplate) {
@ -532,9 +532,9 @@ TEST(TypeHierarchy, DeriveFromTemplate) {
testPath(TU.Filename));
ASSERT_TRUE(bool(Result));
EXPECT_THAT(*Result,
AllOf(WithName("Parent"), WithKind(SymbolKind::Struct),
Children(AllOf(WithName("Child"),
WithKind(SymbolKind::Struct), Children()))));
AllOf(withName("Parent"), withKind(SymbolKind::Struct),
children(AllOf(withName("Child"),
withKind(SymbolKind::Struct), children()))));
}
TEST(TypeHierarchy, Preamble) {
@ -558,10 +558,10 @@ struct [[Parent]] {
ASSERT_TRUE(Result);
EXPECT_THAT(
*Result,
AllOf(WithName("Child"),
Parents(AllOf(WithName("Parent"),
SelectionRangeIs(HeaderInPreambleAnnotations.range()),
Parents()))));
AllOf(withName("Child"),
parents(AllOf(withName("Parent"),
selectionRangeIs(HeaderInPreambleAnnotations.range()),
parents()))));
}
SymbolID findSymbolIDByName(SymbolIndex *Index, llvm::StringRef Name,
@ -734,22 +734,22 @@ struct Child2b : Child1 {};
ASSERT_TRUE(bool(Result));
EXPECT_THAT(
*Result,
AllOf(WithName("Parent"), WithKind(SymbolKind::Struct),
ParentsNotResolved(),
Children(AllOf(WithName("Child1"), WithKind(SymbolKind::Struct),
ParentsNotResolved(), ChildrenNotResolved()))));
AllOf(withName("Parent"), withKind(SymbolKind::Struct),
parentsNotResolved(),
children(AllOf(withName("Child1"), withKind(SymbolKind::Struct),
parentsNotResolved(), childrenNotResolved()))));
resolveTypeHierarchy((*Result->children)[0], /*ResolveLevels=*/1,
TypeHierarchyDirection::Children, Index.get());
EXPECT_THAT(
(*Result->children)[0],
AllOf(WithName("Child1"), WithKind(SymbolKind::Struct),
ParentsNotResolved(),
Children(AllOf(WithName("Child2a"), WithKind(SymbolKind::Struct),
ParentsNotResolved(), ChildrenNotResolved()),
AllOf(WithName("Child2b"), WithKind(SymbolKind::Struct),
ParentsNotResolved(), ChildrenNotResolved()))));
AllOf(withName("Child1"), withKind(SymbolKind::Struct),
parentsNotResolved(),
children(AllOf(withName("Child2a"), withKind(SymbolKind::Struct),
parentsNotResolved(), childrenNotResolved()),
AllOf(withName("Child2b"), withKind(SymbolKind::Struct),
parentsNotResolved(), childrenNotResolved()))));
}
} // namespace

View File

@ -23,9 +23,9 @@ namespace {
using ::testing::AllOf;
MATCHER_P(Scheme, S, "") { return arg.scheme() == S; }
MATCHER_P(Authority, A, "") { return arg.authority() == A; }
MATCHER_P(Body, B, "") { return arg.body() == B; }
MATCHER_P(scheme, S, "") { return arg.scheme() == S; }
MATCHER_P(authority, A, "") { return arg.authority() == A; }
MATCHER_P(body, B, "") { return arg.body() == B; }
std::string createOrDie(llvm::StringRef AbsolutePath,
llvm::StringRef Scheme = "file") {
@ -43,10 +43,10 @@ URI parseOrDie(llvm::StringRef Uri) {
}
TEST(PercentEncodingTest, Encode) {
EXPECT_EQ(URI("x", /*Authority=*/"", "a/b/c").toString(), "x:a/b/c");
EXPECT_EQ(URI("x", /*Authority=*/"", "a!b;c~").toString(), "x:a%21b%3Bc~");
EXPECT_EQ(URI("x", /*Authority=*/"", "a123b").toString(), "x:a123b");
EXPECT_EQ(URI("x", /*Authority=*/"", "a:b;c").toString(), "x:a:b%3Bc");
EXPECT_EQ(URI("x", /*authority=*/"", "a/b/c").toString(), "x:a/b/c");
EXPECT_EQ(URI("x", /*authority=*/"", "a!b;c~").toString(), "x:a%21b%3Bc~");
EXPECT_EQ(URI("x", /*authority=*/"", "a123b").toString(), "x:a123b");
EXPECT_EQ(URI("x", /*authority=*/"", "a:b;c").toString(), "x:a:b%3Bc");
}
TEST(PercentEncodingTest, Decode) {
@ -94,32 +94,32 @@ TEST(URITest, FailedCreate) {
TEST(URITest, Parse) {
EXPECT_THAT(parseOrDie("file://auth/x/y/z"),
AllOf(Scheme("file"), Authority("auth"), Body("/x/y/z")));
AllOf(scheme("file"), authority("auth"), body("/x/y/z")));
EXPECT_THAT(parseOrDie("file://au%3dth/%28x%29/y/%5c%20z"),
AllOf(Scheme("file"), Authority("au=th"), Body("/(x)/y/\\ z")));
AllOf(scheme("file"), authority("au=th"), body("/(x)/y/\\ z")));
EXPECT_THAT(parseOrDie("file:///%28x%29/y/%5c%20z"),
AllOf(Scheme("file"), Authority(""), Body("/(x)/y/\\ z")));
AllOf(scheme("file"), authority(""), body("/(x)/y/\\ z")));
EXPECT_THAT(parseOrDie("file:///x/y/z"),
AllOf(Scheme("file"), Authority(""), Body("/x/y/z")));
AllOf(scheme("file"), authority(""), body("/x/y/z")));
EXPECT_THAT(parseOrDie("file:"),
AllOf(Scheme("file"), Authority(""), Body("")));
AllOf(scheme("file"), authority(""), body("")));
EXPECT_THAT(parseOrDie("file:///x/y/z%2"),
AllOf(Scheme("file"), Authority(""), Body("/x/y/z%2")));
AllOf(scheme("file"), authority(""), body("/x/y/z%2")));
EXPECT_THAT(parseOrDie("http://llvm.org"),
AllOf(Scheme("http"), Authority("llvm.org"), Body("")));
AllOf(scheme("http"), authority("llvm.org"), body("")));
EXPECT_THAT(parseOrDie("http://llvm.org/"),
AllOf(Scheme("http"), Authority("llvm.org"), Body("/")));
AllOf(scheme("http"), authority("llvm.org"), body("/")));
EXPECT_THAT(parseOrDie("http://llvm.org/D"),
AllOf(Scheme("http"), Authority("llvm.org"), Body("/D")));
AllOf(scheme("http"), authority("llvm.org"), body("/D")));
EXPECT_THAT(parseOrDie("http:/"),
AllOf(Scheme("http"), Authority(""), Body("/")));
AllOf(scheme("http"), authority(""), body("/")));
EXPECT_THAT(parseOrDie("urn:isbn:0451450523"),
AllOf(Scheme("urn"), Authority(""), Body("isbn:0451450523")));
AllOf(scheme("urn"), authority(""), body("isbn:0451450523")));
EXPECT_THAT(
parseOrDie("file:///c:/windows/system32/"),
AllOf(Scheme("file"), Authority(""), Body("/c:/windows/system32/")));
AllOf(scheme("file"), authority(""), body("/c:/windows/system32/")));
}
TEST(URITest, ParseFailed) {

View File

@ -51,7 +51,7 @@ using ::testing::UnorderedPointwise;
MATCHER_P2(FileRange, File, Range, "") {
return Location{URIForFile::canonicalize(File, testRoot()), Range} == arg;
}
MATCHER(DeclRange, "") {
MATCHER(declRange, "") {
const LocatedSymbol &Sym = ::testing::get<0>(arg);
const Range &Range = ::testing::get<1>(arg);
return Sym.PreferredDeclaration.range == Range;
@ -60,7 +60,7 @@ MATCHER(DeclRange, "") {
// Extracts ranges from an annotated example, and constructs a matcher for a
// highlight set. Ranges should be named $read/$write as appropriate.
Matcher<const std::vector<DocumentHighlight> &>
HighlightsFrom(const Annotations &Test) {
highlightsFrom(const Annotations &Test) {
std::vector<DocumentHighlight> Expected;
auto Add = [&](const Range &R, DocumentHighlightKind K) {
Expected.emplace_back();
@ -134,7 +134,7 @@ TEST(HighlightsTest, All) {
auto TU = TestTU::withCode(T.code());
TU.ExtraArgs.push_back("-xobjective-c++");
auto AST = TU.build();
EXPECT_THAT(findDocumentHighlights(AST, T.point()), HighlightsFrom(T))
EXPECT_THAT(findDocumentHighlights(AST, T.point()), highlightsFrom(T))
<< Test;
}
}
@ -271,12 +271,12 @@ TEST(HighlightsTest, ControlFlow) {
auto TU = TestTU::withCode(T.code());
TU.ExtraArgs.push_back("-fexceptions"); // FIXME: stop testing on PS4.
auto AST = TU.build();
EXPECT_THAT(findDocumentHighlights(AST, T.point()), HighlightsFrom(T))
EXPECT_THAT(findDocumentHighlights(AST, T.point()), highlightsFrom(T))
<< Test;
}
}
MATCHER_P3(Sym, Name, Decl, DefOrNone, "") {
MATCHER_P3(sym, Name, Decl, DefOrNone, "") {
llvm::Optional<Range> Def = DefOrNone;
if (Name != arg.Name) {
*result_listener << "Name is " << arg.Name;
@ -304,11 +304,11 @@ MATCHER_P3(Sym, Name, Decl, DefOrNone, "") {
return true;
}
MATCHER_P(Sym, Name, "") { return arg.Name == Name; }
MATCHER_P(sym, Name, "") { return arg.Name == Name; }
MATCHER_P(RangeIs, R, "") { return arg.Loc.range == R; }
MATCHER_P(AttrsAre, A, "") { return arg.Attributes == A; }
MATCHER_P(HasID, ID, "") { return arg.ID == ID; }
MATCHER_P(rangeIs, R, "") { return arg.Loc.range == R; }
MATCHER_P(attrsAre, A, "") { return arg.Attributes == A; }
MATCHER_P(hasID, ID, "") { return arg.ID == ID; }
TEST(LocateSymbol, WithIndex) {
Annotations SymbolHeader(R"cpp(
@ -340,7 +340,7 @@ TEST(LocateSymbol, WithIndex) {
}
)cpp");
EXPECT_THAT(LocateWithIndex(Test),
ElementsAre(Sym("f1", Test.range(), SymbolCpp.range("f1"))));
ElementsAre(sym("f1", Test.range(), SymbolCpp.range("f1"))));
Test = Annotations(R"cpp(// definition in AST.
void [[f1]]() {}
@ -349,14 +349,14 @@ TEST(LocateSymbol, WithIndex) {
}
)cpp");
EXPECT_THAT(LocateWithIndex(Test),
ElementsAre(Sym("f1", SymbolHeader.range("f1"), Test.range())));
ElementsAre(sym("f1", SymbolHeader.range("f1"), Test.range())));
Test = Annotations(R"cpp(// forward declaration in AST.
class [[Foo]];
F^oo* create();
)cpp");
EXPECT_THAT(LocateWithIndex(Test),
ElementsAre(Sym("Foo", Test.range(), SymbolHeader.range("foo"))));
ElementsAre(sym("Foo", Test.range(), SymbolHeader.range("foo"))));
Test = Annotations(R"cpp(// definition in AST.
class [[Forward]] {};
@ -364,7 +364,7 @@ TEST(LocateSymbol, WithIndex) {
)cpp");
EXPECT_THAT(
LocateWithIndex(Test),
ElementsAre(Sym("Forward", SymbolHeader.range("forward"), Test.range())));
ElementsAre(sym("Forward", SymbolHeader.range("forward"), Test.range())));
}
TEST(LocateSymbol, AnonymousStructFields) {
@ -382,10 +382,10 @@ TEST(LocateSymbol, AnonymousStructFields) {
TestTU TU = TestTU::withCode(Code.code());
auto AST = TU.build();
EXPECT_THAT(locateSymbolAt(AST, Code.point("1"), TU.index().get()),
UnorderedElementsAre(Sym("x", Code.range("1"), Code.range("1"))));
UnorderedElementsAre(sym("x", Code.range("1"), Code.range("1"))));
EXPECT_THAT(
locateSymbolAt(AST, Code.point("2"), TU.index().get()),
UnorderedElementsAre(Sym("Foo", Code.range("2"), Code.range("2"))));
UnorderedElementsAre(sym("Foo", Code.range("2"), Code.range("2"))));
}
TEST(LocateSymbol, FindOverrides) {
@ -400,8 +400,8 @@ TEST(LocateSymbol, FindOverrides) {
TestTU TU = TestTU::withCode(Code.code());
auto AST = TU.build();
EXPECT_THAT(locateSymbolAt(AST, Code.point(), TU.index().get()),
UnorderedElementsAre(Sym("foo", Code.range("1"), llvm::None),
Sym("foo", Code.range("2"), llvm::None)));
UnorderedElementsAre(sym("foo", Code.range("1"), llvm::None),
sym("foo", Code.range("2"), llvm::None)));
}
TEST(LocateSymbol, WithIndexPreferredLocation) {
@ -428,12 +428,12 @@ TEST(LocateSymbol, WithIndexPreferredLocation) {
{
auto Locs = clangd::locateSymbolAt(AST, Test.point("p"), Index.get());
auto CodeGenLoc = SymbolHeader.range("p");
EXPECT_THAT(Locs, ElementsAre(Sym("Proto", CodeGenLoc, CodeGenLoc)));
EXPECT_THAT(Locs, ElementsAre(sym("Proto", CodeGenLoc, CodeGenLoc)));
}
{
auto Locs = clangd::locateSymbolAt(AST, Test.point("f"), Index.get());
auto CodeGenLoc = SymbolHeader.range("f");
EXPECT_THAT(Locs, ElementsAre(Sym("func", CodeGenLoc, CodeGenLoc)));
EXPECT_THAT(Locs, ElementsAre(sym("func", CodeGenLoc, CodeGenLoc)));
}
}
@ -1000,12 +1000,12 @@ TEST(LocateSymbol, ValidSymbolID) {
auto AST = TU.build();
auto Index = TU.index();
EXPECT_THAT(locateSymbolAt(AST, T.point("add"), Index.get()),
ElementsAre(AllOf(Sym("add"),
HasID(getSymbolID(&findDecl(AST, "add"))))));
ElementsAre(AllOf(sym("add"),
hasID(getSymbolID(&findDecl(AST, "add"))))));
EXPECT_THAT(
locateSymbolAt(AST, T.point("MACRO"), Index.get()),
ElementsAre(AllOf(Sym("MACRO"),
HasID(findSymbol(TU.headerSymbols(), "MACRO").ID))));
ElementsAre(AllOf(sym("MACRO"),
hasID(findSymbol(TU.headerSymbols(), "MACRO").ID))));
}
TEST(LocateSymbol, AllMulti) {
@ -1155,8 +1155,8 @@ TEST(LocateSymbol, TextualSmoke) {
auto Index = TU.index();
EXPECT_THAT(
locateSymbolAt(AST, T.point(), Index.get()),
ElementsAre(AllOf(Sym("MyClass", T.range(), T.range()),
HasID(getSymbolID(&findDecl(AST, "MyClass"))))));
ElementsAre(AllOf(sym("MyClass", T.range(), T.range()),
hasID(getSymbolID(&findDecl(AST, "MyClass"))))));
}
TEST(LocateSymbol, Textual) {
@ -1263,33 +1263,33 @@ TEST(LocateSymbol, Ambiguous) {
TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
auto AST = TU.build();
// Ordered assertions are deliberate: we expect a predictable order.
EXPECT_THAT(locateSymbolAt(AST, T.point("1")), ElementsAre(Sym("str")));
EXPECT_THAT(locateSymbolAt(AST, T.point("2")), ElementsAre(Sym("str")));
EXPECT_THAT(locateSymbolAt(AST, T.point("3")), ElementsAre(Sym("f")));
EXPECT_THAT(locateSymbolAt(AST, T.point("4")), ElementsAre(Sym("g")));
EXPECT_THAT(locateSymbolAt(AST, T.point("5")), ElementsAre(Sym("f")));
EXPECT_THAT(locateSymbolAt(AST, T.point("6")), ElementsAre(Sym("str")));
EXPECT_THAT(locateSymbolAt(AST, T.point("1")), ElementsAre(sym("str")));
EXPECT_THAT(locateSymbolAt(AST, T.point("2")), ElementsAre(sym("str")));
EXPECT_THAT(locateSymbolAt(AST, T.point("3")), ElementsAre(sym("f")));
EXPECT_THAT(locateSymbolAt(AST, T.point("4")), ElementsAre(sym("g")));
EXPECT_THAT(locateSymbolAt(AST, T.point("5")), ElementsAre(sym("f")));
EXPECT_THAT(locateSymbolAt(AST, T.point("6")), ElementsAre(sym("str")));
// FIXME: Target the constructor as well.
EXPECT_THAT(locateSymbolAt(AST, T.point("7")), ElementsAre(Sym("abc")));
EXPECT_THAT(locateSymbolAt(AST, T.point("7")), ElementsAre(sym("abc")));
// FIXME: Target the constructor as well.
EXPECT_THAT(locateSymbolAt(AST, T.point("8")), ElementsAre(Sym("abcd")));
EXPECT_THAT(locateSymbolAt(AST, T.point("8")), ElementsAre(sym("abcd")));
// FIXME: Target the constructor as well.
EXPECT_THAT(locateSymbolAt(AST, T.point("9")), ElementsAre(Sym("Foo")));
EXPECT_THAT(locateSymbolAt(AST, T.point("9")), ElementsAre(sym("Foo")));
EXPECT_THAT(locateSymbolAt(AST, T.point("10")),
ElementsAre(Sym("Foo", T.range("ConstructorLoc"), llvm::None)));
ElementsAre(sym("Foo", T.range("ConstructorLoc"), llvm::None)));
EXPECT_THAT(locateSymbolAt(AST, T.point("11")),
ElementsAre(Sym("Foo", T.range("ConstructorLoc"), llvm::None)));
ElementsAre(sym("Foo", T.range("ConstructorLoc"), llvm::None)));
// These assertions are unordered because the order comes from
// CXXRecordDecl::lookupDependentName() which doesn't appear to provide
// an order guarantee.
EXPECT_THAT(locateSymbolAt(AST, T.point("12")),
UnorderedElementsAre(
Sym("bar", T.range("NonstaticOverload1"), llvm::None),
Sym("bar", T.range("NonstaticOverload2"), llvm::None)));
sym("bar", T.range("NonstaticOverload1"), llvm::None),
sym("bar", T.range("NonstaticOverload2"), llvm::None)));
EXPECT_THAT(
locateSymbolAt(AST, T.point("13")),
UnorderedElementsAre(Sym("baz", T.range("StaticOverload1"), llvm::None),
Sym("baz", T.range("StaticOverload2"), llvm::None)));
UnorderedElementsAre(sym("baz", T.range("StaticOverload1"), llvm::None),
sym("baz", T.range("StaticOverload2"), llvm::None)));
}
TEST(LocateSymbol, TextualDependent) {
@ -1321,8 +1321,8 @@ TEST(LocateSymbol, TextualDependent) {
auto Results = locateSymbolAt(AST, Source.point(), Index.get());
EXPECT_THAT(Results,
UnorderedElementsAre(
Sym("uniqueMethodName", Header.range("FooLoc"), llvm::None),
Sym("uniqueMethodName", Header.range("BarLoc"), llvm::None)));
sym("uniqueMethodName", Header.range("FooLoc"), llvm::None),
sym("uniqueMethodName", Header.range("BarLoc"), llvm::None)));
}
TEST(LocateSymbol, Alias) {
@ -1406,7 +1406,7 @@ TEST(LocateSymbol, Alias) {
auto T = Annotations(Case);
auto AST = TestTU::withCode(T.code()).build();
EXPECT_THAT(locateSymbolAt(AST, T.point()),
UnorderedPointwise(DeclRange(), T.ranges()));
UnorderedPointwise(declRange(), T.ranges()));
}
}
@ -1454,7 +1454,7 @@ int [[bar_not_preamble]];
auto Locations =
runLocateSymbolAt(Server, FooCpp, SourceAnnotations.point("p1"));
EXPECT_TRUE(bool(Locations)) << "findDefinitions returned an error";
EXPECT_THAT(*Locations, ElementsAre(Sym("foo", SourceAnnotations.range(),
EXPECT_THAT(*Locations, ElementsAre(sym("foo", SourceAnnotations.range(),
SourceAnnotations.range())));
// Go to a definition in header_in_preamble.h.
@ -1462,14 +1462,14 @@ int [[bar_not_preamble]];
EXPECT_TRUE(bool(Locations)) << "findDefinitions returned an error";
EXPECT_THAT(
*Locations,
ElementsAre(Sym("bar_preamble", HeaderInPreambleAnnotations.range(),
ElementsAre(sym("bar_preamble", HeaderInPreambleAnnotations.range(),
HeaderInPreambleAnnotations.range())));
// Go to a definition in header_not_in_preamble.h.
Locations = runLocateSymbolAt(Server, FooCpp, SourceAnnotations.point("p3"));
EXPECT_TRUE(bool(Locations)) << "findDefinitions returned an error";
EXPECT_THAT(*Locations,
ElementsAre(Sym("bar_not_preamble",
ElementsAre(sym("bar_not_preamble",
HeaderNotInPreambleAnnotations.range(),
HeaderNotInPreambleAnnotations.range())));
}
@ -1504,24 +1504,24 @@ TEST(GoToInclude, All) {
// Test include in preamble.
auto Locations = runLocateSymbolAt(Server, FooCpp, SourceAnnotations.point());
ASSERT_TRUE(bool(Locations)) << "locateSymbolAt returned an error";
EXPECT_THAT(*Locations, ElementsAre(Sym("foo.h", HeaderAnnotations.range(),
EXPECT_THAT(*Locations, ElementsAre(sym("foo.h", HeaderAnnotations.range(),
HeaderAnnotations.range())));
// Test include in preamble, last char.
Locations = runLocateSymbolAt(Server, FooCpp, SourceAnnotations.point("2"));
ASSERT_TRUE(bool(Locations)) << "locateSymbolAt returned an error";
EXPECT_THAT(*Locations, ElementsAre(Sym("foo.h", HeaderAnnotations.range(),
EXPECT_THAT(*Locations, ElementsAre(sym("foo.h", HeaderAnnotations.range(),
HeaderAnnotations.range())));
Locations = runLocateSymbolAt(Server, FooCpp, SourceAnnotations.point("3"));
ASSERT_TRUE(bool(Locations)) << "locateSymbolAt returned an error";
EXPECT_THAT(*Locations, ElementsAre(Sym("foo.h", HeaderAnnotations.range(),
EXPECT_THAT(*Locations, ElementsAre(sym("foo.h", HeaderAnnotations.range(),
HeaderAnnotations.range())));
// Test include outside of preamble.
Locations = runLocateSymbolAt(Server, FooCpp, SourceAnnotations.point("6"));
ASSERT_TRUE(bool(Locations)) << "locateSymbolAt returned an error";
EXPECT_THAT(*Locations, ElementsAre(Sym("foo.h", HeaderAnnotations.range(),
EXPECT_THAT(*Locations, ElementsAre(sym("foo.h", HeaderAnnotations.range(),
HeaderAnnotations.range())));
// Test a few positions that do not result in Locations.
@ -1531,12 +1531,12 @@ TEST(GoToInclude, All) {
Locations = runLocateSymbolAt(Server, FooCpp, SourceAnnotations.point("5"));
ASSERT_TRUE(bool(Locations)) << "locateSymbolAt returned an error";
EXPECT_THAT(*Locations, ElementsAre(Sym("foo.h", HeaderAnnotations.range(),
EXPECT_THAT(*Locations, ElementsAre(sym("foo.h", HeaderAnnotations.range(),
HeaderAnnotations.range())));
Locations = runLocateSymbolAt(Server, FooCpp, SourceAnnotations.point("7"));
ASSERT_TRUE(bool(Locations)) << "locateSymbolAt returned an error";
EXPECT_THAT(*Locations, ElementsAre(Sym("foo.h", HeaderAnnotations.range(),
EXPECT_THAT(*Locations, ElementsAre(sym("foo.h", HeaderAnnotations.range(),
HeaderAnnotations.range())));
// Objective C #import directive.
@ -1549,7 +1549,7 @@ TEST(GoToInclude, All) {
runAddDocument(Server, FooM, ObjC.code());
Locations = runLocateSymbolAt(Server, FooM, ObjC.point());
ASSERT_TRUE(bool(Locations)) << "locateSymbolAt returned an error";
EXPECT_THAT(*Locations, ElementsAre(Sym("foo.h", HeaderAnnotations.range(),
EXPECT_THAT(*Locations, ElementsAre(sym("foo.h", HeaderAnnotations.range(),
HeaderAnnotations.range())));
}
@ -1575,7 +1575,7 @@ TEST(LocateSymbol, WithPreamble) {
// LocateSymbol goes to a #include file: the result comes from the preamble.
EXPECT_THAT(
cantFail(runLocateSymbolAt(Server, FooCpp, FooWithHeader.point())),
ElementsAre(Sym("foo.h", FooHeader.range(), FooHeader.range())));
ElementsAre(sym("foo.h", FooHeader.range(), FooHeader.range())));
// Only preamble is built, and no AST is built in this request.
Server.addDocument(FooCpp, FooWithoutHeader.code(), "null",
@ -1584,7 +1584,7 @@ TEST(LocateSymbol, WithPreamble) {
// stale one.
EXPECT_THAT(
cantFail(runLocateSymbolAt(Server, FooCpp, FooWithoutHeader.point())),
ElementsAre(Sym("foo", FooWithoutHeader.range(), llvm::None)));
ElementsAre(sym("foo", FooWithoutHeader.range(), llvm::None)));
// Reset test environment.
runAddDocument(Server, FooCpp, FooWithHeader.code());
@ -1594,7 +1594,7 @@ TEST(LocateSymbol, WithPreamble) {
// Use the AST being built in above request.
EXPECT_THAT(
cantFail(runLocateSymbolAt(Server, FooCpp, FooWithoutHeader.point())),
ElementsAre(Sym("foo", FooWithoutHeader.range(), llvm::None)));
ElementsAre(sym("foo", FooWithoutHeader.range(), llvm::None)));
}
TEST(LocateSymbol, NearbyTokenSmoke) {
@ -1605,7 +1605,7 @@ TEST(LocateSymbol, NearbyTokenSmoke) {
auto AST = TestTU::withCode(T.code()).build();
// We don't pass an index, so can't hit index-based fallback.
EXPECT_THAT(locateSymbolAt(AST, T.point()),
ElementsAre(Sym("err", T.range(), T.range())));
ElementsAre(sym("err", T.range(), T.range())));
}
TEST(LocateSymbol, NearbyIdentifier) {
@ -1754,7 +1754,7 @@ TEST(FindImplementations, Inheritance) {
for (StringRef Label : {"0", "1", "2", "3", "4", "5", "6", "7"}) {
for (const auto &Point : Code.points(Label)) {
EXPECT_THAT(findImplementations(AST, Point, Index.get()),
UnorderedPointwise(DeclRange(), Code.ranges(Label)))
UnorderedPointwise(declRange(), Code.ranges(Label)))
<< Code.code() << " at " << Point << " for Label " << Label;
}
}
@ -1778,8 +1778,8 @@ TEST(FindImplementations, CaptureDefintion) {
auto AST = TU.build();
EXPECT_THAT(
findImplementations(AST, Code.point(), TU.index().get()),
UnorderedElementsAre(Sym("Foo", Code.range("Decl"), Code.range("Def")),
Sym("Foo", Code.range("Child2"), llvm::None)))
UnorderedElementsAre(sym("Foo", Code.range("Decl"), Code.range("Def")),
sym("Foo", Code.range("Child2"), llvm::None)))
<< Test;
}
@ -1828,7 +1828,7 @@ TEST(FindType, All) {
ASSERT_GT(A.points().size(), 0u) << Case;
for (auto Pos : A.points())
EXPECT_THAT(findType(AST, Pos),
ElementsAre(Sym("Target", HeaderA.range(), HeaderA.range())))
ElementsAre(sym("Target", HeaderA.range(), HeaderA.range())))
<< Case;
}
@ -1841,7 +1841,7 @@ TEST(FindType, All) {
ParsedAST AST = TU.build();
EXPECT_THAT(findType(AST, A.point()),
Not(Contains(Sym("Target", HeaderA.range(), HeaderA.range()))))
Not(Contains(sym("Target", HeaderA.range(), HeaderA.range()))))
<< Case;
}
}
@ -1852,23 +1852,23 @@ void checkFindRefs(llvm::StringRef Test, bool UseIndex = false) {
auto AST = TU.build();
std::vector<Matcher<ReferencesResult::Reference>> ExpectedLocations;
for (const auto &R : T.ranges())
ExpectedLocations.push_back(AllOf(RangeIs(R), AttrsAre(0u)));
ExpectedLocations.push_back(AllOf(rangeIs(R), attrsAre(0u)));
// $def is actually shorthand for both definition and declaration.
// If we have cases that are definition-only, we should change this.
for (const auto &R : T.ranges("def"))
ExpectedLocations.push_back(
AllOf(RangeIs(R), AttrsAre(ReferencesResult::Definition |
AllOf(rangeIs(R), attrsAre(ReferencesResult::Definition |
ReferencesResult::Declaration)));
for (const auto &R : T.ranges("decl"))
ExpectedLocations.push_back(
AllOf(RangeIs(R), AttrsAre(ReferencesResult::Declaration)));
AllOf(rangeIs(R), attrsAre(ReferencesResult::Declaration)));
for (const auto &R : T.ranges("overridedecl"))
ExpectedLocations.push_back(AllOf(
RangeIs(R),
AttrsAre(ReferencesResult::Declaration | ReferencesResult::Override)));
rangeIs(R),
attrsAre(ReferencesResult::Declaration | ReferencesResult::Override)));
for (const auto &R : T.ranges("overridedef"))
ExpectedLocations.push_back(
AllOf(RangeIs(R), AttrsAre(ReferencesResult::Declaration |
AllOf(rangeIs(R), attrsAre(ReferencesResult::Declaration |
ReferencesResult::Definition |
ReferencesResult::Override)));
for (const auto &P : T.points()) {
@ -2126,7 +2126,7 @@ TEST(FindReferences, MainFileReferencesOnly) {
std::vector<Matcher<ReferencesResult::Reference>> ExpectedLocations;
for (const auto &R : Code.ranges())
ExpectedLocations.push_back(RangeIs(R));
ExpectedLocations.push_back(rangeIs(R));
EXPECT_THAT(findReferences(AST, Code.point(), 0).References,
ElementsAreArray(ExpectedLocations))
<< Test;
@ -2195,7 +2195,7 @@ TEST(FindReferences, NeedsIndexForSymbols) {
// References in main file are returned without index.
EXPECT_THAT(
findReferences(AST, Main.point(), 0, /*Index=*/nullptr).References,
ElementsAre(RangeIs(Main.range())));
ElementsAre(rangeIs(Main.range())));
Annotations IndexedMain(R"cpp(
int [[foo]]() { return 42; }
)cpp");
@ -2207,9 +2207,9 @@ TEST(FindReferences, NeedsIndexForSymbols) {
IndexedTU.HeaderCode = Header;
EXPECT_THAT(
findReferences(AST, Main.point(), 0, IndexedTU.index().get()).References,
ElementsAre(RangeIs(Main.range()),
AllOf(RangeIs(IndexedMain.range()),
AttrsAre(ReferencesResult::Declaration |
ElementsAre(rangeIs(Main.range()),
AllOf(rangeIs(IndexedMain.range()),
attrsAre(ReferencesResult::Declaration |
ReferencesResult::Definition))));
auto LimitRefs =
findReferences(AST, Main.point(), /*Limit*/ 1, IndexedTU.index().get());
@ -2219,7 +2219,7 @@ TEST(FindReferences, NeedsIndexForSymbols) {
// Avoid indexed results for the main file. Use AST for the mainfile.
TU.Code = ("\n\n" + Main.code()).str();
EXPECT_THAT(findReferences(AST, Main.point(), 0, TU.index().get()).References,
ElementsAre(RangeIs(Main.range())));
ElementsAre(rangeIs(Main.range())));
}
TEST(FindReferences, NeedsIndexForMacro) {
@ -2237,7 +2237,7 @@ TEST(FindReferences, NeedsIndexForMacro) {
// References in main file are returned without index.
EXPECT_THAT(
findReferences(AST, Main.point(), 0, /*Index=*/nullptr).References,
ElementsAre(RangeIs(Main.range())));
ElementsAre(rangeIs(Main.range())));
Annotations IndexedMain(R"cpp(
int indexed_main() {
@ -2252,7 +2252,7 @@ TEST(FindReferences, NeedsIndexForMacro) {
IndexedTU.HeaderCode = Header;
EXPECT_THAT(
findReferences(AST, Main.point(), 0, IndexedTU.index().get()).References,
ElementsAre(RangeIs(Main.range()), RangeIs(IndexedMain.range())));
ElementsAre(rangeIs(Main.range()), rangeIs(IndexedMain.range())));
auto LimitRefs =
findReferences(AST, Main.point(), /*Limit*/ 1, IndexedTU.index().get());
EXPECT_EQ(1u, LimitRefs.References.size());

View File

@ -29,7 +29,7 @@ TEST_F(ThreadingTest, TaskRunner) {
int Counter(0); /* GUARDED_BY(Mutex) */
{
AsyncTaskRunner Tasks;
auto scheduleIncrements = [&]() {
auto ScheduleIncrements = [&]() {
for (int TaskI = 0; TaskI < TasksCnt; ++TaskI) {
Tasks.runAsync("task", [&Counter, &Mutex, IncrementsPerTask]() {
for (int Increment = 0; Increment < IncrementsPerTask; ++Increment) {
@ -44,7 +44,7 @@ TEST_F(ThreadingTest, TaskRunner) {
// Make sure runAsync is not running tasks synchronously on the same
// thread by locking the Mutex used for increments.
std::lock_guard<std::mutex> Lock(Mutex);
scheduleIncrements();
ScheduleIncrements();
}
Tasks.wait();
@ -56,7 +56,7 @@ TEST_F(ThreadingTest, TaskRunner) {
{
std::lock_guard<std::mutex> Lock(Mutex);
Counter = 0;
scheduleIncrements();
ScheduleIncrements();
}
}
// Check that destructor has waited for tasks to finish.

View File

@ -28,7 +28,7 @@ using testing::ElementsAre;
using testing::SizeIs;
using testing::StartsWith;
MATCHER_P(StringNode, Val, "") {
MATCHER_P(stringNode, Val, "") {
if (arg->getType() != llvm::yaml::Node::NK_Scalar) {
*result_listener << "is a " << arg->getVerbatimTag();
return false;
@ -39,7 +39,7 @@ MATCHER_P(StringNode, Val, "") {
// Checks that N is a Mapping (JS object) with the expected scalar properties.
// The object must have all the Expected properties, but may have others.
bool VerifyObject(llvm::yaml::Node &N,
bool verifyObject(llvm::yaml::Node &N,
std::map<std::string, std::string> Expected) {
auto *M = llvm::dyn_cast<llvm::yaml::MappingNode>(&N);
if (!M) {
@ -109,24 +109,24 @@ TEST(TraceTest, SmokeTest) {
// (The order doesn't matter, but the YAML parser is awkward to use otherwise)
auto Prop = Root->begin();
ASSERT_NE(Prop, Root->end()) << "Expected displayTimeUnit property";
ASSERT_THAT(Prop->getKey(), StringNode("displayTimeUnit"));
EXPECT_THAT(Prop->getValue(), StringNode("ns"));
ASSERT_THAT(Prop->getKey(), stringNode("displayTimeUnit"));
EXPECT_THAT(Prop->getValue(), stringNode("ns"));
ASSERT_NE(++Prop, Root->end()) << "Expected traceEvents property";
EXPECT_THAT(Prop->getKey(), StringNode("traceEvents"));
EXPECT_THAT(Prop->getKey(), stringNode("traceEvents"));
auto *Events =
llvm::dyn_cast_or_null<llvm::yaml::SequenceNode>(Prop->getValue());
ASSERT_NE(Events, nullptr) << "traceEvents should be an array";
auto Event = Events->begin();
ASSERT_NE(Event, Events->end()) << "Expected process name";
EXPECT_TRUE(VerifyObject(*Event, {{"ph", "M"}, {"name", "process_name"}}));
EXPECT_TRUE(verifyObject(*Event, {{"ph", "M"}, {"name", "process_name"}}));
if (ThreadsHaveNames) {
ASSERT_NE(++Event, Events->end()) << "Expected thread name";
EXPECT_TRUE(VerifyObject(*Event, {{"ph", "M"}, {"name", "thread_name"}}));
EXPECT_TRUE(verifyObject(*Event, {{"ph", "M"}, {"name", "thread_name"}}));
}
ASSERT_NE(++Event, Events->end()) << "Expected log message";
EXPECT_TRUE(VerifyObject(*Event, {{"ph", "i"}, {"name", "Log"}}));
EXPECT_TRUE(verifyObject(*Event, {{"ph", "i"}, {"name", "Log"}}));
ASSERT_NE(++Event, Events->end()) << "Expected span end";
EXPECT_TRUE(VerifyObject(*Event, {{"ph", "X"}, {"name", "A"}}));
EXPECT_TRUE(verifyObject(*Event, {{"ph", "X"}, {"name", "A"}}));
ASSERT_EQ(++Event, Events->end());
ASSERT_EQ(++Prop, Root->end());
}