aboutsummaryrefslogtreecommitdiff
path: root/unittests/ASTMatchers/ASTMatchersTest.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2012-07-25 10:02:02 +0000
committerManuel Klimek <klimek@google.com>2012-07-25 10:02:02 +0000
commit715c9568ee5d75f25dab98229c87bcec880daf5d (patch)
tree23fbfb207a44f1ca3f06a3b05e7e5bd20bc555c2 /unittests/ASTMatchers/ASTMatchersTest.cpp
parent310fe466761023874250a44cc9a5f56600c44f46 (diff)
Introduces the 'decl' matcher which was missing for a while
and became necessary with the change to require BindableMatchers for binding. Also fixes PR 13445: "hasSourceExpression only works for implicit casts". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160716 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ASTMatchers/ASTMatchersTest.cpp')
-rw-r--r--unittests/ASTMatchers/ASTMatchersTest.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp
index f76a59696f..91095eb3ff 100644
--- a/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -39,6 +39,12 @@ TEST(IsDerivedFromDeathTest, DiesOnEmptyBaseName) {
}
#endif
+TEST(Decl, MatchesDeclarations) {
+ EXPECT_TRUE(notMatches("", decl(usingDecl())));
+ EXPECT_TRUE(matches("namespace x { class X {}; } using x::X;",
+ decl(usingDecl())));
+}
+
TEST(NameableDeclaration, MatchesVariousDecls) {
DeclarationMatcher NamedX = nameableDeclaration(hasName("X"));
EXPECT_TRUE(matches("typedef int X;", NamedX));
@@ -2037,13 +2043,20 @@ TEST(HasDestinationType, MatchesSimpleCase) {
pointsTo(TypeMatcher(anything())))))));
}
-TEST(HasSourceExpression, MatchesSimpleCase) {
+TEST(HasSourceExpression, MatchesImplicitCasts) {
EXPECT_TRUE(matches("class string {}; class URL { public: URL(string s); };"
"void r() {string a_string; URL url = a_string; }",
expression(implicitCast(
hasSourceExpression(constructorCall())))));
}
+TEST(HasSourceExpression, MatchesExplicitCasts) {
+ EXPECT_TRUE(matches("float x = static_cast<float>(42);",
+ expression(explicitCast(
+ hasSourceExpression(hasDescendant(
+ expression(integerLiteral())))))));
+}
+
TEST(Statement, DoesNotMatchDeclarations) {
EXPECT_TRUE(notMatches("class X {};", statement()));
}