diff options
author | Björn Schäpers <bjoern@hazardy.de> | 2022-07-04 10:53:34 +0200 |
---|---|---|
committer | Björn Schäpers <bjoern@hazardy.de> | 2022-07-18 21:41:09 +0200 |
commit | 2b04c41b28320c1e399209fbe7a5a8d540578999 (patch) | |
tree | a159a85b8bfcd3fbc302aab50808d257a233f96e /clang/unittests | |
parent | 523a99c0eb0331680905e9ef6fbdd114f4ee7a47 (diff) | |
download | llvm-2b04c41b28320c1e399209fbe7a5a8d540578999.zip llvm-2b04c41b28320c1e399209fbe7a5a8d540578999.tar.gz llvm-2b04c41b28320c1e399209fbe7a5a8d540578999.tar.bz2 |
[clang-format] Fix misannotation of colon in presence of requires clause
For clauses without parentheses it was annotated as TT_InheritanceColon.
Relates to https://github.com/llvm/llvm-project/issues/56215
Differential Revision: https://reviews.llvm.org/D129940
Diffstat (limited to 'clang/unittests')
-rw-r--r-- | clang/unittests/Format/TokenAnnotatorTest.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index a2474d5c..ed6fb41 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -802,6 +802,70 @@ TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) { << I; } } + + BaseTokens = annotate("constexpr Foo(Foo const &other)\n" + " : value{other.value} {\n" + " do_magic();\n" + " do_more_magic();\n" + "}"); + + ConstrainedTokens = annotate("constexpr Foo(Foo const &other)\n" + " requires std::is_copy_constructible<T>\n" + " : value{other.value} {\n" + " do_magic();\n" + " do_more_magic();\n" + "}"); + + NumberOfBaseTokens = 26u; + NumberOfAdditionalRequiresClauseTokens = 7u; + NumberOfTokensBeforeRequires = 8u; + + ASSERT_EQ(BaseTokens.size(), NumberOfBaseTokens) << BaseTokens; + ASSERT_EQ(ConstrainedTokens.size(), + NumberOfBaseTokens + NumberOfAdditionalRequiresClauseTokens) + << ConstrainedTokens; + + for (auto I = 0u; I < NumberOfBaseTokens; ++I) { + if (I < NumberOfTokensBeforeRequires) { + EXPECT_EQ(*BaseTokens[I], *ConstrainedTokens[I]) << I; + } else { + EXPECT_EQ(*BaseTokens[I], + *ConstrainedTokens[I + NumberOfAdditionalRequiresClauseTokens]) + << I; + } + } + + BaseTokens = annotate("constexpr Foo(Foo const &other)\n" + " : value{other.value} {\n" + " do_magic();\n" + " do_more_magic();\n" + "}"); + + ConstrainedTokens = annotate("constexpr Foo(Foo const &other)\n" + " requires (std::is_copy_constructible<T>)\n" + " : value{other.value} {\n" + " do_magic();\n" + " do_more_magic();\n" + "}"); + + NumberOfBaseTokens = 26u; + NumberOfAdditionalRequiresClauseTokens = 9u; + NumberOfTokensBeforeRequires = 8u; + + ASSERT_EQ(BaseTokens.size(), NumberOfBaseTokens) << BaseTokens; + ASSERT_EQ(ConstrainedTokens.size(), + NumberOfBaseTokens + NumberOfAdditionalRequiresClauseTokens) + << ConstrainedTokens; + + for (auto I = 0u; I < NumberOfBaseTokens; ++I) { + if (I < NumberOfTokensBeforeRequires) { + EXPECT_EQ(*BaseTokens[I], *ConstrainedTokens[I]) << I; + } else { + EXPECT_EQ(*BaseTokens[I], + *ConstrainedTokens[I + NumberOfAdditionalRequiresClauseTokens]) + << I; + } + } } TEST_F(TokenAnnotatorTest, UnderstandsAsm) { |