Change how replacements are filtered (#541)

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.
This commit is contained in:
Jon Meow
2021-06-03 16:35:55 -07:00
committed by GitHub
parent c836ae78bb
commit f180c64454
4 changed files with 36 additions and 21 deletions
@@ -16,23 +16,20 @@ 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()));
auto it = replacements.find(Filename);
if (it != replacements.end()) {
auto actual = ct::applyAllReplacements(before, it->second);
// 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));
} else {
// No replacements; before and after should match.
EXPECT_THAT(before, testing::Eq(after));
}
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