1 //===- unittests/AST/ConceptPrinterTest.cpp --- Concept printer tests -----===//
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
7 //===----------------------------------------------------------------------===//
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"
18 using namespace clang
;
19 using namespace ast_matchers
;
20 using namespace tooling
;
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");
30 PrintingPolicy Policy
= Context
->getPrintingPolicy();
32 PolicyAdjuster(Policy
);
33 T
->getConceptReference()->print(Out
, Policy
);
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
, "", PrintConceptReference
);
43 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ConceptSpecializationExpr
>
44 conceptSpecializationExpr
;
45 } // unnamed namespace
47 TEST(ConceptPrinter
, ConceptReference
) {
48 std::string Code
= R
"cpp(
49 template <typename, typename> concept D = true;
50 template<typename T, typename U>
54 auto Matcher
= conceptSpecializationExpr().bind("id");
56 ASSERT_TRUE(PrintedConceptMatches(Code
, {"-std=c++20"}, Matcher
, "D<T, U>"));