summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTestTextProto.cpp
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2018-06-12 17:26:31 +0000
committerKrasimir Georgiev <krasimir@google.com>2018-06-12 17:26:31 +0000
commit70a9e47f530089261061d5bb3192f43aad28250a (patch)
tree8c2a26e442840feffb1ac6d714f534a616b2296a /clang/unittests/Format/FormatTestTextProto.cpp
parent0e33a0cd58ac7e7764943b5b478ea6812d890476 (diff)
downloadbcm5719-llvm-70a9e47f530089261061d5bb3192f43aad28250a.tar.gz
bcm5719-llvm-70a9e47f530089261061d5bb3192f43aad28250a.zip
[clang-format] Discourage breaks in submessage entries, hard rule
Summary: Currently clang-format allows this for text protos: ``` submessage: { key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' } ``` when it is under the column limit and when putting it all on one line exceeds the column limit. This is not a very intuitive formatting, so I'd prefer having ``` submessage: { key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' } ``` instead, even if it takes one line more. This patch prevents clang-format from inserting a break between `: {` and similar cases. Reviewers: djasper, sammccall Reviewed By: sammccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48063 llvm-svn: 334517
Diffstat (limited to 'clang/unittests/Format/FormatTestTextProto.cpp')
-rw-r--r--clang/unittests/Format/FormatTestTextProto.cpp34
1 files changed, 32 insertions, 2 deletions
diff --git a/clang/unittests/Format/FormatTestTextProto.cpp b/clang/unittests/Format/FormatTestTextProto.cpp
index d62975feb44..8ef4bf9a40a 100644
--- a/clang/unittests/Format/FormatTestTextProto.cpp
+++ b/clang/unittests/Format/FormatTestTextProto.cpp
@@ -485,8 +485,15 @@ TEST_F(FormatTestTextProto, FormatsRepeatedListInitializers) {
verifyFormat("keys: []");
verifyFormat("keys: [ 1 ]");
verifyFormat("keys: [ 'ala', 'bala' ]");
- verifyFormat("keys:\n"
- " [ 'ala', 'bala', 'porto', 'kala', 'too', 'long', 'ng' ]");
+ verifyFormat("keys: [\n"
+ " 'ala',\n"
+ " 'bala',\n"
+ " 'porto',\n"
+ " 'kala',\n"
+ " 'too',\n"
+ " 'long',\n"
+ " 'ng'\n"
+ "]");
verifyFormat("key: item\n"
"keys: [\n"
" 'ala',\n"
@@ -670,5 +677,28 @@ TEST_F(FormatTestTextProto, BreaksEntriesOfSubmessagesContainingSubmessages) {
"}");
}
+TEST_F(FormatTestTextProto, PreventBreaksBetweenKeyAndSubmessages) {
+ verifyFormat("submessage: {\n"
+ " key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\n"
+ "}");
+ verifyFormat("submessage {\n"
+ " key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\n"
+ "}");
+ verifyFormat("submessage: <\n"
+ " key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\n"
+ ">");
+ verifyFormat("submessage <\n"
+ " key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\n"
+ ">");
+ verifyFormat("repeatedd: [\n"
+ " 'eyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\n"
+ "]");
+ // "{" is going over the column limit.
+ verifyFormat(
+ "submessageeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee: {\n"
+ " key: 'aaaaa'\n"
+ "}");
+}
+
} // end namespace tooling
} // end namespace clang
OpenPOWER on IntegriCloud