diff options
| author | 2019-06-23 21:36:31 +0000 | |
|---|---|---|
| committer | 2019-06-23 21:36:31 +0000 | |
| commit | 23f101f37937a1bd4a29726cab2f76e0fb038b35 (patch) | |
| tree | f7da7d6b32c2e07114da399150bfa88d72187012 /gnu/llvm/tools/clang/unittests/AST/ASTContextParentMapTest.cpp | |
| parent | sort previous; ok deraadt (diff) | |
| download | wireguard-openbsd-23f101f37937a1bd4a29726cab2f76e0fb038b35.tar.xz wireguard-openbsd-23f101f37937a1bd4a29726cab2f76e0fb038b35.zip | |
Import LLVM 8.0.0 release including clang, lld and lldb.
Diffstat (limited to 'gnu/llvm/tools/clang/unittests/AST/ASTContextParentMapTest.cpp')
| -rw-r--r-- | gnu/llvm/tools/clang/unittests/AST/ASTContextParentMapTest.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/gnu/llvm/tools/clang/unittests/AST/ASTContextParentMapTest.cpp b/gnu/llvm/tools/clang/unittests/AST/ASTContextParentMapTest.cpp index a39189620b6..fb9d5170698 100644 --- a/gnu/llvm/tools/clang/unittests/AST/ASTContextParentMapTest.cpp +++ b/gnu/llvm/tools/clang/unittests/AST/ASTContextParentMapTest.cpp @@ -17,6 +17,9 @@ #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Tooling/Tooling.h" #include "gtest/gtest.h" +#include "gmock/gmock.h" + +using testing::ElementsAre; namespace clang { namespace ast_matchers { @@ -78,5 +81,41 @@ TEST(GetParents, ReturnsMultipleParentsInTemplateInstantiations) { hasAncestor(cxxRecordDecl(unless(isTemplateInstantiation()))))))); } +TEST(GetParents, RespectsTraversalScope) { + auto AST = + tooling::buildASTFromCode("struct foo { int bar; };", "foo.cpp", + std::make_shared<PCHContainerOperations>()); + auto &Ctx = AST->getASTContext(); + auto &TU = *Ctx.getTranslationUnitDecl(); + auto &Foo = *TU.lookup(&Ctx.Idents.get("foo")).front(); + auto &Bar = *cast<DeclContext>(Foo).lookup(&Ctx.Idents.get("bar")).front(); + + using ast_type_traits::DynTypedNode; + // Initially, scope is the whole TU. + EXPECT_THAT(Ctx.getParents(Bar), ElementsAre(DynTypedNode::create(Foo))); + EXPECT_THAT(Ctx.getParents(Foo), ElementsAre(DynTypedNode::create(TU))); + + // Restrict the scope, now some parents are gone. + Ctx.setTraversalScope({&Foo}); + EXPECT_THAT(Ctx.getParents(Bar), ElementsAre(DynTypedNode::create(Foo))); + EXPECT_THAT(Ctx.getParents(Foo), ElementsAre()); + + // Reset the scope, we get back the original results. + Ctx.setTraversalScope({&TU}); + EXPECT_THAT(Ctx.getParents(Bar), ElementsAre(DynTypedNode::create(Foo))); + EXPECT_THAT(Ctx.getParents(Foo), ElementsAre(DynTypedNode::create(TU))); +} + +TEST(GetParents, ImplicitLambdaNodes) { + MatchVerifier<Decl> LambdaVerifier; + EXPECT_TRUE(LambdaVerifier.match( + "auto x = []{int y;};", + varDecl(hasName("y"), hasAncestor(functionDecl( + hasOverloadedOperatorName("()"), + hasParent(cxxRecordDecl( + isImplicit(), hasParent(lambdaExpr())))))), + Lang_CXX11)); +} + } // end namespace ast_matchers } // end namespace clang |
