Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Mar 28, 2020. It is now read-only.
/swift-clangPublic archive

Commit798cf2a

Browse files
yvvancyndyishida
authored andcommitted
[clang-tidy] Fix the YAML created for checks like modernize-pass-by-value
Currently this check generates the replacement with the newline in the end.The proper way to export it to YAML is to have two \n\n instead of one.Without this fix clients should reinterpret the replacement as"#include <utility> " instead of "#include <utility>\n"Differential Revision:https://reviews.llvm.org/D63482git-svn-id:https://llvm.org/svn/llvm-project/cfe/trunk@365017 91177308-0d34-0410-b5e6-96231b3b80d8
1 parenteeafed2 commit798cf2a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

‎include/clang/Tooling/ReplacementsYaml.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ template <> struct MappingTraits<clang::tooling::Replacement> {
3535

3636
NormalizedReplacement(const IO &,const clang::tooling::Replacement &R)
3737
: FilePath(R.getFilePath()), Offset(R.getOffset()),
38-
Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
38+
Length(R.getLength()), ReplacementText(R.getReplacementText()) {
39+
size_t lineBreakPos = ReplacementText.find('\n');
40+
while (lineBreakPos != std::string::npos) {
41+
ReplacementText.replace(lineBreakPos,1,"\n\n");
42+
lineBreakPos = ReplacementText.find('\n', lineBreakPos +2);
43+
}
44+
}
3945

4046
clang::tooling::Replacementdenormalize(const IO &) {
4147
returnclang::tooling::Replacement(FilePath, Offset, Length,

‎unittests/Tooling/ReplacementsYamlTest.cpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,30 @@ TEST(ReplacementsYamlTest, serializesReplacements) {
4646
YamlContentStream.str().c_str());
4747
}
4848

49+
TEST(ReplacementsYamlTest, serializesNewLines) {
50+
TranslationUnitReplacements Doc;
51+
52+
Doc.MainSourceFile ="/path/to/source.cpp";
53+
Doc.Replacements.emplace_back("/path/to/file1.h",0,0,"#include <utility>\n");
54+
55+
std::string YamlContent;
56+
llvm::raw_string_ostreamYamlContentStream(YamlContent);
57+
58+
yaml::OutputYAML(YamlContentStream);
59+
YAML << Doc;
60+
61+
// NOTE: If this test starts to fail for no obvious reason, check whitespace.
62+
ASSERT_STREQ("---\n"
63+
"MainSourceFile: '/path/to/source.cpp'\n"
64+
"Replacements:\n"// Extra whitespace here!
65+
" - FilePath: '/path/to/file1.h'\n"
66+
" Offset: 0\n"
67+
" Length: 0\n"
68+
" ReplacementText: '#include <utility>\n\n'\n"
69+
"...\n",
70+
YamlContentStream.str().c_str());
71+
}
72+
4973
TEST(ReplacementsYamlTest, deserializesReplacements) {
5074
std::string YamlContent ="---\n"
5175
"MainSourceFile: /path/to/source.cpp\n"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp