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
14 using namespace clang::replace;
15 using namespace llvm;
16
17 namespace clang {
18 namespace tooling {
19
20 static TUDiagnostics
makeTUDiagnostics(const std::string & MainSourceFile,StringRef DiagnosticName,const DiagnosticMessage & Message,const StringMap<Replacements> & Replacements,StringRef BuildDirectory)21 makeTUDiagnostics(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({MainSourceFile,
27 {{DiagnosticName,
28 Message,
29 {},
30 Diagnostic::Warning,
31 BuildDirectory,
32 {}}}});
33 return TUs;
34 }
35
36 // Test to ensure diagnostics with no fixes, will be merged correctly
37 // before applying.
TEST(ApplyReplacementsTest,mergeDiagnosticsWithNoFixes)38 TEST(ApplyReplacementsTest, mergeDiagnosticsWithNoFixes) {
39 IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
40 DiagnosticsEngine Diagnostics(
41 IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts.get());
42 FileManager Files((FileSystemOptions()));
43 SourceManager SM(Diagnostics, Files);
44 TUReplacements TURs;
45 TUDiagnostics TUs =
46 makeTUDiagnostics("path/to/source.cpp", "diagnostic", {}, {}, "path/to");
47 FileToChangesMap ReplacementsMap;
48
49 EXPECT_TRUE(mergeAndDeduplicate(TURs, TUs, ReplacementsMap, SM));
50 EXPECT_TRUE(ReplacementsMap.empty());
51 }
52
53 } // end namespace tooling
54 } // end namespace clang
55