clang-tools  14.0.0git
TestWorkspace.h
Go to the documentation of this file.
1 //===--- TestWorkspace.h - Utility for writing multi-file tests --*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // TestWorkspace builds on TestTU to provide a way to write tests involving
10 // several related files with inclusion relationships between them.
11 //
12 // The tests can exercise both index and AST based operations.
13 //
14 //===---------------------------------------------------------------------===//
15 
16 #ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTWORKSPACE_H
17 #define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTWORKSPACE_H
18 
19 #include "TestFS.h"
20 #include "TestTU.h"
21 #include "index/FileIndex.h"
22 #include "index/Index.h"
23 #include "llvm/ADT/StringRef.h"
24 #include <string>
25 #include <vector>
26 
27 namespace clang {
28 namespace clangd {
29 
31 public:
32  // The difference between addSource() and addMainFile() is that only main
33  // files will be indexed.
34  void addSource(llvm::StringRef Filename, llvm::StringRef Code) {
35  addInput(Filename.str(), {Code.str(), /*IsMainFile=*/false});
36  }
37  void addMainFile(llvm::StringRef Filename, llvm::StringRef Code) {
38  addInput(Filename.str(), {Code.str(), /*IsMainFile=*/true});
39  }
40 
41  std::unique_ptr<SymbolIndex> index();
42 
43  Optional<ParsedAST> openFile(llvm::StringRef Filename);
44 
45 private:
46  struct SourceFile {
47  std::string Code;
48  bool IsMainFile = false;
49  };
50  llvm::StringMap<SourceFile> Inputs;
51  TestTU TU;
52 
53  void addInput(llvm::StringRef Filename, const SourceFile &Input);
54 };
55 
56 } // namespace clangd
57 } // namespace clang
58 
59 #endif // LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTWORKSPACE_H
Index.h
clang::clangd::TestWorkspace::addSource
void addSource(llvm::StringRef Filename, llvm::StringRef Code)
Definition: TestWorkspace.h:34
TestTU.h
Filename
std::string Filename
Filename as a string.
Definition: IncludeOrderCheck.cpp:39
clang::clangd::TestWorkspace::openFile
Optional< ParsedAST > openFile(llvm::StringRef Filename)
Definition: TestWorkspace.cpp:33
Code
std::string Code
Definition: FindTargetTests.cpp:67
TestFS.h
clang::clangd::TestWorkspace::index
std::unique_ptr< SymbolIndex > index()
Definition: TestWorkspace.cpp:15
FileIndex.h
clang::clangd::TestWorkspace
Definition: TestWorkspace.h:30
clang::clangd::TestWorkspace::addMainFile
void addMainFile(llvm::StringRef Filename, llvm::StringRef Code)
Definition: TestWorkspace.h:37
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27