[PATCH] D63482: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value
Ivan Donchevskii via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 2 00:40:41 PDT 2019
yvvan updated this revision to Diff 207483.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63482/new/
https://reviews.llvm.org/D63482
Files:
clang/include/clang/Tooling/ReplacementsYaml.h
clang/unittests/Tooling/ReplacementsYamlTest.cpp
Index: clang/unittests/Tooling/ReplacementsYamlTest.cpp
===================================================================
--- clang/unittests/Tooling/ReplacementsYamlTest.cpp
+++ clang/unittests/Tooling/ReplacementsYamlTest.cpp
@@ -46,6 +46,30 @@
YamlContentStream.str().c_str());
}
+TEST(ReplacementsYamlTest, serializesNewLines) {
+ TranslationUnitReplacements Doc;
+
+ Doc.MainSourceFile = "/path/to/source.cpp";
+ Doc.Replacements.emplace_back("/path/to/file1.h", 0, 0, "#include <utility>\n");
+
+ std::string YamlContent;
+ llvm::raw_string_ostream YamlContentStream(YamlContent);
+
+ yaml::Output YAML(YamlContentStream);
+ YAML << Doc;
+
+ // NOTE: If this test starts to fail for no obvious reason, check whitespace.
+ ASSERT_STREQ("---\n"
+ "MainSourceFile: '/path/to/source.cpp'\n"
+ "Replacements: \n" // Extra whitespace here!
+ " - FilePath: '/path/to/file1.h'\n"
+ " Offset: 0\n"
+ " Length: 0\n"
+ " ReplacementText: '#include <utility>\n\n'\n"
+ "...\n",
+ YamlContentStream.str().c_str());
+}
+
TEST(ReplacementsYamlTest, deserializesReplacements) {
std::string YamlContent = "---\n"
"MainSourceFile: /path/to/source.cpp\n"
Index: clang/include/clang/Tooling/ReplacementsYaml.h
===================================================================
--- clang/include/clang/Tooling/ReplacementsYaml.h
+++ clang/include/clang/Tooling/ReplacementsYaml.h
@@ -35,7 +35,13 @@
NormalizedReplacement(const IO &, const clang::tooling::Replacement &R)
: FilePath(R.getFilePath()), Offset(R.getOffset()),
- Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
+ Length(R.getLength()), ReplacementText(R.getReplacementText()) {
+ size_t lineBreakPos = ReplacementText.find('\n');
+ while (lineBreakPos != std::string::npos) {
+ ReplacementText.replace(lineBreakPos, 1, "\n\n");
+ lineBreakPos = ReplacementText.find('\n', lineBreakPos + 2);
+ }
+ }
clang::tooling::Replacement denormalize(const IO &) {
return clang::tooling::Replacement(FilePath, Offset, Length,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63482.207483.patch
Type: text/x-patch
Size: 2279 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190702/8e5b333a/attachment-0001.bin>
More information about the cfe-commits
mailing list