brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 3285306 Raw
53 lines · cpp
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-exception6//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(Filename, 0, llvm::MemoryBuffer::getMemBuffer(""));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 forward44  // slashes and Windows would use backward slashes instead, so the headers are45  // not matched appropriately.46  auto STLVectorFile = addFile(*InMemFS, Files, "bits/stl_vector.h");47  ASSERT_EQ("<vector>", CI.mapHeader(STLVectorFile.getName()));48}49 50} // namespace51} // namespace clangd52} // namespace clang53