diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:02:28 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:02:28 +0000 |
commit | 7442d6faa2719e4e7d33a7021c406c5a4facd74d (patch) | |
tree | c72b9241553fc9966179aba84f90f17bfa9235c3 /unittests/ASTMatchers | |
parent | b52119637f743680a99710ce5fdb6646da2772af (diff) |
Notes
Diffstat (limited to 'unittests/ASTMatchers')
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersNodeTest.cpp | 59 | ||||
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.h | 35 |
2 files changed, 81 insertions, 13 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/unittests/ASTMatchers/ASTMatchersNodeTest.cpp index dd45ca3ced92f..5c29334222df9 100644 --- a/unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -1494,15 +1494,32 @@ TEST(TypedefNameDeclMatcher, Match) { typedefNameDecl(hasName("typedefNameDeclTest2")))); } +TEST(TypeAliasTemplateDeclMatcher, Match) { + std::string Code = R"( + template <typename T> + class X { T t; }; + + template <typename T> + using typeAliasTemplateDecl = X<T>; + + using typeAliasDecl = X<int>; + )"; + EXPECT_TRUE( + matches(Code, typeAliasTemplateDecl(hasName("typeAliasTemplateDecl")))); + EXPECT_TRUE( + notMatches(Code, typeAliasTemplateDecl(hasName("typeAliasDecl")))); +} + TEST(ObjCMessageExprMatcher, SimpleExprs) { // don't find ObjCMessageExpr where none are present EXPECT_TRUE(notMatchesObjC("", objcMessageExpr(anything()))); std::string Objc1String = "@interface Str " - " - (Str *)uppercaseString:(Str *)str;" + " - (Str *)uppercaseString;" "@end " "@interface foo " + "- (void)contents;" "- (void)meth:(Str *)text;" "@end " " " @@ -1540,5 +1557,45 @@ TEST(ObjCMessageExprMatcher, SimpleExprs) { ))); } +TEST(ObjCDeclMacher, CoreDecls) { + std::string ObjCString = + "@protocol Proto " + "- (void)protoDidThing; " + "@end " + "@interface Thing " + "@property int enabled; " + "@end " + "@interface Thing (ABC) " + "- (void)abc_doThing; " + "@end " + "@implementation Thing " + "{ id _ivar; } " + "- (void)anything {} " + "@end " + ; + + EXPECT_TRUE(matchesObjC( + ObjCString, + objcProtocolDecl(hasName("Proto")))); + EXPECT_TRUE(matchesObjC( + ObjCString, + objcCategoryDecl(hasName("ABC")))); + EXPECT_TRUE(matchesObjC( + ObjCString, + objcMethodDecl(hasName("protoDidThing")))); + EXPECT_TRUE(matchesObjC( + ObjCString, + objcMethodDecl(hasName("abc_doThing")))); + EXPECT_TRUE(matchesObjC( + ObjCString, + objcMethodDecl(hasName("anything")))); + EXPECT_TRUE(matchesObjC( + ObjCString, + objcIvarDecl(hasName("_ivar")))); + EXPECT_TRUE(matchesObjC( + ObjCString, + objcPropertyDecl(hasName("enabled")))); +} + } // namespace ast_matchers } // namespace clang diff --git a/unittests/ASTMatchers/ASTMatchersTest.h b/unittests/ASTMatchers/ASTMatchersTest.h index fdb273c672da3..4f5579ce0def1 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.h +++ b/unittests/ASTMatchers/ASTMatchersTest.h @@ -61,7 +61,7 @@ private: template <typename T> testing::AssertionResult matchesConditionally( const std::string &Code, const T &AMatcher, bool ExpectMatch, - llvm::StringRef CompileArg, + llvm::ArrayRef<llvm::StringRef> CompileArgs, const FileContentMappings &VirtualMappedFiles = FileContentMappings(), const std::string &Filename = "input.cc") { bool Found = false, DynamicFound = false; @@ -81,8 +81,9 @@ testing::AssertionResult matchesConditionally( // FIXME: This is a hack to work around the fact that there's no way to do the // equivalent of runToolOnCodeWithArgs without instantiating a full Driver. // We should consider having a function, at least for tests, that invokes cc1. - std::vector<std::string> Args = {CompileArg, "-frtti", "-fexceptions", - "-target", "i386-unknown-unknown"}; + std::vector<std::string> Args(CompileArgs.begin(), CompileArgs.end()); + Args.insert(Args.end(), {"-frtti", "-fexceptions", + "-target", "i386-unknown-unknown"}); if (!runToolOnCodeWithArgs( Factory->create(), Code, Args, Filename, "clang-tool", std::make_shared<PCHContainerOperations>(), VirtualMappedFiles)) { @@ -105,6 +106,17 @@ testing::AssertionResult matchesConditionally( } template <typename T> +testing::AssertionResult matchesConditionally( + const std::string &Code, const T &AMatcher, bool ExpectMatch, + llvm::StringRef CompileArg, + const FileContentMappings &VirtualMappedFiles = FileContentMappings(), + const std::string &Filename = "input.cc") { + return matchesConditionally(Code, AMatcher, ExpectMatch, + llvm::makeArrayRef(CompileArg), + VirtualMappedFiles, Filename); +} + +template <typename T> testing::AssertionResult matches(const std::string &Code, const T &AMatcher) { return matchesConditionally(Code, AMatcher, true, "-std=c++11"); } @@ -116,11 +128,12 @@ testing::AssertionResult notMatches(const std::string &Code, } template <typename T> -testing::AssertionResult matchesObjC(const std::string &Code, - const T &AMatcher) { - return matchesConditionally( - Code, AMatcher, true, - "", FileContentMappings(), "input.m"); +testing::AssertionResult matchesObjC(const std::string &Code, const T &AMatcher, + bool ExpectMatch = true) { + return matchesConditionally(Code, AMatcher, ExpectMatch, + {"-fobjc-nonfragile-abi", "-Wno-objc-root-class", + "-Wno-incomplete-implementation"}, + FileContentMappings(), "input.m"); } template <typename T> @@ -145,10 +158,8 @@ testing::AssertionResult notMatchesC(const std::string &Code, template <typename T> testing::AssertionResult notMatchesObjC(const std::string &Code, - const T &AMatcher) { - return matchesConditionally( - Code, AMatcher, false, - "", FileContentMappings(), "input.m"); + const T &AMatcher) { + return matchesObjC(Code, AMatcher, false); } |