summaryrefslogtreecommitdiff
path: root/unittests/ASTMatchers/ASTMatchersTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/ASTMatchers/ASTMatchersTest.cpp')
-rw-r--r--unittests/ASTMatchers/ASTMatchersTest.cpp43
1 files changed, 37 insertions, 6 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp
index 301b4f7c8a8a..cfa53868ed29 100644
--- a/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -337,14 +337,22 @@ TEST(DeclarationMatcher, hasDeclContext) {
" class D {};"
" }"
"}",
- recordDecl(hasDeclContext(namedDecl(hasName("M"))))));
+ recordDecl(hasDeclContext(namespaceDecl(hasName("M"))))));
EXPECT_TRUE(notMatches(
"namespace N {"
" namespace M {"
" class D {};"
" }"
"}",
- recordDecl(hasDeclContext(namedDecl(hasName("N"))))));
+ recordDecl(hasDeclContext(namespaceDecl(hasName("N"))))));
+
+ EXPECT_TRUE(matches("namespace {"
+ " namespace M {"
+ " class D {};"
+ " }"
+ "}",
+ recordDecl(hasDeclContext(namespaceDecl(
+ hasName("M"), hasDeclContext(namespaceDecl()))))));
}
TEST(ClassTemplate, DoesNotMatchClass) {
@@ -1492,6 +1500,27 @@ TEST(Matcher, MatchesAccessSpecDecls) {
EXPECT_TRUE(notMatches("class C { int i; };", accessSpecDecl()));
}
+TEST(Matcher, MatchesVirtualMethod) {
+ EXPECT_TRUE(matches("class X { virtual int f(); };",
+ methodDecl(isVirtual(), hasName("::X::f"))));
+ EXPECT_TRUE(notMatches("class X { int f(); };",
+ methodDecl(isVirtual())));
+}
+
+TEST(Matcher, MatchesOverridingMethod) {
+ EXPECT_TRUE(matches("class X { virtual int f(); }; "
+ "class Y : public X { int f(); };",
+ methodDecl(isOverride(), hasName("::Y::f"))));
+ EXPECT_TRUE(notMatches("class X { virtual int f(); }; "
+ "class Y : public X { int f(); };",
+ methodDecl(isOverride(), hasName("::X::f"))));
+ EXPECT_TRUE(notMatches("class X { int f(); }; "
+ "class Y : public X { int f(); };",
+ methodDecl(isOverride())));
+ EXPECT_TRUE(notMatches("class X { int f(); int f(int); }; ",
+ methodDecl(isOverride())));
+}
+
TEST(Matcher, ConstructorCall) {
StatementMatcher Constructor = constructExpr();
@@ -3387,10 +3416,12 @@ TEST(TypeMatching, MatchesAutoTypes) {
EXPECT_TRUE(matches("int v[] = { 2, 3 }; void f() { for (int i : v) {} }",
autoType()));
- EXPECT_TRUE(matches("auto a = 1;",
- autoType(hasDeducedType(isInteger()))));
- EXPECT_TRUE(notMatches("auto b = 2.0;",
- autoType(hasDeducedType(isInteger()))));
+ // FIXME: Matching against the type-as-written can't work here, because the
+ // type as written was not deduced.
+ //EXPECT_TRUE(matches("auto a = 1;",
+ // autoType(hasDeducedType(isInteger()))));
+ //EXPECT_TRUE(notMatches("auto b = 2.0;",
+ // autoType(hasDeducedType(isInteger()))));
}
TEST(TypeMatching, MatchesFunctionTypes) {