summaryrefslogtreecommitdiff
path: root/clang/unittests/Format/FormatTestProto.cpp
AgeCommit message (Collapse)Author
2024-10-07[clang-format] Don't insert spaces after keywords in protobuf field o… ↵Owen Pan
(#111229) …ptions Fixes #54848.
2024-09-17[clang-format[NFC] Clean up FormatTestBase and Proto/TextProto tests (#108334)Owen Pan
2024-05-20[clang-format][NFC] Remove redundnat llvm::, clang::, etc.Owen Pan
2023-10-27[clang-format][NFC] Remove more extraneous newlines in unit testsOwen Pan
Also removed a duplicate test case.
2023-01-16Fix format for `case` in .proto filesMatt Kulukundis
Fix format for `case` in .proto files Reviewed By: krasimir, echristo Differential Revision: https://reviews.llvm.org/D141547
2020-05-02[clang-format] NFC - clang-format the FormatTestsmydeveloperday
Summary: Ensure the clang-format unit tests are themselves clang-formatted Having areas of the llvm code which are clang-format clean, give us more areas to run new clang-format binaries on ensuring we haven't broken anything. It seems to me we SHOULD have this clang-formatted at a minimum, otherwise how can we expect others to use clang-format if we "don't eat our own dogfood", also if the tests are dependent on the formatting of the code then that would also be bad! Reviewed By: sammccall Subscribers: cfe-commits Tags: #clang, #clang-format Differential Revision: https://reviews.llvm.org/D79204
2019-05-10Revert "Revert "[clang-format] Keep protobuf "package" statement on one line""Krasimir Georgiev
Summary: Top-level "package" and "import" statements should generally be kept on one line, for all languages. ---- This reverts commit rL356912. The regression from rL356835 was fixed via rC358275. Reviewers: krasimir, sammccall, MyDeveloperDay, xinz, dchai, klimek Reviewed By: krasimir, xinz, dchai Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60661 llvm-svn: 360411
2019-04-12[clang-format] Use SpacesBeforeTrailingComments for "option" directiveKrasimir Georgiev
Summary: AnnotatingParser::next() is needed to implicitly set TT_BlockComment versus TT_LineComment. On most other paths through AnnotatingParser::parseLine(), all tokens are consumed to achieve that. This change updates one place where this wasn't done. Contributed by @dchai! Reviewers: krasimir Reviewed By: krasimir Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60541 llvm-svn: 358275
2019-03-25Revert "[clang-format] Keep protobuf "package" statement on one line"Haojian Wu
This reverts commit r356835. This patch causes a regression, see the test below: verifyFormat("// Detached comment\n\n" "// Leading comment\n" "syntax = \"proto2\"; // trailing comment\n\n" "// in foo.bar package\n" "package foo.bar; // foo.bar package\n"); llvm-svn: 356912
2019-03-23[clang-format] Keep protobuf "package" statement on one linePaul Hoad
Summary: Top-level "package" and "import" statements should generally be kept on one line, for all languages. Reviewers: sammccall, krasimir, MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: MyDeveloperDay, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59627 Patch By: dchai (Donald Chai) llvm-svn: 356835
2019-03-23[clang-format] correctly format protobuf fields named "enum".Paul Hoad
Summary: Similar to TypeScript, "enum" is not a reserved word. Reviewers: krasimir, MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: MyDeveloperDay, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D59629 Patch by: dchai (Donald Chai) llvm-svn: 356833
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-08-15clang-format: Change Google style wrt. the formatting of empty messages.Daniel Jasper
Before: message Empty { } After: message Empty {} llvm-svn: 339803
2018-06-12[clang-format] Discourage breaks in submessage entries, hard ruleKrasimir Georgiev
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
2018-06-11[clang-format] text protos: put entries on separate lines if there is a ↵Krasimir Georgiev
submessage Summary: This patch updates clang-format text protos to put entries of a submessage into separate lines if the submessage contains at least two entries and contains at least one submessage entry. For example, the entries here are kept on separate lines even if putting them on a single line would be under the column limit: ``` message: { entry: 1 submessage: { key: value } } ``` Messages containing a single submessage or several scalar entries can still be put on one line if they fit: ``` message { submessage { key: value } } message { x: 1 y: 2 z: 3 } ``` Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D46757 llvm-svn: 334401
2018-05-15[clang] Update uses of DEBUG macro to LLVM_DEBUG.Nicola Zaghen
The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM Explicitly avoided changing the strings in the clang-format tests. Differential Revision: https://reviews.llvm.org/D44975 llvm-svn: 332350
2018-05-09[clang-format] Respect BreakBeforeClosingBrace while calculating lengthKrasimir Georgiev
Summary: This patch makes `getLengthToMatchingParen` respect the `BreakBeforeClosingBrace` ParenState for matching scope closers. In order to distinguish between paren states introduced by real vs. fake parens, I've added the token opening the ParensState to that struct. Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D46519 llvm-svn: 331857
2018-04-23Revert "[clang-format] Improve Incomplete detection for (text) protos"Krasimir Georgiev
This reverts commit r330016. The incomplete detection has too many false positives, picking up typos for hard failures and refusing to format anything in that case. llvm-svn: 330569
2018-04-13[clang-format] Improve Incomplete detection for (text) protosKrasimir Georgiev
Summary: This patch improves detection of incomplete code for protos and text protos. This is especially important for text protos in raw string literals, since they might be partial strings concatenated, and we'd like to disable formatting in these cases. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D44203 llvm-svn: 330016
2018-04-05[clang-format] Preserve spaces before a percent in (text) protosKrasimir Georgiev
This makes sure that we do not change the meaning of pieces of text with format specifiers. llvm-svn: 329263
2018-04-04[clang-format] In tests, expected code should be format-stableMark Zeren
Summary: Extend various verifyFormat helper functions to check that the expected text is "stable". This provides some protection against bugs where formatting results are ocilating between two forms, or continually change in some other way. Testing Done: * Ran unit tests. * Reproduced a known instability in preprocessor indentation which was caught by this new check. Reviewers: krasimir Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D42034 llvm-svn: 329231
2018-03-12clang-format: Properly handle implicit string concatenation in text protosDaniel Jasper
Three issues to fix: - char_constants weren't properly treated as string literals - Prevening the break after "label: " does not make sense in concunction with AlwaysBreakBeforeMultilineStrings. It leads to situations where clang-format just cannot find a viable format (it must break and yet it must not break). - AlwaysBreakBeforeMultilineStrings should not be on for LK_TextProto in Google style. llvm-svn: 327255
2018-02-27[clang-format] Format operator key in protosKrasimir Georgiev
Summary: This fixes a glitch where ``operator: value`` in a text proto would mess up the underlying formatting since it gets parsed as a kw_operator instead of an identifier. Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D43830 llvm-svn: 326227
2018-02-19[clang-format] Fixup a case of text proto message attributesKrasimir Georgiev
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 llvm-svn: 325509
2018-02-15[clang-format] Support repeated field lists in protosKrasimir Georgiev
Summary: This patch adds support for list initialization of proto repeated fields: ``` keys: [1, 2, 3] ``` Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D43298 llvm-svn: 325252
2018-02-14[clang-format] Recognize percents as format specifiers in protosKrasimir Georgiev
Summary: Frequently, a percent in protos denotes a formatting specifier for string replacement. Thus it is desirable to keep the percent together with what follows after it. Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D43294 llvm-svn: 325159
2018-02-13[clang-format] Support text proto extensionsKrasimir Georgiev
Summary: This adds support for text proto extensions, like: ``` msg { [type.type/ext] { key: value } } ``` Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D43180 llvm-svn: 324995
2018-02-08[clang-format] Do not break before long string literals in protosKrasimir Georgiev
Summary: This patch is a follow-up to r323319 (which disables string literal breaking for text protos) and it disables breaking before long string literals. For example this: ``` keyyyyy: "long string literal" ``` used to get broken into: ``` keyyyyy: "long string literal" ``` While at it, I also enabled it for LK_Proto and fixed a bug in the mustBreak code. Reviewers: djasper, sammccall Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D42957 llvm-svn: 324591
2018-02-06[clang-format] Adds space around angle brackets in text protosKrasimir Georgiev
Summary: This patch adds spaces around angle brackets in text proto Google style. Previously these were detected as template openers and closers, which happened to have the expected effect. Now we detect them as scope openers and closers similarly to the way braces are handled in this context. Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D42727 llvm-svn: 324337
2018-01-31[clang-format] Adds space around braces in text protosKrasimir Georgiev
Summary: This patch modifies the text proto Google style to add spaces around braces. I investigated using something different than Cpp11BracedListStyle, but it turns out it's what we want and also the java and js styles also depend on that. Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D42685 llvm-svn: 323860
2017-08-03[clang-format] Fix indent of 'key <...>' and 'key {...}' in text protosKrasimir Georgiev
Summary: This patch fixes the indentation of the code pattern `key <...>`and `key {...}` in text protos. Previously, such line would be alinged depending on the column of the previous colon, which usually indents too much. I'm gonna go ahead and commit this since it's a straightforward bugfix. Reviewers: djasper, klimek Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D36143 llvm-svn: 309941
2017-08-03[clang-format] Fix parsing of <>-style proto optionsKrasimir Georgiev
Summary: This patch fixes the parsing of proto option fields like `option op = <...>`. Previously the parser did not enter the right code path inside the angle braces, causing the contents to be split into several unwrapped lines inside. I'll just go ahead and commit this since it's a straightforward bugfix. Reviewers: djasper, klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D36217 llvm-svn: 309937
2017-07-06[clang-format] Add space between a message field key and the opening bracket ↵Krasimir Georgiev
in proto messages Summary: This patch updates the formatting of message fields of type `a{...}` to `a {...}` for proto messages. Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D35015 llvm-svn: 307261
2017-06-29[clang-format] Fix parsing of msg{field}-style proto optionsKrasimir Georgiev
Summary: This patch makes the `{` in `msg_field{field: OK}` in a proto option scope be treated as an assignment operator. Previosly the added test case was formatted as: ``` option (MyProto.options) = { field_a: OK field_b{field_c: OK} field_d: OKOKOK field_e: OK } ``` Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D34749 llvm-svn: 306672
2017-06-27[clang-format] Support <>-style proto message fieldsKrasimir Georgiev
Summary: This patch adds support for <>-style proto message fields inside proto options. Previously these were wrongly treated as binary operators and as such were working only by chance for a limited number of cases. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D34621 llvm-svn: 306406
2017-06-27[clang-format] Add a test for associative map proto buffer fieldsKrasimir Georgiev
Summary: The test suite was missing a test about associative maps: https://developers.google.com/protocol-buffers/docs/proto3#maps Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D34623 llvm-svn: 306386
2017-03-14clang-format: Make it very slighly more expensive to wrap between "= {".Daniel Jasper
This prevents unwanted fallout from r296664. Specifically in proto formatting, this changed: optional Aaaaaaaa aaaaaaaa = 12 [ (aaa) = aaaa, (bbbbbbbbbbbbbbbbbbbbbbbbbb) = { aaaaaaaaaaaaaaaaa: true, aaaaaaaaaaaaaaaa: true } ]; Into: optional Aaaaaaaa aaaaaaaa = 12 [ (aaa) = aaaa, (bbbbbbbbbbbbbbbbbbbbbbbbbb) = {aaaaaaaaaaaaaaaaa: true, aaaaaaaaaaaaaaaa: true} ]; Which is considered less readable. Generally, it seems preferable to format such dict literals as blocks rather than contract them to one line. llvm-svn: 297696
2017-02-03clang-format: [Proto] Also supports implicit string literal concatenationDaniel Jasper
llvm-svn: 293995
2016-07-11Make tooling::applyAllReplacements return llvm::Expected<string> instead of ↵Eric Liu
empty string to indicate potential error. Summary: return llvm::Expected<> to carry error status and error information. This is the first step towards introducing "Error" into tooling::Replacements. Reviewers: djasper, klimek Subscribers: ioeric, klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D21601 llvm-svn: 275062
2016-06-23clang-format: [Proto] Use more compact format for text-formatted optionsDaniel Jasper
Before: enum Type { UNKNOWN = 0 [(some_options) = { a: aa, b: bb }]; }; After: enum Type { UNKNOWN = 0 [(some_options) = {a: aa, b: bb}]; }; llvm-svn: 273553
2016-06-20clang-format: [Proto] Fix "import public" after r273179.Daniel Jasper
llvm-svn: 273196
2016-06-20clang-format: [Proto] Don't do bad things if imports are missing ;.Daniel Jasper
llvm-svn: 273179
2016-01-04clang-format: [Proto] Basic support for options with <> for repeated fields.Daniel Jasper
llvm-svn: 256737
2016-01-04clang-format: [Proto] Improve wrapping of message field attributes.Daniel Jasper
Before: optional AAA aaa = 1 [foo = { key: "a" // }, bar = { key: "a" // }]; After: optional AAA aaa = 1 [ foo = { key: "a" // }, bar = { key: "a" // } ]; llvm-svn: 256736
2015-11-20clang-format: [Proto] Support extending message.Daniel Jasper
Before: extend.foo.Bar { } After: extend .foo.Bar { } llvm-svn: 253667
2015-07-16clang-format: [Proto] Handle enum bodies differently.Daniel Jasper
In proto, enum constants can contain complex options and should be handled more like individual declarations. Before: enum Type { UNKNOWN = 0 [(some_options) = { a: aa, b: bb }]; }; After: enum Type { UNKNOWN = 0 [(some_options) = { a: aa, b: bb }]; }; llvm-svn: 242404
2015-06-25clang-format: [Proto] Don't treat "operator" as keyword.Daniel Jasper
Before: optional string operator= 1; After: optional string operator = 1; llvm-svn: 240624
2015-06-22Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko
llvm-svn: 240353
2015-06-22Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko
The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270
2015-04-23clang-format: [Proto] Don't linewrap top-level options.Daniel Jasper
They are very similar to import statements. llvm-svn: 235582