From 374f1d81febf8143e8e633296a42c2311699c5b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= Date: Sat, 12 Dec 2020 17:37:35 +0100 Subject: [PATCH] [clang-format] Fix handling of TextProto comments Differential Revision: https://reviews.llvm.org/D93163 --- clang/lib/Format/BreakableToken.cpp | 9 +++++++-- clang/unittests/Format/FormatTestTextProto.cpp | 16 ++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp index 6a240fdec8b9..c5edc670393c 100644 --- a/clang/lib/Format/BreakableToken.cpp +++ b/clang/lib/Format/BreakableToken.cpp @@ -789,9 +789,14 @@ BreakableLineCommentSection::BreakableLineCommentSection( Prefix[i] = "///< "; else if (Prefix[i] == "//!<") Prefix[i] = "//!< "; - else if (Prefix[i] == "#" && - Style.Language == FormatStyle::LK_TextProto) + else if (Prefix[i] == "#") Prefix[i] = "# "; + else if (Prefix[i] == "##") + Prefix[i] = "## "; + else if (Prefix[i] == "###") + Prefix[i] = "### "; + else if (Prefix[i] == "####") + Prefix[i] = "#### "; } Tokens[i] = LineTok; diff --git a/clang/unittests/Format/FormatTestTextProto.cpp b/clang/unittests/Format/FormatTestTextProto.cpp index 3ae13d172865..1e2594893841 100644 --- a/clang/unittests/Format/FormatTestTextProto.cpp +++ b/clang/unittests/Format/FormatTestTextProto.cpp @@ -380,25 +380,29 @@ TEST_F(FormatTestTextProto, KeepsCommentsIndentedInList) { "cccccccccccccccccccccccc: 3849"); } -TEST_F(FormatTestTextProto, UnderstandsHashHashComments) { +TEST_F(FormatTestTextProto, UnderstandsHashComments) { FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto); Style.ColumnLimit = 60; // To make writing tests easier. EXPECT_EQ("aaa: 100\n" - "##this is a double-hash comment.\n" + "## this is a double-hash comment.\n" "bb: 100\n" "## another double-hash comment.\n" "### a triple-hash comment\n" "cc: 200\n" + "### another triple-hash comment\n" "#### a quadriple-hash comment\n" - "dd: 100\n", + "dd: 100\n" + "#### another quadriple-hash comment\n", format("aaa: 100\n" "##this is a double-hash comment.\n" "bb: 100\n" "## another double-hash comment.\n" - "### a triple-hash comment\n" + "###a triple-hash comment\n" "cc: 200\n" - "#### a quadriple-hash comment\n" - "dd: 100\n", + "### another triple-hash comment\n" + "####a quadriple-hash comment\n" + "dd: 100\n" + "#### another quadriple-hash comment\n", Style)); }