1 | //===- unittests/AST/ConceptPrinterTest.cpp --- Concept printer tests -----===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "ASTPrint.h" |
10 | #include "clang/AST/ASTConcept.h" |
11 | #include "clang/AST/ASTContext.h" |
12 | #include "clang/AST/ExprConcepts.h" |
13 | #include "clang/ASTMatchers/ASTMatchFinder.h" |
14 | #include "clang/Tooling/Tooling.h" |
15 | #include "llvm/ADT/SmallString.h" |
16 | #include "gtest/gtest.h" |
17 | |
18 | using namespace clang; |
19 | using namespace ast_matchers; |
20 | using namespace tooling; |
21 | |
22 | namespace { |
23 | |
24 | static void PrintConceptReference(raw_ostream &Out, const ASTContext *Context, |
25 | const ConceptSpecializationExpr *T, |
26 | PrintingPolicyAdjuster PolicyAdjuster) { |
27 | assert(T && T->getConceptReference() && |
28 | "Expected non-null concept reference" ); |
29 | |
30 | PrintingPolicy Policy = Context->getPrintingPolicy(); |
31 | if (PolicyAdjuster) |
32 | PolicyAdjuster(Policy); |
33 | T->getConceptReference()->print(OS&: Out, Policy); |
34 | } |
35 | |
36 | ::testing::AssertionResult |
37 | PrintedConceptMatches(StringRef Code, const std::vector<std::string> &Args, |
38 | const StatementMatcher &NodeMatch, |
39 | StringRef ExpectedPrinted) { |
40 | return PrintedNodeMatches<ConceptSpecializationExpr>( |
41 | Code, Args, NodeMatch, ExpectedPrinted, FileName: "" , Printer: PrintConceptReference); |
42 | } |
43 | const internal::VariadicDynCastAllOfMatcher<Stmt, ConceptSpecializationExpr> |
44 | conceptSpecializationExpr; |
45 | } // unnamed namespace |
46 | |
47 | TEST(ConceptPrinter, ConceptReference) { |
48 | std::string Code = R"cpp( |
49 | template <typename, typename> concept D = true; |
50 | template<typename T, typename U> |
51 | requires D<T, U> |
52 | void g(T); |
53 | )cpp" ; |
54 | auto Matcher = conceptSpecializationExpr().bind(ID: "id" ); |
55 | |
56 | ASSERT_TRUE(PrintedConceptMatches(Code, {"-std=c++20" }, Matcher, "D<T, U>" )); |
57 | } |
58 | |