Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/apple/stable/20190619' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-ci committed Oct 4, 2019
2 parents 25814dd + 2ede160 commit dbf97d9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
8 changes: 7 additions & 1 deletion include/clang/Tooling/ReplacementsYaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ template <> struct MappingTraits<clang::tooling::Replacement> {

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,
Expand Down
14 changes: 7 additions & 7 deletions unittests/Tooling/DiagnosticsYamlTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,34 @@ static Diagnostic makeDiagnostic(StringRef DiagnosticName,
static const char *YAMLContent =
"---\n"
"MainSourceFile: 'path/to/source.cpp'\n"
"Diagnostics: \n"
"Diagnostics:\n"
" - DiagnosticName: 'diagnostic#1\'\n"
" DiagnosticMessage: \n"
" DiagnosticMessage:\n"
" Message: 'message #1'\n"
" FilePath: 'path/to/source.cpp'\n"
" FileOffset: 55\n"
" Replacements: \n"
" Replacements:\n"
" - FilePath: 'path/to/source.cpp'\n"
" Offset: 100\n"
" Length: 12\n"
" ReplacementText: 'replacement #1'\n"
" - DiagnosticName: 'diagnostic#2'\n"
" DiagnosticMessage: \n"
" DiagnosticMessage:\n"
" Message: 'message #2'\n"
" FilePath: 'path/to/header.h'\n"
" FileOffset: 60\n"
" Replacements: \n"
" Replacements:\n"
" - FilePath: 'path/to/header.h'\n"
" Offset: 62\n"
" Length: 2\n"
" ReplacementText: 'replacement #2'\n"
" - DiagnosticName: 'diagnostic#3'\n"
" DiagnosticMessage: \n"
" DiagnosticMessage:\n"
" Message: 'message #3'\n"
" FilePath: 'path/to/source2.cpp'\n"
" FileOffset: 72\n"
" Replacements: []\n"
" Notes: \n"
" Notes:\n"
" - Message: Note1\n"
" FilePath: 'path/to/note1.cpp'\n"
" FileOffset: 88\n"
Expand Down
2 changes: 1 addition & 1 deletion unittests/Tooling/RefactoringActionRulesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ TEST_F(RefactoringActionRulesTest, MyFirstRefactoringRule) {
"Error: ''\n"
"InsertedHeaders: []\n"
"RemovedHeaders: []\n"
"Replacements: \n" // Extra whitespace here!
"Replacements:\n"
" - FilePath: input.cpp\n"
" Offset: 30\n"
" Length: 1\n"
Expand Down
12 changes: 6 additions & 6 deletions unittests/Tooling/RefactoringTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,11 +1172,11 @@ TEST_F(AtomicChangeTest, AtomicChangeToYAML) {
"Key: 'input.cpp:20'\n"
"FilePath: input.cpp\n"
"Error: ''\n"
"InsertedHeaders: \n" // Extra whitespace here!
"InsertedHeaders:\n"
" - a.h\n"
"RemovedHeaders: \n" // Extra whitespace here!
"RemovedHeaders:\n"
" - b.h\n"
"Replacements: \n" // Extra whitespace here!
"Replacements:\n"
" - FilePath: input.cpp\n"
" Offset: 20\n"
" Length: 0\n"
Expand All @@ -1194,11 +1194,11 @@ TEST_F(AtomicChangeTest, YAMLToAtomicChange) {
"Key: 'input.cpp:20'\n"
"FilePath: input.cpp\n"
"Error: 'ok'\n"
"InsertedHeaders: \n" // Extra whitespace here!
"InsertedHeaders:\n"
" - a.h\n"
"RemovedHeaders: \n" // Extra whitespace here!
"RemovedHeaders:\n"
" - b.h\n"
"Replacements: \n" // Extra whitespace here!
"Replacements:\n"
" - FilePath: input.cpp\n"
" Offset: 20\n"
" Length: 0\n"
Expand Down
26 changes: 25 additions & 1 deletion unittests/Tooling/ReplacementsYamlTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TEST(ReplacementsYamlTest, serializesReplacements) {
// 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!
"Replacements:\n"
" - FilePath: '/path/to/file1.h'\n"
" Offset: 232\n"
" Length: 56\n"
Expand All @@ -46,6 +46,30 @@ TEST(ReplacementsYamlTest, serializesReplacements) {
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"
" - 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"
Expand Down

0 comments on commit dbf97d9

Please sign in to comment.