[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
Wed Jul 3 03:21:44 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL365017: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value (authored by yvvan, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63482?vs=207483&id=207747#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63482/new/

https://reviews.llvm.org/D63482

Files:
  cfe/trunk/include/clang/Tooling/ReplacementsYaml.h
  cfe/trunk/unittests/Tooling/ReplacementsYamlTest.cpp


Index: cfe/trunk/unittests/Tooling/ReplacementsYamlTest.cpp
===================================================================
--- cfe/trunk/unittests/Tooling/ReplacementsYamlTest.cpp
+++ cfe/trunk/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: cfe/trunk/include/clang/Tooling/ReplacementsYaml.h
===================================================================
--- cfe/trunk/include/clang/Tooling/ReplacementsYaml.h
+++ cfe/trunk/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.207747.patch
Type: text/x-patch
Size: 2303 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190703/72c422b5/attachment-0001.bin>


More information about the cfe-commits mailing list