diff options
author | dim <dim@FreeBSD.org> | 2015-12-30 11:49:41 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2015-12-30 11:49:41 +0000 |
commit | 3176e97f130184ece0e1a21352c8124cc83ff24a (patch) | |
tree | 0a5b74c0b9ca73aded34df95c91fcaf3815230d8 /unittests/AST | |
parent | 1e9b8d38881c3213d1e67b0c47ab9b2c00721a5c (diff) | |
download | FreeBSD-src-3176e97f130184ece0e1a21352c8124cc83ff24a.zip FreeBSD-src-3176e97f130184ece0e1a21352c8124cc83ff24a.tar.gz |
Vendor import of clang trunk r256633:
https://llvm.org/svn/llvm-project/cfe/trunk@256633
Diffstat (limited to 'unittests/AST')
-rw-r--r-- | unittests/AST/ASTContextParentMapTest.cpp | 39 | ||||
-rw-r--r-- | unittests/AST/ASTTypeTraitsTest.cpp | 7 | ||||
-rw-r--r-- | unittests/AST/DeclPrinterTest.cpp | 46 | ||||
-rw-r--r-- | unittests/AST/NamedDeclPrinterTest.cpp | 42 | ||||
-rw-r--r-- | unittests/AST/SourceLocationTest.cpp | 26 | ||||
-rw-r--r-- | unittests/AST/StmtPrinterTest.cpp | 4 |
6 files changed, 114 insertions, 50 deletions
diff --git a/unittests/AST/ASTContextParentMapTest.cpp b/unittests/AST/ASTContextParentMapTest.cpp index 0dcb175..b1d7db4 100644 --- a/unittests/AST/ASTContextParentMapTest.cpp +++ b/unittests/AST/ASTContextParentMapTest.cpp @@ -27,8 +27,9 @@ using clang::tooling::FrontendActionFactory; TEST(GetParents, ReturnsParentForDecl) { MatchVerifier<Decl> Verifier; - EXPECT_TRUE(Verifier.match("class C { void f(); };", - methodDecl(hasParent(recordDecl(hasName("C")))))); + EXPECT_TRUE( + Verifier.match("class C { void f(); };", + cxxMethodDecl(hasParent(recordDecl(hasName("C")))))); } TEST(GetParents, ReturnsParentForStmt) { @@ -37,24 +38,38 @@ TEST(GetParents, ReturnsParentForStmt) { ifStmt(hasParent(compoundStmt())))); } +TEST(GetParents, ReturnsParentForTypeLoc) { + MatchVerifier<TypeLoc> Verifier; + EXPECT_TRUE( + Verifier.match("namespace a { class b {}; } void f(a::b) {}", + typeLoc(hasParent(typeLoc(hasParent(functionDecl())))))); +} + +TEST(GetParents, ReturnsParentForNestedNameSpecifierLoc) { + MatchVerifier<NestedNameSpecifierLoc> Verifier; + EXPECT_TRUE(Verifier.match("namespace a { class b {}; } void f(a::b) {}", + nestedNameSpecifierLoc(hasParent(typeLoc())))); +} + TEST(GetParents, ReturnsParentInsideTemplateInstantiations) { MatchVerifier<Decl> DeclVerifier; EXPECT_TRUE(DeclVerifier.match( "template<typename T> struct C { void f() {} };" "void g() { C<int> c; c.f(); }", - methodDecl(hasName("f"), - hasParent(recordDecl(isTemplateInstantiation()))))); + cxxMethodDecl(hasName("f"), + hasParent(cxxRecordDecl(isTemplateInstantiation()))))); EXPECT_TRUE(DeclVerifier.match( "template<typename T> struct C { void f() {} };" "void g() { C<int> c; c.f(); }", - methodDecl(hasName("f"), - hasParent(recordDecl(unless(isTemplateInstantiation())))))); + cxxMethodDecl(hasName("f"), + hasParent(cxxRecordDecl(unless(isTemplateInstantiation())))))); EXPECT_FALSE(DeclVerifier.match( "template<typename T> struct C { void f() {} };" "void g() { C<int> c; c.f(); }", - methodDecl(hasName("f"), - allOf(hasParent(recordDecl(unless(isTemplateInstantiation()))), - hasParent(recordDecl(isTemplateInstantiation())))))); + cxxMethodDecl( + hasName("f"), + allOf(hasParent(cxxRecordDecl(unless(isTemplateInstantiation()))), + hasParent(cxxRecordDecl(isTemplateInstantiation())))))); } TEST(GetParents, ReturnsMultipleParentsInTemplateInstantiations) { @@ -62,9 +77,9 @@ TEST(GetParents, ReturnsMultipleParentsInTemplateInstantiations) { EXPECT_TRUE(TemplateVerifier.match( "template<typename T> struct C { void f() {} };" "void g() { C<int> c; c.f(); }", - compoundStmt( - allOf(hasAncestor(recordDecl(isTemplateInstantiation())), - hasAncestor(recordDecl(unless(isTemplateInstantiation()))))))); + compoundStmt(allOf( + hasAncestor(cxxRecordDecl(isTemplateInstantiation())), + hasAncestor(cxxRecordDecl(unless(isTemplateInstantiation()))))))); } } // end namespace ast_matchers diff --git a/unittests/AST/ASTTypeTraitsTest.cpp b/unittests/AST/ASTTypeTraitsTest.cpp index eeb01cc..b635653 100644 --- a/unittests/AST/ASTTypeTraitsTest.cpp +++ b/unittests/AST/ASTTypeTraitsTest.cpp @@ -162,5 +162,12 @@ TEST(DynTypedNode, StmtPrint) { EXPECT_TRUE(Verifier.match("void f() {}", stmt())); } +TEST(DynTypedNode, QualType) { + QualType Q; + DynTypedNode Node = DynTypedNode::create(Q); + EXPECT_TRUE(Node == Node); + EXPECT_FALSE(Node < Node); +} + } // namespace ast_type_traits } // namespace clang diff --git a/unittests/AST/DeclPrinterTest.cpp b/unittests/AST/DeclPrinterTest.cpp index d8cb977..d06fbfe 100644 --- a/unittests/AST/DeclPrinterTest.cpp +++ b/unittests/AST/DeclPrinterTest.cpp @@ -471,7 +471,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl1) { "struct A {" " A();" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A()")); } @@ -480,7 +480,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl2) { "struct A {" " A(int a);" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A(int a)")); } @@ -489,7 +489,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl3) { "struct A {" " A(const A &a);" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A(const A &a)")); } @@ -498,7 +498,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl4) { "struct A {" " A(const A &a, int = 0);" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A(const A &a, int = 0)")); } @@ -507,7 +507,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl5) { "struct A {" " A(const A &&a);" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A(const A &&a)")); } @@ -516,7 +516,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl6) { "struct A {" " explicit A(int a);" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "explicit A(int a)")); } @@ -525,7 +525,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl7) { "struct A {" " constexpr A();" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "constexpr A()")); } @@ -534,7 +534,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl8) { "struct A {" " A() = default;" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A() = default")); } @@ -543,7 +543,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl9) { "struct A {" " A() = delete;" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A() = delete")); } @@ -553,7 +553,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl10) { "struct A {" " A(const A &a);" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A<T...>(const A<T...> &a)")); // WRONG; Should be: "A(const A<T...> &a);" } @@ -564,7 +564,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl11) { "struct A : public T... {" " A(T&&... ts) : T(ts)... {}" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A<T...>(T &&...ts) : T(ts)...")); // WRONG; Should be: "A(T &&...ts) : T(ts)... {}" } @@ -574,7 +574,7 @@ TEST(DeclPrinter, TestCXXDestructorDecl1) { "struct A {" " ~A();" "};", - destructorDecl(ofClass(hasName("A"))).bind("id"), + cxxDestructorDecl(ofClass(hasName("A"))).bind("id"), "~A()")); } @@ -583,7 +583,7 @@ TEST(DeclPrinter, TestCXXDestructorDecl2) { "struct A {" " virtual ~A();" "};", - destructorDecl(ofClass(hasName("A"))).bind("id"), + cxxDestructorDecl(ofClass(hasName("A"))).bind("id"), "virtual ~A()")); } @@ -592,7 +592,7 @@ TEST(DeclPrinter, TestCXXConversionDecl1) { "struct A {" " operator int();" "};", - methodDecl(ofClass(hasName("A"))).bind("id"), + cxxMethodDecl(ofClass(hasName("A"))).bind("id"), "operator int()")); } @@ -601,7 +601,7 @@ TEST(DeclPrinter, TestCXXConversionDecl2) { "struct A {" " operator bool();" "};", - methodDecl(ofClass(hasName("A"))).bind("id"), + cxxMethodDecl(ofClass(hasName("A"))).bind("id"), "operator bool()")); } @@ -611,7 +611,7 @@ TEST(DeclPrinter, TestCXXConversionDecl3) { "struct A {" " operator Z();" "};", - methodDecl(ofClass(hasName("A"))).bind("id"), + cxxMethodDecl(ofClass(hasName("A"))).bind("id"), "operator Z()")); } @@ -621,7 +621,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction1) { "struct Z {" " void *operator new(std::size_t);" "};", - methodDecl(ofClass(hasName("Z"))).bind("id"), + cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), "void *operator new(std::size_t)")); // Should be: with semicolon } @@ -632,7 +632,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction2) { "struct Z {" " void *operator new[](std::size_t);" "};", - methodDecl(ofClass(hasName("Z"))).bind("id"), + cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), "void *operator new[](std::size_t)")); // Should be: with semicolon } @@ -642,7 +642,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction3) { "struct Z {" " void operator delete(void *);" "};", - methodDecl(ofClass(hasName("Z"))).bind("id"), + cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), "void operator delete(void *) noexcept")); // Should be: with semicolon, without noexcept? } @@ -652,7 +652,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction4) { "struct Z {" " void operator delete(void *);" "};", - methodDecl(ofClass(hasName("Z"))).bind("id"), + cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), "void operator delete(void *)")); // Should be: with semicolon } @@ -662,7 +662,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction5) { "struct Z {" " void operator delete[](void *);" "};", - methodDecl(ofClass(hasName("Z"))).bind("id"), + cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), "void operator delete[](void *) noexcept")); // Should be: with semicolon, without noexcept? } @@ -690,7 +690,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_Operator1) { ASSERT_TRUE(PrintedDeclCXX98Matches( Code, - methodDecl(ofClass(hasName("Z"))).bind("id"), + cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), Expected)); } } @@ -714,7 +714,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_Operator2) { ASSERT_TRUE(PrintedDeclCXX98Matches( Code, - methodDecl(ofClass(hasName("Z"))).bind("id"), + cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), Expected)); } } diff --git a/unittests/AST/NamedDeclPrinterTest.cpp b/unittests/AST/NamedDeclPrinterTest.cpp index cf97a0a..92df457 100644 --- a/unittests/AST/NamedDeclPrinterTest.cpp +++ b/unittests/AST/NamedDeclPrinterTest.cpp @@ -131,3 +131,45 @@ TEST(NamedDeclPrinter, TestNamespace2) { "A", "A")); } + +TEST(NamedDeclPrinter, TestUnscopedUnnamedEnum) { + ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches( + "enum { A };", + "A", + "A")); +} + +TEST(NamedDeclPrinter, TestNamedEnum) { + ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches( + "enum X { A };", + "A", + "X::A")); +} + +TEST(NamedDeclPrinter, TestScopedNamedEnum) { + ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches( + "enum class X { A };", + "A", + "X::A")); +} + +TEST(NamedDeclPrinter, TestClassWithUnscopedUnnamedEnum) { + ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches( + "class X { enum { A }; };", + "A", + "X::A")); +} + +TEST(NamedDeclPrinter, TestClassWithUnscopedNamedEnum) { + ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches( + "class X { enum Y { A }; };", + "A", + "X::Y::A")); +} + +TEST(NamedDeclPrinter, TestClassWithScopedNamedEnum) { + ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches( + "class X { enum class Y { A }; };", + "A", + "X::Y::A")); +} diff --git a/unittests/AST/SourceLocationTest.cpp b/unittests/AST/SourceLocationTest.cpp index b0a8f85..4c77def 100644 --- a/unittests/AST/SourceLocationTest.cpp +++ b/unittests/AST/SourceLocationTest.cpp @@ -92,13 +92,13 @@ TEST(ParmVarDecl, KNRRange) { TEST(CXXNewExpr, ArrayRange) { RangeVerifier<CXXNewExpr> Verifier; Verifier.expectRange(1, 12, 1, 22); - EXPECT_TRUE(Verifier.match("void f() { new int[10]; }", newExpr())); + EXPECT_TRUE(Verifier.match("void f() { new int[10]; }", cxxNewExpr())); } TEST(CXXNewExpr, ParenRange) { RangeVerifier<CXXNewExpr> Verifier; Verifier.expectRange(1, 12, 1, 20); - EXPECT_TRUE(Verifier.match("void f() { new int(); }", newExpr())); + EXPECT_TRUE(Verifier.match("void f() { new int(); }", cxxNewExpr())); } TEST(MemberExpr, ImplicitMemberRange) { @@ -221,7 +221,7 @@ TEST(TemplateSpecializationTypeLoc, AngleBracketLocations) { TEST(CXXNewExpr, TypeParenRange) { RangeVerifier<CXXNewExpr> Verifier; Verifier.expectRange(1, 10, 1, 18); - EXPECT_TRUE(Verifier.match("int* a = new (int);", newExpr())); + EXPECT_TRUE(Verifier.match("int* a = new (int);", cxxNewExpr())); } class UnaryTransformTypeLocParensRangeVerifier : public RangeVerifier<TypeLoc> { @@ -252,7 +252,7 @@ TEST(CXXFunctionalCastExpr, SourceRange) { "int foo() {\n" " return int{};\n" "}", - functionalCastExpr(), Lang_CXX11)); + cxxFunctionalCastExpr(), Lang_CXX11)); } TEST(CXXConstructExpr, SourceRange) { @@ -262,7 +262,7 @@ TEST(CXXConstructExpr, SourceRange) { "struct A { A(int, int); };\n" "void f(A a);\n" "void g() { f({0, 0}); }", - constructExpr(), Lang_CXX11)); + cxxConstructExpr(), Lang_CXX11)); } TEST(CXXTemporaryObjectExpr, SourceRange) { @@ -271,7 +271,7 @@ TEST(CXXTemporaryObjectExpr, SourceRange) { EXPECT_TRUE(Verifier.match( "struct A { A(int, int); };\n" "A a( A{0, 0} );", - temporaryObjectExpr(), Lang_CXX11)); + cxxTemporaryObjectExpr(), Lang_CXX11)); } TEST(CXXUnresolvedConstructExpr, SourceRange) { @@ -284,7 +284,7 @@ TEST(CXXUnresolvedConstructExpr, SourceRange) { "U foo() {\n" " return U{};\n" "}", - unresolvedConstructExpr(), Args, Lang_CXX11)); + cxxUnresolvedConstructExpr(), Args, Lang_CXX11)); } TEST(UsingDecl, SourceRange) { @@ -434,11 +434,11 @@ TEST(FriendDecl, FriendConstructorDestructorLocation) { LocationVerifier<FriendDecl> ConstructorVerifier; ConstructorVerifier.expectLocation(6, 11); EXPECT_TRUE(ConstructorVerifier.match( - Code, friendDecl(has(constructorDecl(ofClass(hasName("B"))))))); + Code, friendDecl(has(cxxConstructorDecl(ofClass(hasName("B"))))))); LocationVerifier<FriendDecl> DestructorVerifier; DestructorVerifier.expectLocation(6, 19); EXPECT_TRUE(DestructorVerifier.match( - Code, friendDecl(has(destructorDecl(ofClass(hasName("B"))))))); + Code, friendDecl(has(cxxDestructorDecl(ofClass(hasName("B"))))))); } TEST(FriendDecl, FriendConstructorDestructorRange) { @@ -452,11 +452,11 @@ TEST(FriendDecl, FriendConstructorDestructorRange) { RangeVerifier<FriendDecl> ConstructorVerifier; ConstructorVerifier.expectRange(6, 1, 6, 13); EXPECT_TRUE(ConstructorVerifier.match( - Code, friendDecl(has(constructorDecl(ofClass(hasName("B"))))))); + Code, friendDecl(has(cxxConstructorDecl(ofClass(hasName("B"))))))); RangeVerifier<FriendDecl> DestructorVerifier; DestructorVerifier.expectRange(6, 1, 6, 22); EXPECT_TRUE(DestructorVerifier.match( - Code, friendDecl(has(destructorDecl(ofClass(hasName("B"))))))); + Code, friendDecl(has(cxxDestructorDecl(ofClass(hasName("B"))))))); } TEST(FriendDecl, FriendTemplateFunctionLocation) { @@ -527,7 +527,7 @@ TEST(FriendDecl, InstantiationSourceRange) { " friend void operator+<>(S<T> src);\n" "};\n" "void test(S<double> s) { +s; }", - friendDecl(hasParent(recordDecl(isTemplateInstantiation()))))); + friendDecl(hasParent(cxxRecordDecl(isTemplateInstantiation()))))); } TEST(ObjCMessageExpr, CXXConstructExprRange) { @@ -539,7 +539,7 @@ TEST(ObjCMessageExpr, CXXConstructExprRange) { "+ (void) f1: (A)arg;\n" "@end\n" "void f2() { A a; [B f1: (a)]; }\n", - constructExpr(), Lang_OBJCXX)); + cxxConstructExpr(), Lang_OBJCXX)); } } // end namespace ast_matchers diff --git a/unittests/AST/StmtPrinterTest.cpp b/unittests/AST/StmtPrinterTest.cpp index b1fd2c1..bc7fd54 100644 --- a/unittests/AST/StmtPrinterTest.cpp +++ b/unittests/AST/StmtPrinterTest.cpp @@ -196,7 +196,7 @@ TEST(StmtPrinter, TestCXXConversionDeclImplicit) { "void foo(A a, A b) {" " bar(a & b);" "}", - memberCallExpr(anything()).bind("id"), + cxxMemberCallExpr(anything()).bind("id"), "a & b")); } @@ -210,7 +210,7 @@ TEST(StmtPrinter, TestCXXConversionDeclExplicit) { "void foo(A a, A b) {" " auto x = (a & b).operator void *();" "}", - memberCallExpr(anything()).bind("id"), + cxxMemberCallExpr(anything()).bind("id"), "(a & b)")); // WRONG; Should be: (a & b).operator void *() } |