diff options
author | Gedare Bloom <gedare@rtems.org> | 2025-01-27 22:40:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-27 21:40:17 -0800 |
commit | d50ebd47ae57812e5d2db1e3d3157f26b8d9d159 (patch) | |
tree | 6336bbc85e6aac581fca26c5116cb93f01f65f14 /clang/unittests/Format | |
parent | 3a439e2caf0bb545ee451df1de5b02ea068140f7 (diff) | |
download | llvm-d50ebd47ae57812e5d2db1e3d3157f26b8d9d159.zip llvm-d50ebd47ae57812e5d2db1e3d3157f26b8d9d159.tar.gz llvm-d50ebd47ae57812e5d2db1e3d3157f26b8d9d159.tar.bz2 |
[clang-format] Add style option `PenaltyBreakBeforeMemberAccess` (#118409)
The penalty for breaking before a member access is hard-coded to 150.
Add a configuration option to allow setting it.
---------
Co-authored-by: Owen Pan <owenpiano@gmail.com>
Diffstat (limited to 'clang/unittests/Format')
-rw-r--r-- | clang/unittests/Format/ConfigParseTest.cpp | 2 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 18 |
2 files changed, 20 insertions, 0 deletions
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp index 9746aa3..1078844 100644 --- a/clang/unittests/Format/ConfigParseTest.cpp +++ b/clang/unittests/Format/ConfigParseTest.cpp @@ -266,6 +266,8 @@ TEST(ConfigParseTest, ParsesConfiguration) { CHECK_PARSE("PenaltyBreakAssignment: 1234", PenaltyBreakAssignment, 1234u); CHECK_PARSE("PenaltyBreakBeforeFirstCallParameter: 1234", PenaltyBreakBeforeFirstCallParameter, 1234u); + CHECK_PARSE("PenaltyBreakBeforeMemberAccess: 1234", + PenaltyBreakBeforeMemberAccess, 1234u); CHECK_PARSE("PenaltyBreakTemplateDeclaration: 1234", PenaltyBreakTemplateDeclaration, 1234u); CHECK_PARSE("PenaltyBreakOpenParenthesis: 1234", PenaltyBreakOpenParenthesis, diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 2654615..57f1222 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -22365,6 +22365,24 @@ TEST_F(FormatTest, BreakPenaltyAfterForLoopLParen) { Style); } +TEST_F(FormatTest, BreakPenaltyBeforeMemberAccess) { + auto Style = getLLVMStyle(); + EXPECT_EQ(Style.PenaltyBreakBeforeMemberAccess, 150u); + + Style.ColumnLimit = 60; + Style.PenaltyBreakBeforeMemberAccess = 110; + verifyFormat("aaaaaaaa.aaaaaaaa.bbbbbbbb()\n" + " .ccccccccccccccccccccc(dddddddd);\n" + "aaaaaaaa.aaaaaaaa\n" + " .bbbbbbbb(cccccccccccccccccccccccccccccccc);", + Style); + + Style.ColumnLimit = 13; + verifyFormat("foo->bar\n" + " .b(a);", + Style); +} + TEST_F(FormatTest, BreakPenaltyScopeResolution) { FormatStyle Style = getLLVMStyle(); Style.ColumnLimit = 20; |