Bump version to 19.1.0 (final)
[llvm-project.git] / clang-tools-extra / unittests / clang-apply-replacements / ApplyReplacementsTest.cpp
blob4fe57e618004ddef911123c549187a51fa945a51
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 //===----------------------------------------------------------------------===//
10 #include "clang-apply-replacements/Tooling/ApplyReplacements.h"
11 #include "clang/Format/Format.h"
12 #include "gtest/gtest.h"
14 using namespace clang::replace;
15 using namespace llvm;
17 namespace clang {
18 namespace tooling {
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;
32 // Test to ensure diagnostics with no fixes, will be merged correctly
33 // before applying.
34 TEST(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("path/to/source.cpp", "diagnostic", {}, {}, "path/to");
43 FileToChangesMap ReplacementsMap;
45 EXPECT_TRUE(mergeAndDeduplicate(TURs, TUs, ReplacementsMap, SM));
46 EXPECT_TRUE(ReplacementsMap.empty());
49 } // end namespace tooling
50 } // end namespace clang