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

Commitdbf97d9

Browse files
committed
Merge remote-tracking branch 'origin/apple/stable/20190619' into stable
2 parents25814dd +2ede160 commitdbf97d9

File tree

5 files changed

+46
-16
lines changed

5 files changed

+46
-16
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/DiagnosticsYamlTest.cpp‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,34 @@ static Diagnostic makeDiagnostic(StringRef DiagnosticName,
4242
staticconstchar *YAMLContent =
4343
"---\n"
4444
"MainSourceFile: 'path/to/source.cpp'\n"
45-
"Diagnostics:\n"
45+
"Diagnostics:\n"
4646
" - DiagnosticName: 'diagnostic#1\'\n"
47-
" DiagnosticMessage:\n"
47+
" DiagnosticMessage:\n"
4848
" Message: 'message #1'\n"
4949
" FilePath: 'path/to/source.cpp'\n"
5050
" FileOffset: 55\n"
51-
" Replacements:\n"
51+
" Replacements:\n"
5252
" - FilePath: 'path/to/source.cpp'\n"
5353
" Offset: 100\n"
5454
" Length: 12\n"
5555
" ReplacementText: 'replacement #1'\n"
5656
" - DiagnosticName: 'diagnostic#2'\n"
57-
" DiagnosticMessage:\n"
57+
" DiagnosticMessage:\n"
5858
" Message: 'message #2'\n"
5959
" FilePath: 'path/to/header.h'\n"
6060
" FileOffset: 60\n"
61-
" Replacements:\n"
61+
" Replacements:\n"
6262
" - FilePath: 'path/to/header.h'\n"
6363
" Offset: 62\n"
6464
" Length: 2\n"
6565
" ReplacementText: 'replacement #2'\n"
6666
" - DiagnosticName: 'diagnostic#3'\n"
67-
" DiagnosticMessage:\n"
67+
" DiagnosticMessage:\n"
6868
" Message: 'message #3'\n"
6969
" FilePath: 'path/to/source2.cpp'\n"
7070
" FileOffset: 72\n"
7171
" Replacements: []\n"
72-
" Notes:\n"
72+
" Notes:\n"
7373
" - Message: Note1\n"
7474
" FilePath: 'path/to/note1.cpp'\n"
7575
" FileOffset: 88\n"

‎unittests/Tooling/RefactoringActionRulesTest.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ TEST_F(RefactoringActionRulesTest, MyFirstRefactoringRule) {
118118
"Error: ''\n"
119119
"InsertedHeaders: []\n"
120120
"RemovedHeaders: []\n"
121-
"Replacements:\n"// Extra whitespace here!
121+
"Replacements:\n"
122122
" - FilePath: input.cpp\n"
123123
" Offset: 30\n"
124124
" Length: 1\n"

‎unittests/Tooling/RefactoringTest.cpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,11 +1172,11 @@ TEST_F(AtomicChangeTest, AtomicChangeToYAML) {
11721172
"Key: 'input.cpp:20'\n"
11731173
"FilePath: input.cpp\n"
11741174
"Error: ''\n"
1175-
"InsertedHeaders:\n"// Extra whitespace here!
1175+
"InsertedHeaders:\n"
11761176
" - a.h\n"
1177-
"RemovedHeaders:\n"// Extra whitespace here!
1177+
"RemovedHeaders:\n"
11781178
" - b.h\n"
1179-
"Replacements:\n"// Extra whitespace here!
1179+
"Replacements:\n"
11801180
" - FilePath: input.cpp\n"
11811181
" Offset: 20\n"
11821182
" Length: 0\n"
@@ -1194,11 +1194,11 @@ TEST_F(AtomicChangeTest, YAMLToAtomicChange) {
11941194
"Key: 'input.cpp:20'\n"
11951195
"FilePath: input.cpp\n"
11961196
"Error: 'ok'\n"
1197-
"InsertedHeaders:\n"// Extra whitespace here!
1197+
"InsertedHeaders:\n"
11981198
" - a.h\n"
1199-
"RemovedHeaders:\n"// Extra whitespace here!
1199+
"RemovedHeaders:\n"
12001200
" - b.h\n"
1201-
"Replacements:\n"// Extra whitespace here!
1201+
"Replacements:\n"
12021202
" - FilePath: input.cpp\n"
12031203
" Offset: 20\n"
12041204
" Length: 0\n"

‎unittests/Tooling/ReplacementsYamlTest.cpp‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ TEST(ReplacementsYamlTest, serializesReplacements) {
3333
// NOTE: If this test starts to fail for no obvious reason, check whitespace.
3434
ASSERT_STREQ("---\n"
3535
"MainSourceFile: '/path/to/source.cpp'\n"
36-
"Replacements:\n"// Extra whitespace here!
36+
"Replacements:\n"
3737
" - FilePath: '/path/to/file1.h'\n"
3838
" Offset: 232\n"
3939
" Length: 56\n"
@@ -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"
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