aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Format
diff options
context:
space:
mode:
authorBackl1ght <backlight.zzk@gmail.com>2023-10-25 05:10:35 -0700
committerOwen Pan <owenpiano@gmail.com>2023-10-25 05:13:50 -0700
commit69209e30a7168b0493d8fb34989ddccd8c574670 (patch)
treeec02129fa944c725cc2e39012ef781e66851c410 /clang/unittests/Format
parent66f4a1399d7de3d38312a5b251d4f8acd75237ca (diff)
downloadllvm-69209e30a7168b0493d8fb34989ddccd8c574670.zip
llvm-69209e30a7168b0493d8fb34989ddccd8c574670.tar.gz
llvm-69209e30a7168b0493d8fb34989ddccd8c574670.tar.bz2
[clang-format] AllowShortCompoundRequirementOnASingleLine
clang-format brace wrapping did not take requires into consideration, compound requirements will be affected by BraceWrapping.AfterFunction. Closes #59412. Differential Revision: https://reviews.llvm.org/D139834
Diffstat (limited to 'clang/unittests/Format')
-rw-r--r--clang/unittests/Format/ConfigParseTest.cpp1
-rw-r--r--clang/unittests/Format/FormatTest.cpp34
2 files changed, 35 insertions, 0 deletions
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index ba79c8d..f90ed17 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -154,6 +154,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowAllArgumentsOnNextLine);
CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
+ CHECK_PARSE_BOOL(AllowShortCompoundRequirementOnASingleLine);
CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
CHECK_PARSE_BOOL(BinPackArguments);
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 8329daa..b2d84f2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2767,6 +2767,40 @@ TEST_F(FormatTest, ShortEnums) {
Style);
}
+TEST_F(FormatTest, ShortCompoundRequirement) {
+ FormatStyle Style = getLLVMStyle();
+ EXPECT_TRUE(Style.AllowShortCompoundRequirementOnASingleLine);
+ verifyFormat("template <typename T>\n"
+ "concept c = requires(T x) {\n"
+ " { x + 1 } -> std::same_as<int>;\n"
+ "};",
+ Style);
+ verifyFormat("template <typename T>\n"
+ "concept c = requires(T x) {\n"
+ " { x + 1 } -> std::same_as<int>;\n"
+ " { x + 2 } -> std::same_as<int>;\n"
+ "};",
+ Style);
+ Style.AllowShortCompoundRequirementOnASingleLine = false;
+ verifyFormat("template <typename T>\n"
+ "concept c = requires(T x) {\n"
+ " {\n"
+ " x + 1\n"
+ " } -> std::same_as<int>;\n"
+ "};",
+ Style);
+ verifyFormat("template <typename T>\n"
+ "concept c = requires(T x) {\n"
+ " {\n"
+ " x + 1\n"
+ " } -> std::same_as<int>;\n"
+ " {\n"
+ " x + 2\n"
+ " } -> std::same_as<int>;\n"
+ "};",
+ Style);
+}
+
TEST_F(FormatTest, ShortCaseLabels) {
FormatStyle Style = getLLVMStyle();
Style.AllowShortCaseLabelsOnASingleLine = true;