From: Krasimir Georgiev Date: Mon, 19 Feb 2018 15:31:25 +0000 (+0000) Subject: [clang-format] Fixup a case of text proto message attributes X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4337e351aaa5407ba3cd73782ce2892a8625028e;p=clang [clang-format] Fixup a case of text proto message attributes Summary: This patch fixes a case where a proto message attribute is wrongly identified as an text proto extension. Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D43465 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325509 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 75a3fdce80..f56230ee88 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -375,6 +375,10 @@ private: // (aaa) = aaa // ]; // + // extensions 123 [ + // (aaa) = aaa + // ]; + // // or text proto extensions (in options): // // option (Aaa.options) = { @@ -394,6 +398,8 @@ private: Left->Type = TT_ArrayInitializerLSquare; if (!Left->endsSequence(tok::l_square, tok::numeric_constant, tok::equal) && + !Left->endsSequence(tok::l_square, tok::numeric_constant, + tok::identifier) && !Left->endsSequence(tok::l_square, tok::colon, TT_SelectorName)) { Left->Type = TT_ProtoExtensionLSquare; BindingIncrease = 10; diff --git a/unittests/Format/FormatTestProto.cpp b/unittests/Format/FormatTestProto.cpp index 4c61ec1398..1d6b7502e0 100644 --- a/unittests/Format/FormatTestProto.cpp +++ b/unittests/Format/FormatTestProto.cpp @@ -168,6 +168,16 @@ TEST_F(FormatTestProto, MessageFieldAttributes) { " aaaaaaaaaaaaaaaa: true\n" " }\n" "];"); + verifyFormat("extensions 20 [(proto2.type) = 'Aaaa.bbbb'];"); + verifyFormat("extensions 20\n" + " [(proto3.type) = 'Aaaa.bbbb', (aaa.Aaa) = 'aaa.bbb'];"); + verifyFormat("extensions 123 [\n" + " (aaa) = aaaa,\n" + " (bbbbbbbbbbbbbbbbbbbbbbbbbb) = {\n" + " aaaaaaaaaaaaaaaaa: true,\n" + " aaaaaaaaaaaaaaaa: true\n" + " }\n" + "];"); } TEST_F(FormatTestProto, DoesntWrapFileOptions) {