63 lines · cpp
1//===-- TweakTests.cpp ------------------------------------------*- 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-exception6//7//===----------------------------------------------------------------------===//8 9#include "TestFS.h"10#include "refactor/Tweak.h"11#include "clang/Basic/Diagnostic.h"12#include "clang/Basic/DiagnosticIDs.h"13#include "clang/Basic/DiagnosticOptions.h"14#include "clang/Basic/FileManager.h"15#include "clang/Basic/FileSystemOptions.h"16#include "clang/Basic/LLVM.h"17#include "clang/Basic/SourceLocation.h"18#include "clang/Basic/SourceManager.h"19#include "clang/Tooling/Core/Replacement.h"20#include "llvm/ADT/IntrusiveRefCntPtr.h"21#include "llvm/ADT/StringRef.h"22#include "llvm/Support/Error.h"23#include "llvm/Support/MemoryBuffer.h"24#include "llvm/Support/VirtualFileSystem.h"25#include "llvm/Testing/Support/Error.h"26#include "gmock/gmock-matchers.h"27#include "gmock/gmock.h"28#include "gtest/gtest.h"29#include <cassert>30#include <string>31#include <utility>32#include <vector>33 34namespace clang {35namespace clangd {36namespace {37 38TEST(FileEdits, AbsolutePath) {39 auto RelPaths = {"a.h", "foo.cpp", "test/test.cpp"};40 41 llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> MemFS(42 new llvm::vfs::InMemoryFileSystem);43 MemFS->setCurrentWorkingDirectory(testRoot());44 for (const auto *Path : RelPaths)45 MemFS->addFile(Path, 0, llvm::MemoryBuffer::getMemBuffer("", Path));46 FileManager FM(FileSystemOptions(), MemFS);47 DiagnosticOptions DiagOpts;48 DiagnosticsEngine DE(DiagnosticIDs::create(), DiagOpts);49 SourceManager SM(DE, FM);50 51 for (const auto *Path : RelPaths) {52 auto FID = SM.createFileID(*FM.getOptionalFileRef(Path), SourceLocation(),53 clang::SrcMgr::C_User);54 auto Res = Tweak::Effect::fileEdit(SM, FID, tooling::Replacements());55 ASSERT_THAT_EXPECTED(Res, llvm::Succeeded());56 EXPECT_EQ(Res->first, testPath(Path));57 }58}59 60} // namespace61} // namespace clangd62} // namespace clang63