[clang-format] Add regression tests for function ref qualifiers on operator definition. NFC.

Fixes https://github.com/llvm/llvm-project/issues/54374.
This commit is contained in:
Marek Kurdej 2022-03-15 12:00:37 +01:00
parent 5c4d64eb0d
commit e60defb931
2 changed files with 42 additions and 0 deletions

View File

@ -9889,6 +9889,14 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
verifyFormat("template <typename T>\n"
"void F(T) && = delete;",
getGoogleStyle());
verifyFormat("template <typename T> void operator=(T) &;");
verifyFormat("template <typename T> void operator=(T) const &;");
verifyFormat("template <typename T> void operator=(T) &noexcept;");
verifyFormat("template <typename T> void operator=(T) & = default;");
verifyFormat("template <typename T> void operator=(T) &&;");
verifyFormat("template <typename T> void operator=(T) && = delete;");
verifyFormat("template <typename T> void operator=(T) & {}");
verifyFormat("template <typename T> void operator=(T) && {}");
FormatStyle AlignLeft = getLLVMStyle();
AlignLeft.PointerAlignment = FormatStyle::PAS_Left;
@ -9909,6 +9917,14 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
verifyFormat("void Fn(T const volatile&&) const volatile&&;", AlignLeft);
verifyFormat("void Fn(T const volatile&&) const volatile&& noexcept;",
AlignLeft);
verifyFormat("template <typename T> void operator=(T) &;", AlignLeft);
verifyFormat("template <typename T> void operator=(T) const&;", AlignLeft);
verifyFormat("template <typename T> void operator=(T) & noexcept;", AlignLeft);
verifyFormat("template <typename T> void operator=(T) & = default;", AlignLeft);
verifyFormat("template <typename T> void operator=(T) &&;", AlignLeft);
verifyFormat("template <typename T> void operator=(T) && = delete;", AlignLeft);
verifyFormat("template <typename T> void operator=(T) & {}", AlignLeft);
verifyFormat("template <typename T> void operator=(T) && {}", AlignLeft);
FormatStyle AlignMiddle = getLLVMStyle();
AlignMiddle.PointerAlignment = FormatStyle::PAS_Middle;
@ -9930,6 +9946,14 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
verifyFormat("void Fn(T const volatile &&) const volatile &&;", AlignMiddle);
verifyFormat("void Fn(T const volatile &&) const volatile && noexcept;",
AlignMiddle);
verifyFormat("template <typename T> void operator=(T) &;", AlignMiddle);
verifyFormat("template <typename T> void operator=(T) const &;", AlignMiddle);
verifyFormat("template <typename T> void operator=(T) & noexcept;", AlignMiddle);
verifyFormat("template <typename T> void operator=(T) & = default;", AlignMiddle);
verifyFormat("template <typename T> void operator=(T) &&;", AlignMiddle);
verifyFormat("template <typename T> void operator=(T) && = delete;", AlignMiddle);
verifyFormat("template <typename T> void operator=(T) & {}", AlignMiddle);
verifyFormat("template <typename T> void operator=(T) && {}", AlignMiddle);
FormatStyle Spaces = getLLVMStyle();
Spaces.SpacesInCStyleCastParentheses = true;

View File

@ -159,6 +159,24 @@ TEST_F(TokenAnnotatorTest, UnderstandsDelete) {
EXPECT_TOKEN(Tokens[7], tok::r_paren, TT_CastRParen);
}
TEST_F(TokenAnnotatorTest, UnderstandsFunctionRefQualifiers) {
auto Tokens = annotate("void f() &;");
EXPECT_EQ(Tokens.size(), 7u) << Tokens;
EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
Tokens = annotate("void operator=() &&;");
EXPECT_EQ(Tokens.size(), 8u) << Tokens;
EXPECT_TOKEN(Tokens[5], tok::ampamp, TT_PointerOrReference);
Tokens = annotate("template <typename T> void f() &;");
EXPECT_EQ(Tokens.size(), 12u) << Tokens;
EXPECT_TOKEN(Tokens[9], tok::amp, TT_PointerOrReference);
Tokens = annotate("template <typename T> void operator=() &;");
EXPECT_EQ(Tokens.size(), 13u) << Tokens;
EXPECT_TOKEN(Tokens[10], tok::amp, TT_PointerOrReference);
}
TEST_F(TokenAnnotatorTest, UnderstandsRequiresClausesAndConcepts) {
auto Tokens = annotate("template <typename T>\n"
"concept C = (Foo && Bar) && (Bar && Baz);");