aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Format
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/Format')
-rw-r--r--clang/unittests/Format/ConfigParseTest.cpp66
-rw-r--r--clang/unittests/Format/FormatTest.cpp78
2 files changed, 112 insertions, 32 deletions
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index 0c9f68f..18ecba2 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -289,37 +289,43 @@ TEST(ConfigParseTest, ParsesConfiguration) {
#define CHECK_ALIGN_CONSECUTIVE(FIELD) \
do { \
Style.FIELD.Enabled = true; \
- CHECK_PARSE(#FIELD ": None", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \
- /*AcrossComments=*/false, /*AlignCompound=*/false, \
- /*PadOperators=*/true})); \
- CHECK_PARSE(#FIELD ": Consecutive", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
- /*AcrossComments=*/false, /*AlignCompound=*/false, \
- /*PadOperators=*/true})); \
- CHECK_PARSE(#FIELD ": AcrossEmptyLines", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
- /*AcrossComments=*/false, /*AlignCompound=*/false, \
- /*PadOperators=*/true})); \
- CHECK_PARSE(#FIELD ": AcrossEmptyLinesAndComments", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
- /*AcrossComments=*/true, /*AlignCompound=*/false, \
- /*PadOperators=*/true})); \
+ CHECK_PARSE( \
+ #FIELD ": None", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \
+ /*AcrossComments=*/false, /*AlignCompound=*/false, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
+ CHECK_PARSE( \
+ #FIELD ": Consecutive", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
+ /*AcrossComments=*/false, /*AlignCompound=*/false, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
+ CHECK_PARSE( \
+ #FIELD ": AcrossEmptyLines", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
+ /*AcrossComments=*/false, /*AlignCompound=*/false, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
+ CHECK_PARSE( \
+ #FIELD ": AcrossEmptyLinesAndComments", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
+ /*AcrossComments=*/true, /*AlignCompound=*/false, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
/* For backwards compability, false / true should still parse */ \
- CHECK_PARSE(#FIELD ": false", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \
- /*AcrossComments=*/false, /*AlignCompound=*/false, \
- /*PadOperators=*/true})); \
- CHECK_PARSE(#FIELD ": true", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
- /*AcrossComments=*/false, /*AlignCompound=*/false, \
- /*PadOperators=*/true})); \
+ CHECK_PARSE( \
+ #FIELD ": false", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \
+ /*AcrossComments=*/false, /*AlignCompound=*/false, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
+ CHECK_PARSE( \
+ #FIELD ": true", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
+ /*AcrossComments=*/false, /*AlignCompound=*/false, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
\
CHECK_PARSE_NESTED_BOOL(FIELD, Enabled); \
CHECK_PARSE_NESTED_BOOL(FIELD, AcrossEmptyLines); \
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index c346f38..9fd55db 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2046,13 +2046,26 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
Style);
Style.AlignConsecutiveDeclarations.Enabled = true;
+ Style.AlignConsecutiveDeclarations.AlignFunctionPointers = true;
verifyFormat("Const unsigned int *c;\n"
"const unsigned int *d;\n"
"Const unsigned int &e;\n"
"const unsigned int &f;\n"
+ "int *f1(int *a, int &b, int &&c);\n"
+ "double *(*f2)(int *a, double &&b);\n"
"const unsigned &&g;\n"
"Const unsigned h;",
Style);
+ Style.AlignConsecutiveDeclarations.AlignFunctionPointers = false;
+ verifyFormat("Const unsigned int *c;\n"
+ "const unsigned int *d;\n"
+ "Const unsigned int &e;\n"
+ "const unsigned int &f;\n"
+ "int *f1(int *a, int &b, int &&c);\n"
+ "double *(*f2)(int *a, double &&b);\n"
+ "const unsigned &&g;\n"
+ "Const unsigned h;",
+ Style);
Style.PointerAlignment = FormatStyle::PAS_Left;
Style.ReferenceAlignment = FormatStyle::RAS_Pointer;
@@ -2091,13 +2104,26 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
Style);
Style.AlignConsecutiveDeclarations.Enabled = true;
+ Style.AlignConsecutiveDeclarations.AlignFunctionPointers = true;
verifyFormat("Const unsigned int* c;\n"
"const unsigned int* d;\n"
"Const unsigned int& e;\n"
"const unsigned int& f;\n"
+ "int* f1(int* a, int& b, int&& c);\n"
+ "double* (*f2)(int* a, double&& b);\n"
"const unsigned&& g;\n"
"Const unsigned h;",
Style);
+ Style.AlignConsecutiveDeclarations.AlignFunctionPointers = false;
+ verifyFormat("Const unsigned int* c;\n"
+ "const unsigned int* d;\n"
+ "Const unsigned int& e;\n"
+ "const unsigned int& f;\n"
+ "int* f1(int* a, int& b, int&& c);\n"
+ "double* (*f2)(int* a, double&& b);\n"
+ "const unsigned&& g;\n"
+ "Const unsigned h;",
+ Style);
Style.PointerAlignment = FormatStyle::PAS_Right;
Style.ReferenceAlignment = FormatStyle::RAS_Left;
@@ -2116,13 +2142,26 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
verifyFormat("for (int a = 0, b++; const Foo *c : {1, 2, 3})", Style);
Style.AlignConsecutiveDeclarations.Enabled = true;
+ Style.AlignConsecutiveDeclarations.AlignFunctionPointers = true;
verifyFormat("Const unsigned int *c;\n"
"const unsigned int *d;\n"
"Const unsigned int& e;\n"
"const unsigned int& f;\n"
- "const unsigned g;\n"
+ "int *f1(int *a, int& b, int&& c);\n"
+ "double *(*f2)(int *a, double&& b);\n"
+ "const unsigned&& g;\n"
"Const unsigned h;",
Style);
+ Style.AlignConsecutiveDeclarations.AlignFunctionPointers = false;
+ verifyFormat("Const unsigned int *c;\n"
+ "const unsigned int *d;\n"
+ "Const unsigned int& e;\n"
+ "const unsigned int& f;\n"
+ "int *f1(int *a, int& b, int&& c);\n"
+ "double *(*f2)(int *a, double&& b);\n"
+ "const unsigned&& g;\n"
+ "Const unsigned h;",
+ Style);
Style.PointerAlignment = FormatStyle::PAS_Left;
Style.ReferenceAlignment = FormatStyle::RAS_Middle;
@@ -2156,13 +2195,26 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
Style);
Style.AlignConsecutiveDeclarations.Enabled = true;
+ Style.AlignConsecutiveDeclarations.AlignFunctionPointers = true;
verifyFormat("Const unsigned int* c;\n"
"const unsigned int* d;\n"
"Const unsigned int & e;\n"
"const unsigned int & f;\n"
+ "int* f1(int* a, int & b, int && c);\n"
+ "double* (*f2)(int* a, double && b);\n"
"const unsigned && g;\n"
"Const unsigned h;",
Style);
+ Style.AlignConsecutiveDeclarations.AlignFunctionPointers = false;
+ verifyFormat("Const unsigned int* c;\n"
+ "const unsigned int* d;\n"
+ "Const unsigned int & e;\n"
+ "const unsigned int & f;\n"
+ "int* f1(int* a, int & b, int && c);\n"
+ "double* (*f2)(int* a, double && b);\n"
+ "const unsigned && g;\n"
+ "Const unsigned h;",
+ Style);
Style.PointerAlignment = FormatStyle::PAS_Middle;
Style.ReferenceAlignment = FormatStyle::RAS_Right;
@@ -2181,13 +2233,26 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
verifyFormat("for (int a = 0, b++; const Foo * c : {1, 2, 3})", Style);
Style.AlignConsecutiveDeclarations.Enabled = true;
+ Style.AlignConsecutiveDeclarations.AlignFunctionPointers = true;
verifyFormat("Const unsigned int * c;\n"
"const unsigned int * d;\n"
"Const unsigned int &e;\n"
"const unsigned int &f;\n"
+ "int * f1(int * a, int &b, int &&c);\n"
+ "double * (*f2)(int * a, double &&b);\n"
"const unsigned &&g;\n"
"Const unsigned h;",
Style);
+ Style.AlignConsecutiveDeclarations.AlignFunctionPointers = false;
+ verifyFormat("Const unsigned int * c;\n"
+ "const unsigned int * d;\n"
+ "Const unsigned int &e;\n"
+ "const unsigned int &f;\n"
+ "int * f1(int * a, int &b, int &&c);\n"
+ "double * (*f2)(int * a, double &&b);\n"
+ "const unsigned &&g;\n"
+ "Const unsigned h;",
+ Style);
// FIXME: we don't handle this yet, so output may be arbitrary until it's
// specifically handled
@@ -18933,6 +18998,15 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
" \"bb\"};\n"
"int bbbbbbb = 0;",
Alignment);
+ // http://llvm.org/PR68079
+ verifyFormat("using Fn = int (A::*)();\n"
+ "using RFn = int (A::*)() &;\n"
+ "using RRFn = int (A::*)() &&;",
+ Alignment);
+ verifyFormat("using Fn = int (A::*)();\n"
+ "using RFn = int *(A::*)() &;\n"
+ "using RRFn = double (A::*)() &&;",
+ Alignment);
// PAS_Right
verifyFormat("void SomeFunction(int parameter = 0) {\n"
@@ -19585,7 +19659,7 @@ TEST_F(FormatTest, AlignWithLineBreaks) {
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
/*AcrossComments=*/false, /*AlignCompound=*/false,
- /*PadOperators=*/true}));
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
EXPECT_EQ(Style.AlignConsecutiveDeclarations,
FormatStyle::AlignConsecutiveStyle({}));
verifyFormat("void foo() {\n"