| 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-exception |
| 6 |
// |
| 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 |
|
| 34 |
namespace clang { |
| 35 |
namespace clangd { |
| 36 |
namespace { |
| 37 |
|
| 38 |
TEST(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 |
DiagnosticsEngine DE(new DiagnosticIDs, new DiagnosticOptions); |
| 48 |
SourceManager SM(DE, FM); |
| 49 |
|
| 50 |
for (const auto *Path : RelPaths) { |
| 51 |
auto FID = SM.createFileID(*FM.getOptionalFileRef(Path), SourceLocation(), |
| 52 |
clang::SrcMgr::C_User); |
| 53 |
auto Res = Tweak::Effect::fileEdit(SM, FID, tooling::Replacements()); |
| 54 |
ASSERT_THAT_EXPECTED(Res, llvm::Succeeded()); |
| 55 |
EXPECT_EQ(Res->first, testPath(Path)); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
} // namespace |
| 60 |
} // namespace clangd |
| 61 |
} // namespace clang |