From e0586a574e8ab46c29952fe00044943bb52f34a1 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 18 Oct 2012 19:12:17 +0000 Subject: [PATCH] Patch for decl printer test of objective-c methods. Patch by Dmitri Gribenko. llvm-svn: 166209 --- clang/unittests/AST/DeclPrinterTest.cpp | 42 ++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/clang/unittests/AST/DeclPrinterTest.cpp b/clang/unittests/AST/DeclPrinterTest.cpp index 0bb0272..a2fc839 100644 --- a/clang/unittests/AST/DeclPrinterTest.cpp +++ b/clang/unittests/AST/DeclPrinterTest.cpp @@ -69,13 +69,14 @@ public: StringRef Code, const std::vector &Args, const DeclarationMatcher &NodeMatch, - StringRef ExpectedPrinted) { + StringRef ExpectedPrinted, + StringRef FileName) { PrintMatch Printer; MatchFinder Finder; Finder.addMatcher(NodeMatch, &Printer); OwningPtr Factory(newFrontendActionFactory(&Finder)); - if (!runToolOnCodeWithArgs(Factory->create(), Code, Args)) + if (!runToolOnCodeWithArgs(Factory->create(), Code, Args, FileName)) return testing::AssertionFailure() << "Parsing error in \"" << Code << "\""; if (Printer.getNumFoundDecls() == 0) @@ -102,7 +103,8 @@ public: return PrintedDeclMatches(Code, Args, namedDecl(hasName(DeclName)).bind("id"), - ExpectedPrinted); + ExpectedPrinted, + "input.cc"); } ::testing::AssertionResult PrintedDeclCXX98Matches( @@ -113,7 +115,8 @@ public: return PrintedDeclMatches(Code, Args, NodeMatch, - ExpectedPrinted); + ExpectedPrinted, + "input.cc"); } ::testing::AssertionResult PrintedDeclCXX11Matches(StringRef Code, @@ -123,7 +126,8 @@ public: return PrintedDeclMatches(Code, Args, namedDecl(hasName(DeclName)).bind("id"), - ExpectedPrinted); + ExpectedPrinted, + "input.cc"); } ::testing::AssertionResult PrintedDeclCXX11Matches( @@ -134,7 +138,20 @@ public: return PrintedDeclMatches(Code, Args, NodeMatch, - ExpectedPrinted); + ExpectedPrinted, + "input.cc"); +} + +::testing::AssertionResult PrintedDeclObjCMatches( + StringRef Code, + const DeclarationMatcher &NodeMatch, + StringRef ExpectedPrinted) { + std::vector Args(1, ""); + return PrintedDeclMatches(Code, + Args, + NodeMatch, + ExpectedPrinted, + "input.m"); } } // unnamed namespace @@ -1216,3 +1233,16 @@ TEST(DeclPrinter, TestTemplateArgumentList15) { // Should be: with semicolon, without extra space in "> >" } +TEST(DeclPrinter, TestObjCMethod1) { + ASSERT_TRUE(PrintedDeclObjCMatches( + "__attribute__((objc_root_class)) @interface X\n" + "- (int)A:(id)anObject inRange:(long)range;\n" + "@end\n" + "@implementation X\n" + "- (int)A:(id)anObject inRange:(long)range { int printThis; return 0; }\n" + "@end\n", + namedDecl(hasName("A:inRange:"), + hasDescendant(namedDecl(hasName("printThis")))).bind("id"), + "- (int) A:(id)anObject inRange:(long)range")); +} + -- 2.7.4