17#include "clang/Basic/LangOptions.h"
18#include "clang/Basic/SourceManager.h"
19#include "gmock/gmock.h"
20#include "gtest/gtest.h"
23using namespace testing;
35 EXPECT_THAT(CXX, HasSubstr(
"#include <string>"));
36 EXPECT_THAT(CXX, HasSubstr(
"#include <cstdio>"));
37 EXPECT_THAT(CXX, Not(HasSubstr(
"#include <ios646.h>")));
41 EXPECT_THAT(
C, Not(HasSubstr(
"#include <string>")));
42 EXPECT_THAT(
C, Not(HasSubstr(
"#include <cstdio>")));
43 EXPECT_THAT(
C, HasSubstr(
"#include <stdio.h>"));
51 FS.Files[
"std/foo.h"] = R
"cpp(
52 #include <platform_stuff.h>
53 #if __cplusplus >= 201703L
55 #elif __cplusplus >= 201402L
61 FS.Files["nonstd/platform_stuff.h"] =
"int magic = 42;";
63 ParseInputs OriginalInputs;
64 OriginalInputs.TFS = &FS;
65 OriginalInputs.CompileCommand.Filename =
testPath(
"main.cc");
66 OriginalInputs.CompileCommand.CommandLine = {
"clang++",
testPath(
"main.cc"),
68 "-isystemnonstd/",
"-std=c++14"};
69 OriginalInputs.CompileCommand.Directory =
testRoot();
70 IgnoreDiagnostics Diags;
79 EXPECT_THAT(
Symbols, ElementsAre(Named(
"foo14")));
82TEST(StdLibTests, StdLibSet) {
85 FS.Files[
"std/_"] =
"";
86 FS.Files[
"libc/_"] =
"";
88 auto Add = [&](
const LangOptions &LO,
89 std::vector<llvm::StringRef> SearchPath) {
90 SourceManagerForFile SM(
"scratch",
"");
91 SM.get().getFileManager().setVirtualFileSystem(FS.
view(std::nullopt));
92 HeaderSearch HS(
nullptr, SM.get(), SM.get().getDiagnostics(), LO,
94 for (
auto P : SearchPath)
97 cantFail(SM.get().getFileManager().getDirectoryRef(
testPath(P))),
98 SrcMgr::C_System,
false),
100 return Set.add(LO, HS);
105 WithContextValue Disabled(
Config::Key, std::move(Cfg));
109 EXPECT_FALSE(Add(LO, {
"std"})) <<
"Disabled in config";
115 EXPECT_FALSE(Add(LO, {
"std"})) <<
"No <vector> found";
116 FS.Files[
"std/vector"] =
"class vector;";
117 EXPECT_TRUE(Add(LO, {
"std"})) <<
"Indexing as C++98";
118 EXPECT_FALSE(Add(LO, {
"std"})) <<
"Don't reindex";
119 LO.CPlusPlus11 =
true;
120 EXPECT_TRUE(Add(LO, {
"std"})) <<
"Indexing as C++11";
121 LO.CPlusPlus =
false;
122 EXPECT_FALSE(Add(LO, {
"libc"})) <<
"No <stdio.h>";
123 FS.Files[
"libc/stdio.h"] =
true;
124 EXPECT_TRUE(Add(LO, {
"libc"})) <<
"Indexing as C";
128 return arg.Name ==
Name && arg.Includes.size() == 1 &&
129 llvm::StringRef(arg.Includes.front().Header).starts_with(
"<");
132TEST(StdLibTests, EndToEnd) {
138 FS.Files[
"stdlib/vector"] =
139 "namespace std { template <class> class vector; }";
140 FS.Files[
"stdlib/list"] =
141 " namespace std { template <typename T> class list; }";
142 MockCompilationDatabase CDB;
143 CDB.ExtraClangFlags.push_back(
"-isystem" +
testPath(
"stdlib"));
145 Opts.BuildDynamicSymbolIndex =
true;
146 ClangdServer Server(CDB, FS, Opts);
148 Annotations
A(
"std::^");
150 Server.addDocument(
testPath(
"foo.cc"),
A.code());
151 ASSERT_TRUE(Server.blockUntilIdleForTest());
152 clangd::CodeCompleteOptions CCOpts;
156 Completions.Completions,
157 UnorderedElementsAre(StdlibSymbol(
"list"), StdlibSymbol(
"vector")));
llvm::SmallString< 256U > Name
const bool Enabled
Whether the heuristic is to be enabled by default.
std::unique_ptr< CompilerInvocation > CI
static Options optsForTest()
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > view(std::nullopt_t CWD) const
Obtain a vfs::FileSystem with an arbitrary initial working directory.
std::unique_ptr< CompilerInvocation > buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D, std::vector< std::string > *CC1Args)
Builds compiler invocation that could be used to build AST or preamble.
llvm::Expected< CodeCompleteResult > runCodeComplete(ClangdServer &Server, PathRef File, Position Pos, clangd::CodeCompleteOptions Opts)
std::string testPath(PathRef File, llvm::sys::path::Style Style)
TEST(BackgroundQueueTest, Priority)
llvm::StringRef getStdlibUmbrellaHeader(const LangOptions &LO)
SymbolSlab indexStandardLibrary(llvm::StringRef HeaderSources, std::unique_ptr< CompilerInvocation > CI, const StdLibLocation &Loc, const ThreadsafeFS &TFS)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static clangd::Key< Config > Key
Context key which can be used to set the current Config.
struct clang::clangd::Config::@3 Index
Controls index behavior.