1//===- clang-apply-replacements/ApplyReplacementsTest.cpp
2//----------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#include "clang-apply-replacements/Tooling/ApplyReplacements.h"
11#include "clang/Format/Format.h"
12#include "gtest/gtest.h"
13
14using namespace clang::replace;
15using namespace llvm;
16
17namespace clang {
18namespace tooling {
19
20static TUDiagnostics
21makeTUDiagnostics(const std::string &MainSourceFile, StringRef DiagnosticName,
22 const DiagnosticMessage &Message,
23 const StringMap<Replacements> &Replacements,
24 StringRef BuildDirectory) {
25 TUDiagnostics TUs;
26 TUs.push_back(
27 x: {.MainSourceFile: MainSourceFile,
28 .Diagnostics: {{DiagnosticName, Message, {}, Diagnostic::Warning, BuildDirectory}}});
29 return TUs;
30}
31
32// Test to ensure diagnostics with no fixes, will be merged correctly
33// before applying.
34TEST(ApplyReplacementsTest, mergeDiagnosticsWithNoFixes) {
35 IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
36 DiagnosticsEngine Diagnostics(
37 IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts.get());
38 FileManager Files((FileSystemOptions()));
39 SourceManager SM(Diagnostics, Files);
40 TUReplacements TURs;
41 TUDiagnostics TUs =
42 makeTUDiagnostics(MainSourceFile: "path/to/source.cpp", DiagnosticName: "diagnostic", Message: {}, Replacements: {}, BuildDirectory: "path/to");
43 FileToChangesMap ReplacementsMap;
44
45 EXPECT_TRUE(mergeAndDeduplicate(TURs, TUs, ReplacementsMap, SM));
46 EXPECT_TRUE(ReplacementsMap.empty());
47}
48
49} // end namespace tooling
50} // end namespace clang
51

source code of clang-tools-extra/unittests/clang-apply-replacements/ApplyReplacementsTest.cpp