rymiel updated this revision to Diff 506370. rymiel added a comment. Annotator tests (copied from format tests)
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D146284/new/ https://reviews.llvm.org/D146284 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Index: clang/unittests/Format/TokenAnnotatorTest.cpp =================================================================== --- clang/unittests/Format/TokenAnnotatorTest.cpp +++ clang/unittests/Format/TokenAnnotatorTest.cpp @@ -242,6 +242,17 @@ "}"); ASSERT_EQ(Tokens.size(), 12u) << Tokens; EXPECT_TOKEN(Tokens[7], tok::amp, TT_BinaryOperator); + + Tokens = + annotate("template <typename T> void swap() noexcept(Bar<T> && Foo<T>);"); + ASSERT_EQ(Tokens.size(), 23u) << Tokens; + EXPECT_TOKEN(Tokens[15], tok::ampamp, TT_BinaryOperator); + + Tokens = annotate("template <typename T> struct S {\n" + " explicit(Bar<T> && Foo<T>) S(const S &);\n" + "};"); + ASSERT_EQ(Tokens.size(), 30u) << Tokens; + EXPECT_TOKEN(Tokens[14], tok::ampamp, TT_BinaryOperator); } TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) { Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -11592,6 +11592,10 @@ verifyFormat("template <bool B, bool C> class A {\n" " static_assert(B && C, \"Something is wrong\");\n" "};"); + verifyFormat("template <typename T> void swap() noexcept(Bar<T> && Foo<T>);"); + verifyFormat("template <typename T> struct S {\n" + " explicit(Bar<T> && Foo<T>) S(const S &);\n" + "};"); verifyGoogleFormat("#define IF(a, b, c) if (a && (b == c))"); verifyGoogleFormat("#define WHILE(a, b, c) while (a && (b == c))"); verifyFormat("#define A(a, b) (a && b)"); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -318,9 +318,10 @@ // export type X = (...); Contexts.back().IsExpression = false; } else if (OpeningParen.Previous && - (OpeningParen.Previous->isOneOf(tok::kw_static_assert, - tok::kw_while, tok::l_paren, - tok::comma, TT_BinaryOperator) || + (OpeningParen.Previous->isOneOf( + tok::kw_static_assert, tok::kw_noexcept, tok::kw_explicit, + tok::kw_while, tok::l_paren, tok::comma, + TT_BinaryOperator) || OpeningParen.Previous->isIf())) { // static_assert, if and while usually contain expressions. Contexts.back().IsExpression = true;
Index: clang/unittests/Format/TokenAnnotatorTest.cpp =================================================================== --- clang/unittests/Format/TokenAnnotatorTest.cpp +++ clang/unittests/Format/TokenAnnotatorTest.cpp @@ -242,6 +242,17 @@ "}"); ASSERT_EQ(Tokens.size(), 12u) << Tokens; EXPECT_TOKEN(Tokens[7], tok::amp, TT_BinaryOperator); + + Tokens = + annotate("template <typename T> void swap() noexcept(Bar<T> && Foo<T>);"); + ASSERT_EQ(Tokens.size(), 23u) << Tokens; + EXPECT_TOKEN(Tokens[15], tok::ampamp, TT_BinaryOperator); + + Tokens = annotate("template <typename T> struct S {\n" + " explicit(Bar<T> && Foo<T>) S(const S &);\n" + "};"); + ASSERT_EQ(Tokens.size(), 30u) << Tokens; + EXPECT_TOKEN(Tokens[14], tok::ampamp, TT_BinaryOperator); } TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) { Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -11592,6 +11592,10 @@ verifyFormat("template <bool B, bool C> class A {\n" " static_assert(B && C, \"Something is wrong\");\n" "};"); + verifyFormat("template <typename T> void swap() noexcept(Bar<T> && Foo<T>);"); + verifyFormat("template <typename T> struct S {\n" + " explicit(Bar<T> && Foo<T>) S(const S &);\n" + "};"); verifyGoogleFormat("#define IF(a, b, c) if (a && (b == c))"); verifyGoogleFormat("#define WHILE(a, b, c) while (a && (b == c))"); verifyFormat("#define A(a, b) (a && b)"); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -318,9 +318,10 @@ // export type X = (...); Contexts.back().IsExpression = false; } else if (OpeningParen.Previous && - (OpeningParen.Previous->isOneOf(tok::kw_static_assert, - tok::kw_while, tok::l_paren, - tok::comma, TT_BinaryOperator) || + (OpeningParen.Previous->isOneOf( + tok::kw_static_assert, tok::kw_noexcept, tok::kw_explicit, + tok::kw_while, tok::l_paren, tok::comma, + TT_BinaryOperator) || OpeningParen.Previous->isIf())) { // static_assert, if and while usually contain expressions. Contexts.back().IsExpression = true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits