1 //===--- TestWorkspace.h - Utility for writing multi-file tests --*- C++-*-===//
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
7 //===----------------------------------------------------------------------===//
9 // TestWorkspace builds on TestTU to provide a way to write tests involving
10 // several related files with inclusion relationships between them.
12 // The tests can exercise both index and AST based operations.
14 //===---------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTWORKSPACE_H
17 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTWORKSPACE_H
20 #include "index/Index.h"
21 #include "llvm/ADT/StringRef.h"
30 // The difference between addSource() and addMainFile() is that only main
31 // files will be indexed.
32 void addSource(llvm::StringRef Filename
, llvm::StringRef Code
) {
33 addInput(Filename
.str(), {Code
.str(), /*IsMainFile=*/false});
35 void addMainFile(llvm::StringRef Filename
, llvm::StringRef Code
) {
36 addInput(Filename
.str(), {Code
.str(), /*IsMainFile=*/true});
39 std::unique_ptr
<SymbolIndex
> index();
41 Optional
<ParsedAST
> openFile(llvm::StringRef Filename
);
46 bool IsMainFile
= false;
48 llvm::StringMap
<SourceFile
> Inputs
;
51 void addInput(llvm::StringRef Filename
, const SourceFile
&Input
);
57 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTWORKSPACE_H