1//===-- CanonicalIncludesTests.cpp - --------------------------------------===//
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#include "index/CanonicalIncludes.h"
10#include "clang/Basic/FileEntry.h"
11#include "clang/Basic/FileManager.h"
12#include "clang/Basic/FileSystemOptions.h"
13#include "clang/Basic/LangOptions.h"
14#include "llvm/ADT/IntrusiveRefCntPtr.h"
15#include "llvm/ADT/StringRef.h"
16#include "llvm/Support/Error.h"
17#include "llvm/Support/VirtualFileSystem.h"
18#include "llvm/Testing/Support/Error.h"
19#include "gtest/gtest.h"
20
21namespace clang {
22namespace clangd {
23namespace {
24
25FileEntryRef addFile(llvm::vfs::InMemoryFileSystem &FS, FileManager &FM,
26 llvm::StringRef Filename) {
27 FS.addFile(Path: Filename, ModificationTime: 0, Buffer: llvm::MemoryBuffer::getMemBuffer(InputData: ""));
28 auto File = FM.getFileRef(Filename);
29 EXPECT_THAT_EXPECTED(File, llvm::Succeeded());
30 return *File;
31}
32
33TEST(CanonicalIncludesTest, SystemHeaderMap) {
34 auto InMemFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
35 FileManager Files(FileSystemOptions(), InMemFS);
36
37 CanonicalIncludes CI;
38 LangOptions Language;
39 Language.CPlusPlus = true;
40 CI.addSystemHeadersMapping(Language);
41
42 // We should have a path from 'bits/stl_vector.h' to '<vector>'.
43 // FIXME: The Standrad Library map in CanonicalIncludes expects forward
44 // slashes and Windows would use backward slashes instead, so the headers are
45 // not matched appropriately.
46 auto STLVectorFile = addFile(FS&: *InMemFS, FM&: Files, Filename: "bits/stl_vector.h");
47 ASSERT_EQ("<vector>", CI.mapHeader(STLVectorFile.getName()));
48}
49
50} // namespace
51} // namespace clangd
52} // namespace clang
53

source code of clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp