mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 12:00:12 +01:00
This replaces the use of `isExpansionInMainFile` with instead taking the list of input files, and only touching them. This doesn't keep `isExpansionInMainFile` because it should be redundant, and as such it'd be easy to forget. Unless it starts being a performance issue, it's probably better to omit.
36 lines
1.3 KiB
C++
36 lines
1.3 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#include "migrate_cpp/cpp_refactoring/matcher_test_base.h"
|
|
|
|
#include "clang/Tooling/Tooling.h"
|
|
#include "gmock/gmock.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace ct = ::clang::tooling;
|
|
|
|
namespace Carbon {
|
|
|
|
void MatcherTestBase::ExpectReplacement(llvm::StringRef before,
|
|
llvm::StringRef after) {
|
|
auto factory = ct::newFrontendActionFactory(&finder);
|
|
constexpr char Filename[] = "test.cc";
|
|
replacements.clear();
|
|
replacements.insert({Filename, {}});
|
|
ASSERT_TRUE(ct::runToolOnCodeWithArgs(
|
|
factory->create(), before, {}, Filename, "clang-tool",
|
|
std::make_shared<clang::PCHContainerOperations>(),
|
|
ct::FileContentMappings()));
|
|
EXPECT_THAT(replacements, testing::ElementsAre(testing::Key(Filename)));
|
|
auto actual = ct::applyAllReplacements(before, replacements[Filename]);
|
|
// Split lines to get gmock to get an easier-to-read error.
|
|
llvm::SmallVector<llvm::StringRef, 0> actual_lines;
|
|
llvm::SplitString(*actual, actual_lines, "\n");
|
|
llvm::SmallVector<llvm::StringRef, 0> after_lines;
|
|
llvm::SplitString(after, after_lines, "\n");
|
|
EXPECT_THAT(actual_lines, testing::ContainerEq(after_lines));
|
|
}
|
|
|
|
} // namespace Carbon
|