Debian Codegraph @

clang-tools-extra/unittests/clang-apply-replacements/ApplyReplacementsTest.cpp

raw
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
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(
27 {MainSourceFile,
28 {{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.
34 TEST(ApplyReplacementsTest, mergeDiagnosticsWithNoFixes) {
35 DiagnosticOptions DiagOpts;
36 DiagnosticsEngine Diagnostics(DiagnosticIDs::create(), DiagOpts);
37 FileManager Files((FileSystemOptions()));
38 SourceManager SM(Diagnostics, Files);
39 TUReplacements TURs;
40 TUDiagnostics TUs =
41 makeTUDiagnostics("path/to/source.cpp", "diagnostic", {}, {}, "path/to");
42 FileToChangesMap ReplacementsMap;
43
44 EXPECT_TRUE(mergeAndDeduplicate(TURs, TUs, ReplacementsMap, SM));
45 EXPECT_TRUE(ReplacementsMap.empty());
46 }
47
48 } // end namespace tooling
49 } // end namespace clang