rymiel updated this revision to Diff 473380. rymiel added a comment. Remove format test, relying only on annotator tests
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D137223/new/ https://reviews.llvm.org/D137223 Files: clang/lib/Format/WhitespaceManager.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Index: clang/unittests/Format/TokenAnnotatorTest.cpp =================================================================== --- clang/unittests/Format/TokenAnnotatorTest.cpp +++ clang/unittests/Format/TokenAnnotatorTest.cpp @@ -393,50 +393,80 @@ TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) { auto Tokens = annotate("x.operator+()"); ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::plus, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator=()"); ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::equal, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator+=()"); ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::plusequal, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator,()"); ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::comma, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator()()"); ASSERT_EQ(Tokens.size(), 8u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[4], tok::r_paren, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator[]()"); ASSERT_EQ(Tokens.size(), 8u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); // EXPECT_TOKEN(Tokens[3], tok::l_square, TT_OverloadedOperator); // EXPECT_TOKEN(Tokens[4], tok::r_square, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator\"\"_a()"); ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator\"\" _a()"); ASSERT_EQ(Tokens.size(), 8u) << Tokens; + // FIXME + // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator\"\"if()"); ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator\"\"s()"); ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator\"\" s()"); ASSERT_EQ(Tokens.size(), 8u) << Tokens; + // FIXME + // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen); + + Tokens = annotate("int operator+(int);"); + ASSERT_EQ(Tokens.size(), 8u) << Tokens; + EXPECT_TOKEN(Tokens[1], tok::kw_operator, TT_FunctionDeclarationName); + EXPECT_TOKEN(Tokens[2], tok::plus, TT_OverloadedOperator); + EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperatorLParen); + Tokens = annotate("auto operator=(T&) {}"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[1], tok::kw_operator, TT_FunctionDeclarationName); + EXPECT_TOKEN(Tokens[2], tok::equal, TT_OverloadedOperator); + EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperatorLParen); + Tokens = annotate("auto operator()() {}"); + ASSERT_EQ(Tokens.size(), 9u) << Tokens; + EXPECT_TOKEN(Tokens[1], tok::kw_operator, TT_FunctionDeclarationName); + EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_OverloadedOperator); + EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_OverloadedOperator); + EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen); } TEST_F(TokenAnnotatorTest, UnderstandsRequiresClausesAndConcepts) { Index: clang/lib/Format/WhitespaceManager.cpp =================================================================== --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -870,9 +870,7 @@ AlignTokens( Style, [](Change const &C) { - // tok::kw_operator is necessary for aligning operator overload - // definitions. - if (C.Tok->isOneOf(TT_FunctionDeclarationName, tok::kw_operator)) + if (C.Tok->is(TT_FunctionDeclarationName)) return true; if (C.Tok->isNot(TT_StartOfName)) return false;
Index: clang/unittests/Format/TokenAnnotatorTest.cpp =================================================================== --- clang/unittests/Format/TokenAnnotatorTest.cpp +++ clang/unittests/Format/TokenAnnotatorTest.cpp @@ -393,50 +393,80 @@ TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) { auto Tokens = annotate("x.operator+()"); ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::plus, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator=()"); ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::equal, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator+=()"); ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::plusequal, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator,()"); ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::comma, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator()()"); ASSERT_EQ(Tokens.size(), 8u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[4], tok::r_paren, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator[]()"); ASSERT_EQ(Tokens.size(), 8u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); // EXPECT_TOKEN(Tokens[3], tok::l_square, TT_OverloadedOperator); // EXPECT_TOKEN(Tokens[4], tok::r_square, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator\"\"_a()"); ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator\"\" _a()"); ASSERT_EQ(Tokens.size(), 8u) << Tokens; + // FIXME + // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator\"\"if()"); ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator\"\"s()"); ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen); Tokens = annotate("x.operator\"\" s()"); ASSERT_EQ(Tokens.size(), 8u) << Tokens; + // FIXME + // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName); EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator); EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen); + + Tokens = annotate("int operator+(int);"); + ASSERT_EQ(Tokens.size(), 8u) << Tokens; + EXPECT_TOKEN(Tokens[1], tok::kw_operator, TT_FunctionDeclarationName); + EXPECT_TOKEN(Tokens[2], tok::plus, TT_OverloadedOperator); + EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperatorLParen); + Tokens = annotate("auto operator=(T&) {}"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[1], tok::kw_operator, TT_FunctionDeclarationName); + EXPECT_TOKEN(Tokens[2], tok::equal, TT_OverloadedOperator); + EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperatorLParen); + Tokens = annotate("auto operator()() {}"); + ASSERT_EQ(Tokens.size(), 9u) << Tokens; + EXPECT_TOKEN(Tokens[1], tok::kw_operator, TT_FunctionDeclarationName); + EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_OverloadedOperator); + EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_OverloadedOperator); + EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen); } TEST_F(TokenAnnotatorTest, UnderstandsRequiresClausesAndConcepts) { Index: clang/lib/Format/WhitespaceManager.cpp =================================================================== --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -870,9 +870,7 @@ AlignTokens( Style, [](Change const &C) { - // tok::kw_operator is necessary for aligning operator overload - // definitions. - if (C.Tok->isOneOf(TT_FunctionDeclarationName, tok::kw_operator)) + if (C.Tok->is(TT_FunctionDeclarationName)) return true; if (C.Tok->isNot(TT_StartOfName)) return false;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits