aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2023-11-09 23:01:48 -0800
committerGitHub <noreply@github.com>2023-11-09 23:01:48 -0800
commit5c36f4332d93c6f9bd9b01a34149a635e07a00d3 (patch)
treef0605ef8b8800f816791d6e7fd4aa40e30a2a1f8 /clang/unittests/Format/FormatTest.cpp
parentfdbff88196b54cea12deb1fae978277066dffd1e (diff)
downloadllvm-5c36f4332d93c6f9bd9b01a34149a635e07a00d3.zip
llvm-5c36f4332d93c6f9bd9b01a34149a635e07a00d3.tar.gz
llvm-5c36f4332d93c6f9bd9b01a34149a635e07a00d3.tar.bz2
[clang-format] Handle variable declarations in BreakAfterAttributes (#71755)
Also cleaned up some old test cases. Fixes #71563.
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp41
1 files changed, 28 insertions, 13 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 80903e7..bb01f57d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8479,18 +8479,25 @@ TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {
" aaaaaaaaaaaaaaaaaaaaaaaaa));");
verifyFormat("bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
" __attribute__((unused));");
- verifyGoogleFormat(
+
+ Style = getGoogleStyle();
+ Style.AttributeMacros.push_back("GUARDED_BY");
+ verifyFormat(
"bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
- " GUARDED_BY(aaaaaaaaaaaa);");
- verifyGoogleFormat(
+ " GUARDED_BY(aaaaaaaaaaaa);",
+ Style);
+ verifyFormat(
"bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
- " GUARDED_BY(aaaaaaaaaaaa);");
- verifyGoogleFormat(
+ " GUARDED_BY(aaaaaaaaaaaa);",
+ Style);
+ verifyFormat(
"bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY(aaaaaaaaaaaa) =\n"
- " aaaaaaaa::aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;");
- verifyGoogleFormat(
+ " aaaaaaaa::aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;",
+ Style);
+ verifyFormat(
"bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY(aaaaaaaaaaaa) =\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaa;");
+ " aaaaaaaaaaaaaaaaaaaaaaaaa;",
+ Style);
}
TEST_F(FormatTest, FunctionAnnotations) {
@@ -26192,9 +26199,10 @@ TEST_F(FormatTest, RemoveSemicolon) {
}
TEST_F(FormatTest, BreakAfterAttributes) {
- FormatStyle Style = getLLVMStyle();
-
- constexpr StringRef Code("[[nodiscard]] inline int f(int &i);\n"
+ constexpr StringRef Code("[[maybe_unused]] const int i;\n"
+ "[[foo([[]])]] [[maybe_unused]]\n"
+ "int j;\n"
+ "[[nodiscard]] inline int f(int &i);\n"
"[[foo([[]])]] [[nodiscard]]\n"
"int g(int &i);\n"
"[[nodiscard]]\n"
@@ -26207,11 +26215,14 @@ TEST_F(FormatTest, BreakAfterAttributes) {
" return 1;\n"
"}");
+ FormatStyle Style = getLLVMStyle();
EXPECT_EQ(Style.BreakAfterAttributes, FormatStyle::ABS_Leave);
verifyNoChange(Code, Style);
Style.BreakAfterAttributes = FormatStyle::ABS_Never;
- verifyFormat("[[nodiscard]] inline int f(int &i);\n"
+ verifyFormat("[[maybe_unused]] const int i;\n"
+ "[[foo([[]])]] [[maybe_unused]] int j;\n"
+ "[[nodiscard]] inline int f(int &i);\n"
"[[foo([[]])]] [[nodiscard]] int g(int &i);\n"
"[[nodiscard]] inline int f(int &i) {\n"
" i = 1;\n"
@@ -26224,7 +26235,11 @@ TEST_F(FormatTest, BreakAfterAttributes) {
Code, Style);
Style.BreakAfterAttributes = FormatStyle::ABS_Always;
- verifyFormat("[[nodiscard]]\n"
+ verifyFormat("[[maybe_unused]]\n"
+ "const int i;\n"
+ "[[foo([[]])]] [[maybe_unused]]\n"
+ "int j;\n"
+ "[[nodiscard]]\n"
"inline int f(int &i);\n"
"[[foo([[]])]] [[nodiscard]]\n"
"int g(int &i);\n"