[clang-format] Break consecutive string literals in text protos
authorKrasimir Georgiev <krasimir@google.com>
Wed, 7 Mar 2018 21:30:38 +0000 (21:30 +0000)
committerKrasimir Georgiev <krasimir@google.com>
Wed, 7 Mar 2018 21:30:38 +0000 (21:30 +0000)
Summary:
This patch fixes a bug where consecutive string literals in text protos were
put on the same line.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D44204

llvm-svn: 326945

clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestTextProto.cpp

index 013a77b..97a201d 100644 (file)
@@ -2717,7 +2717,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
       return true;
   } else if (Style.Language == FormatStyle::LK_Cpp ||
              Style.Language == FormatStyle::LK_ObjC ||
-             Style.Language == FormatStyle::LK_Proto) {
+             Style.Language == FormatStyle::LK_Proto ||
+             Style.Language == FormatStyle::LK_TextProto) {
     if (Left.isStringLiteral() && Right.isStringLiteral())
       return true;
   }
index 1102055..39a2e71 100644 (file)
@@ -452,5 +452,11 @@ TEST_F(FormatTestTextProto, AcceptsOperatorAsKey) {
                "  >\n"
                ">");
 }
+
+TEST_F(FormatTestTextProto, BreaksConsecutiveStringLiterals) {
+  verifyFormat("ala: \"str1\"\n"
+               "     \"str2\"\n");
+}
+
 } // end namespace tooling
 } // end namespace clang