diff options
author | Pirama Arumuga Nainar <pirama@google.com> | 2015-05-06 11:48:57 -0700 |
---|---|---|
committer | Pirama Arumuga Nainar <pirama@google.com> | 2015-05-06 11:48:57 -0700 |
commit | 58878f85ab89b13e9eea4af3ccf055e42c557bc8 (patch) | |
tree | 3bf522a2cb819d02935c537ee23c8604b9e3f807 /unittests | |
parent | 13cb65defa5e5c4578d83b4f3ca5bdfc08a4e06f (diff) | |
download | clang-58878f85ab89b13e9eea4af3ccf055e42c557bc8.tar.gz |
Update aosp/master clang for rebase to r235153
Change-Id: Ia94bbcb6da7c75b6e7c2afedd1001094d62a7324
Diffstat (limited to 'unittests')
24 files changed, 237 insertions, 149 deletions
diff --git a/unittests/AST/DeclPrinterTest.cpp b/unittests/AST/DeclPrinterTest.cpp index 9f179c4a3f..070b4daabb 100644 --- a/unittests/AST/DeclPrinterTest.cpp +++ b/unittests/AST/DeclPrinterTest.cpp @@ -44,7 +44,7 @@ class PrintMatch : public MatchFinder::MatchCallback { public: PrintMatch() : NumFoundDecls(0) {} - virtual void run(const MatchFinder::MatchResult &Result) { + void run(const MatchFinder::MatchResult &Result) override { const Decl *D = Result.Nodes.getDeclAs<Decl>("id"); if (!D || D->isImplicit()) return; diff --git a/unittests/AST/ExternalASTSourceTest.cpp b/unittests/AST/ExternalASTSourceTest.cpp index 0cfde74ccc..4f42dcf103 100644 --- a/unittests/AST/ExternalASTSourceTest.cpp +++ b/unittests/AST/ExternalASTSourceTest.cpp @@ -28,15 +28,15 @@ public: TestFrontendAction(ExternalASTSource *Source) : Source(Source) {} private: - virtual void ExecuteAction() { + void ExecuteAction() override { getCompilerInstance().getASTContext().setExternalSource(Source); getCompilerInstance().getASTContext().getTranslationUnitDecl() ->setHasExternalVisibleStorage(); return ASTFrontendAction::ExecuteAction(); } - virtual std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { + std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override { return llvm::make_unique<ASTConsumer>(); } @@ -67,8 +67,8 @@ TEST(ExternalASTSourceTest, FailedLookupOccursOnce) { struct TestSource : ExternalASTSource { TestSource(unsigned &Calls) : Calls(Calls) {} - bool FindExternalVisibleDeclsByName(const DeclContext*, - DeclarationName Name) { + bool FindExternalVisibleDeclsByName(const DeclContext *, + DeclarationName Name) override { if (Name.getAsString() == "j") ++Calls; return false; diff --git a/unittests/AST/MatchVerifier.h b/unittests/AST/MatchVerifier.h index e6593913b7..31932479ef 100644 --- a/unittests/AST/MatchVerifier.h +++ b/unittests/AST/MatchVerifier.h @@ -63,7 +63,7 @@ public: Language L); protected: - virtual void run(const MatchFinder::MatchResult &Result); + void run(const MatchFinder::MatchResult &Result) override; virtual void verify(const MatchFinder::MatchResult &Result, const NodeType &Node) {} @@ -166,7 +166,8 @@ public: } protected: - void verify(const MatchFinder::MatchResult &Result, const NodeType &Node) { + void verify(const MatchFinder::MatchResult &Result, + const NodeType &Node) override { SourceLocation Loc = getLocation(Node); unsigned Line = Result.SourceManager->getSpellingLineNumber(Loc); unsigned Column = Result.SourceManager->getSpellingColumnNumber(Loc); @@ -205,7 +206,8 @@ public: } protected: - void verify(const MatchFinder::MatchResult &Result, const NodeType &Node) { + void verify(const MatchFinder::MatchResult &Result, + const NodeType &Node) override { SourceRange R = getRange(Node); SourceLocation Begin = R.getBegin(); SourceLocation End = R.getEnd(); @@ -244,7 +246,7 @@ public: protected: void verify(const MatchFinder::MatchResult &Result, - const ast_type_traits::DynTypedNode &Node) { + const ast_type_traits::DynTypedNode &Node) override { std::string DumpStr; llvm::raw_string_ostream Dump(DumpStr); Node.dump(Dump, *Result.SourceManager); @@ -271,7 +273,7 @@ public: protected: void verify(const MatchFinder::MatchResult &Result, - const ast_type_traits::DynTypedNode &Node) { + const ast_type_traits::DynTypedNode &Node) override { std::string PrintStr; llvm::raw_string_ostream Print(PrintStr); Node.print(Print, Result.Context->getPrintingPolicy()); diff --git a/unittests/AST/NamedDeclPrinterTest.cpp b/unittests/AST/NamedDeclPrinterTest.cpp index f8fb98454b..cf97a0abf6 100644 --- a/unittests/AST/NamedDeclPrinterTest.cpp +++ b/unittests/AST/NamedDeclPrinterTest.cpp @@ -37,7 +37,7 @@ public: explicit PrintMatch(bool suppressUnwrittenScope) : NumFoundDecls(0), SuppressUnwrittenScope(suppressUnwrittenScope) {} - virtual void run(const MatchFinder::MatchResult &Result) { + void run(const MatchFinder::MatchResult &Result) override { const NamedDecl *ND = Result.Nodes.getNodeAs<NamedDecl>("id"); if (!ND) return; diff --git a/unittests/AST/SourceLocationTest.cpp b/unittests/AST/SourceLocationTest.cpp index c1f7b18143..a3fc9530ba 100644 --- a/unittests/AST/SourceLocationTest.cpp +++ b/unittests/AST/SourceLocationTest.cpp @@ -60,7 +60,7 @@ TEST(RangeVerifier, WrongRange) { class LabelDeclRangeVerifier : public RangeVerifier<LabelStmt> { protected: - virtual SourceRange getRange(const LabelStmt &Node) { + SourceRange getRange(const LabelStmt &Node) override { return Node.getDecl()->getSourceRange(); } }; @@ -110,8 +110,8 @@ TEST(MemberExpr, ImplicitMemberRange) { }
class MemberExprArrowLocVerifier : public RangeVerifier<MemberExpr> {
-protected:
- virtual SourceRange getRange(const MemberExpr &Node) {
+protected: + SourceRange getRange(const MemberExpr &Node) override { return Node.getOperatorLoc();
}
};
@@ -201,7 +201,7 @@ TEST(InitListExpr, VectorLiteralInitListParens) { class TemplateAngleBracketLocRangeVerifier : public RangeVerifier<TypeLoc> { protected: - virtual SourceRange getRange(const TypeLoc &Node) { + SourceRange getRange(const TypeLoc &Node) override { TemplateSpecializationTypeLoc T = Node.getUnqualifiedLoc().castAs<TemplateSpecializationTypeLoc>(); assert(!T.isNull()); @@ -226,7 +226,7 @@ TEST(CXXNewExpr, TypeParenRange) { class UnaryTransformTypeLocParensRangeVerifier : public RangeVerifier<TypeLoc> { protected: - virtual SourceRange getRange(const TypeLoc &Node) { + SourceRange getRange(const TypeLoc &Node) override { UnaryTransformTypeLoc T = Node.getUnqualifiedLoc().castAs<UnaryTransformTypeLoc>(); assert(!T.isNull()); diff --git a/unittests/AST/StmtPrinterTest.cpp b/unittests/AST/StmtPrinterTest.cpp index 541fb3df1d..b1fd2c1eb4 100644 --- a/unittests/AST/StmtPrinterTest.cpp +++ b/unittests/AST/StmtPrinterTest.cpp @@ -44,7 +44,7 @@ class PrintMatch : public MatchFinder::MatchCallback { public: PrintMatch() : NumFoundStmts(0) {} - virtual void run(const MatchFinder::MatchResult &Result) { + void run(const MatchFinder::MatchResult &Result) override { const Stmt *S = Result.Nodes.getStmtAs<Stmt>("id"); if (!S) return; diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 7edec96c0f..4b0580a814 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -747,12 +747,12 @@ public: Name.clear(); } - ~VerifyIdIsBoundTo() { + ~VerifyIdIsBoundTo() override { EXPECT_EQ(0, Count); EXPECT_EQ("", Name); } - virtual bool run(const BoundNodes *Nodes) override { + bool run(const BoundNodes *Nodes) override { const BoundNodes::IDToNodeMap &M = Nodes->getMap(); if (Nodes->getNodeAs<T>(Id)) { ++Count; @@ -774,7 +774,7 @@ public: return false; } - virtual bool run(const BoundNodes *Nodes, ASTContext *Context) override { + bool run(const BoundNodes *Nodes, ASTContext *Context) override { return run(Nodes); } @@ -4379,9 +4379,9 @@ public: : Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) { } - virtual bool run(const BoundNodes *Nodes) { return false; } + bool run(const BoundNodes *Nodes) override { return false; } - virtual bool run(const BoundNodes *Nodes, ASTContext *Context) { + bool run(const BoundNodes *Nodes, ASTContext *Context) override { const T *Node = Nodes->getNodeAs<T>(Id); return selectFirst<T>(InnerId, match(InnerMatcher, *Node, *Context)) != nullptr; @@ -4430,9 +4430,9 @@ TEST(MatchFinder, CanMatchSingleNodesRecursively) { template <typename T> class VerifyAncestorHasChildIsEqual : public BoundNodesCallback { public: - virtual bool run(const BoundNodes *Nodes) { return false; } + bool run(const BoundNodes *Nodes) override { return false; } - virtual bool run(const BoundNodes *Nodes, ASTContext *Context) { + bool run(const BoundNodes *Nodes, ASTContext *Context) override { const T *Node = Nodes->getNodeAs<T>(""); return verify(*Nodes, *Context, Node); } @@ -4488,12 +4488,10 @@ TEST(MatchFinder, CheckProfiling) { class VerifyStartOfTranslationUnit : public MatchFinder::MatchCallback { public: VerifyStartOfTranslationUnit() : Called(false) {} - virtual void run(const MatchFinder::MatchResult &Result) { + void run(const MatchFinder::MatchResult &Result) override { EXPECT_TRUE(Called); } - virtual void onStartOfTranslationUnit() { - Called = true; - } + void onStartOfTranslationUnit() override { Called = true; } bool Called; }; @@ -4516,12 +4514,10 @@ TEST(MatchFinder, InterceptsStartOfTranslationUnit) { class VerifyEndOfTranslationUnit : public MatchFinder::MatchCallback { public: VerifyEndOfTranslationUnit() : Called(false) {} - virtual void run(const MatchFinder::MatchResult &Result) { + void run(const MatchFinder::MatchResult &Result) override { EXPECT_FALSE(Called); } - virtual void onEndOfTranslationUnit() { - Called = true; - } + void onEndOfTranslationUnit() override { Called = true; } bool Called; }; diff --git a/unittests/ASTMatchers/ASTMatchersTest.h b/unittests/ASTMatchers/ASTMatchersTest.h index 4befe4a129..e555e6318d 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.h +++ b/unittests/ASTMatchers/ASTMatchersTest.h @@ -40,7 +40,7 @@ public: VerifyMatch(BoundNodesCallback *FindResultVerifier, bool *Verified) : Verified(Verified), FindResultReviewer(FindResultVerifier) {} - virtual void run(const MatchFinder::MatchResult &Result) override { + void run(const MatchFinder::MatchResult &Result) override { if (FindResultReviewer != nullptr) { *Verified |= FindResultReviewer->run(&Result.Nodes, Result.Context); } else { diff --git a/unittests/ASTMatchers/Dynamic/ParserTest.cpp b/unittests/ASTMatchers/Dynamic/ParserTest.cpp index 2a9a61b543..5e6cadd196 100644 --- a/unittests/ASTMatchers/Dynamic/ParserTest.cpp +++ b/unittests/ASTMatchers/Dynamic/ParserTest.cpp @@ -23,7 +23,7 @@ namespace { class MockSema : public Parser::Sema { public: - virtual ~MockSema() {} + ~MockSema() override {} uint64_t expectMatcher(StringRef MatcherName) { // Optimizations on the matcher framework make simple matchers like @@ -42,7 +42,8 @@ public: Errors.push_back(Error.toStringFull()); } - llvm::Optional<MatcherCtor> lookupMatcherCtor(StringRef MatcherName) { + llvm::Optional<MatcherCtor> + lookupMatcherCtor(StringRef MatcherName) override { const ExpectedMatchersTy::value_type *Matcher = &*ExpectedMatchers.find(MatcherName); return reinterpret_cast<MatcherCtor>(Matcher); @@ -52,7 +53,7 @@ public: const SourceRange &NameRange, StringRef BindID, ArrayRef<ParserValue> Args, - Diagnostics *Error) { + Diagnostics *Error) override { const ExpectedMatchersTy::value_type *Matcher = reinterpret_cast<const ExpectedMatchersTy::value_type *>(Ctor); MatcherInfo ToStore = { Matcher->first, NameRange, Args, BindID }; diff --git a/unittests/Basic/SourceManagerTest.cpp b/unittests/Basic/SourceManagerTest.cpp index 1dda54dff1..57b87b7604 100644 --- a/unittests/Basic/SourceManagerTest.cpp +++ b/unittests/Basic/SourceManagerTest.cpp @@ -257,15 +257,15 @@ class MacroTracker : public PPCallbacks { public: explicit MacroTracker(std::vector<MacroAction> &Macros) : Macros(Macros) { } - - virtual void MacroDefined(const Token &MacroNameTok, - const MacroDirective *MD) { + + void MacroDefined(const Token &MacroNameTok, + const MacroDirective *MD) override { Macros.push_back(MacroAction(MD->getLocation(), MacroNameTok.getIdentifierInfo()->getName(), true)); } - virtual void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD, - SourceRange Range, const MacroArgs *Args) { + void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD, + SourceRange Range, const MacroArgs *Args) override { Macros.push_back(MacroAction(MacroNameTok.getLocation(), MacroNameTok.getIdentifierInfo()->getName(), false)); diff --git a/unittests/Basic/VirtualFileSystemTest.cpp b/unittests/Basic/VirtualFileSystemTest.cpp index 67beb923d9..71d2d2b60c 100644 --- a/unittests/Basic/VirtualFileSystemTest.cpp +++ b/unittests/Basic/VirtualFileSystemTest.cpp @@ -521,9 +521,7 @@ class VFSFromYAMLTest : public ::testing::Test { public: int NumDiagnostics; - void SetUp() { - NumDiagnostics = 0; - } + void SetUp() override { NumDiagnostics = 0; } static void CountingDiagHandler(const SMDiagnostic &, void *Context) { VFSFromYAMLTest *Test = static_cast<VFSFromYAMLTest *>(Context); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 287ece17e5..9791e2a5fb 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -812,9 +812,11 @@ TEST_F(FormatTest, FormatsLabels) { " some_more_code();\n" " }\n" "}"); - verifyFormat("some_code();\n" + verifyFormat("{\n" + " some_code();\n" "test_label:\n" - "some_other_code();"); + " some_other_code();\n" + "}"); } //===----------------------------------------------------------------------===// @@ -1895,6 +1897,8 @@ TEST_F(FormatTest, UnderstandsAccessSpecifiers) { " void f() {}\n" "public Q_SLOTS:\n" " void f() {}\n" + "signals:\n" + " void g();\n" "};"); } @@ -2143,6 +2147,12 @@ TEST_F(FormatTest, FormatsBitfields) { " int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa : 1,\n" " bbbbbbbbbbbbbbbbbbbbbbbbb;\n" "};"); + verifyFormat("struct MyStruct {\n" + " uchar data;\n" + " uchar : 8;\n" + " uchar : 8;\n" + " uchar other;\n" + "};"); } TEST_F(FormatTest, FormatsNamespaces) { @@ -3048,35 +3058,38 @@ TEST_F(FormatTest, FormatsJoinedLinesOnSubsequentRuns) { } TEST_F(FormatTest, LayoutBlockInsideParens) { - EXPECT_EQ("functionCall({ int i; });", format(" functionCall ( {int i;} );")); - EXPECT_EQ("functionCall({\n" - " int i;\n" - " int j;\n" - "});", - format(" functionCall ( {int i;int j;} );")); - EXPECT_EQ("functionCall({\n" - " int i;\n" - " int j;\n" - "}, aaaa, bbbb, cccc);", - format(" functionCall ( {int i;int j;}, aaaa, bbbb, cccc);")); - EXPECT_EQ("functionCall(\n" - " {\n" - " int i;\n" - " int j;\n" - " },\n" - " aaaa, bbbb, // comment\n" - " cccc);", - format(" functionCall ( {int i;int j;}, aaaa, bbbb, // comment\n" - "cccc);")); - EXPECT_EQ("functionCall(aaaa, bbbb, { int i; });", - format(" functionCall (aaaa, bbbb, {int i;});")); - EXPECT_EQ("functionCall(aaaa, bbbb, {\n" - " int i;\n" - " int j;\n" - "});", - format(" functionCall (aaaa, bbbb, {int i;int j;});")); - EXPECT_EQ("functionCall(aaaa, bbbb, { int i; });", - format(" functionCall (aaaa, bbbb, {int i;});")); + verifyFormat("functionCall({ int i; });"); + verifyFormat("functionCall({\n" + " int i;\n" + " int j;\n" + "});"); + verifyFormat("functionCall({\n" + " int i;\n" + " int j;\n" + "}, aaaa, bbbb, cccc);"); + verifyFormat("functionA(functionB({\n" + " int i;\n" + " int j;\n" + " }),\n" + " aaaa, bbbb, cccc);"); + verifyFormat("functionCall(\n" + " {\n" + " int i;\n" + " int j;\n" + " },\n" + " aaaa, bbbb, // comment\n" + " cccc);"); + verifyFormat("functionA(functionB({\n" + " int i;\n" + " int j;\n" + " }),\n" + " aaaa, bbbb, // comment\n" + " cccc);"); + verifyFormat("functionCall(aaaa, bbbb, { int i; });"); + verifyFormat("functionCall(aaaa, bbbb, {\n" + " int i;\n" + " int j;\n" + "});"); verifyFormat( "Aaa(\n" // FIXME: There shouldn't be a linebreak here. " {\n" @@ -4085,7 +4098,7 @@ TEST_F(FormatTest, FormatsBuilderPattern) { " aaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa();"); verifyFormat( "aaaaaaa->aaaaaaa->aaaaaaaaaaaaaaaa(\n" - " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n" " ->aaaaaaaa(aaaaaaaaaaaaaaa);"); verifyFormat( "aaaaaaaaaaaaaaaaaaa()->aaaaaa(bbbbb)->aaaaaaaaaaaaaaaaaaa( // break\n" @@ -4094,7 +4107,7 @@ TEST_F(FormatTest, FormatsBuilderPattern) { "aaaaaaaaaaaaaaaaaaaaaaa *aaaaaaaaa =\n" " aaaaaa->aaaaaaaaaaaa()\n" " ->aaaaaaaaaaaaaaaa(\n" - " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n" " ->aaaaaaaaaaaaaaaaa();"); verifyGoogleFormat( "void f() {\n" @@ -6738,7 +6751,7 @@ TEST_F(FormatTest, FormatObjCInterface) { "+ (id)init;\n" "@end"); - verifyGoogleFormat("@interface Foo (HackStuff) <MyProtocol>\n" + verifyGoogleFormat("@interface Foo (HackStuff)<MyProtocol>\n" "+ (id)init;\n" "@end"); @@ -6780,7 +6793,7 @@ TEST_F(FormatTest, FormatObjCInterface) { FormatStyle OnePerLine = getGoogleStyle(); OnePerLine.BinPackParameters = false; - verifyFormat("@interface aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa () <\n" + verifyFormat("@interface aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ()<\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" @@ -6985,6 +6998,11 @@ TEST_F(FormatTest, FormatObjCMethodExpr) { verifyFormat("return in[42];"); verifyFormat("for (auto v : in[1]) {\n}"); + verifyFormat("for (int i = 0; i < in[a]; ++i) {\n}"); + verifyFormat("for (int i = 0; in[a] < i; ++i) {\n}"); + verifyFormat("for (int i = 0; i < n; ++i, ++in[a]) {\n}"); + verifyFormat("for (int i = 0; i < n; ++i, in[a]++) {\n}"); + verifyFormat("for (int i = 0; i < f(in[a]); ++i, in[a]++) {\n}"); verifyFormat("for (id foo in [self getStuffFor:bla]) {\n" "}"); verifyFormat("[self aaaaa:MACRO(a, b:, c:)];"); diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 5707024544..695bad5553 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -144,6 +144,35 @@ TEST_F(FormatTestJS, ContainerLiterals) { verifyFormat("x = foo && {a: 123};"); } +TEST_F(FormatTestJS, MethodsInObjectLiterals) { + verifyFormat("var o = {\n" + " value: 'test',\n" + " get value() { // getter\n" + " return this.value;\n" + " }\n" + "};"); + verifyFormat("var o = {\n" + " value: 'test',\n" + " set value(val) { // setter\n" + " this.value = val;\n" + " }\n" + "};"); + verifyFormat("var o = {\n" + " value: 'test',\n" + " someMethod(val) { // method\n" + " doSomething(this.value + val);\n" + " }\n" + "};"); + verifyFormat("var o = {\n" + " someMethod(val) { // method\n" + " doSomething(this.value + val);\n" + " },\n" + " someOtherMethod(val) { // method\n" + " doSomething(this.value + val);\n" + " }\n" + "};"); +} + TEST_F(FormatTestJS, SpacesInContainerLiterals) { verifyFormat("var arr = [1, 2, 3];"); verifyFormat("f({a: 1, b: 2, c: 3});"); @@ -167,6 +196,11 @@ TEST_F(FormatTestJS, GoogScopes) { "var x = a.b;\n" "var y = c.d;\n" "}); // goog.scope"); + verifyFormat("goog.scope(function() {\n" + "// test\n" + "var x = 0;\n" + "// test\n" + "});"); } TEST_F(FormatTestJS, GoogModules) { @@ -374,10 +408,9 @@ TEST_F(FormatTestJS, MultipleFunctionLiterals) { " body();\n" " });"); - // FIXME: This is bad, but it used to be formatted correctly by accident. - verifyFormat("getSomeLongPromise().then(function(value) {\n" - " body();\n" - "}).thenCatch(function(error) { body(); });"); + verifyFormat("getSomeLongPromise()\n" + " .then(function(value) { body(); })\n" + " .thenCatch(function(error) { body(); });"); } TEST_F(FormatTestJS, ReturnStatements) { @@ -511,6 +544,7 @@ TEST_F(FormatTestJS, ClassDeclarations) { verifyFormat("class C {\n private static x: string = 12;\n}"); verifyFormat("class C {\n static x(): string { return 'asd'; }\n}"); verifyFormat("class C extends P implements I {}"); + verifyFormat("class C extends p.P implements i.I {}"); } TEST_F(FormatTestJS, MetadataAnnotations) { @@ -614,6 +648,33 @@ TEST_F(FormatTestJS, TemplateStrings) { // Two template strings. verifyFormat("var x = `hello` == `hello`;"); + + // Comments in template strings. + EXPECT_EQ("var x = `//a`;\n" + "var y;", + format("var x =\n `//a`;\n" + "var y ;")); + EXPECT_EQ("var x = `/*a`;\n" + "var y;", + format("var x =\n `/*a`;\n" + "var y;")); + // Backticks in a comment - not a template string. + EXPECT_EQ("var x = 1 // `/*a`;\n" + " ;", + format("var x =\n 1 // `/*a`;\n" + " ;")); + EXPECT_EQ("/* ` */ var x = 1; /* ` */", + format("/* ` */ var x\n= 1; /* ` */")); + // Comment spans multiple template strings. + EXPECT_EQ("var x = `/*a`;\n" + "var y = ` */ `;", + format("var x =\n `/*a`;\n" + "var y =\n ` */ `;")); + // Escaped backtick. + EXPECT_EQ("var x = ` \\` a`;\n" + "var y;", + format("var x = ` \\` a`;\n" + "var y;")); } TEST_F(FormatTestJS, CastSyntax) { @@ -628,5 +689,17 @@ TEST_F(FormatTestJS, TypeArguments) { verifyFormat("class C extends D<E> implements F<G>, H<I> {}"); } +TEST_F(FormatTestJS, OptionalTypes) { + verifyFormat("function x(a?: b, c?, d?) {\n}"); + verifyFormat("class X {\n" + " y?: z;\n" + " z?;\n" + "}"); +} + +TEST_F(FormatTestJS, IndexSignature) { + verifyFormat("var x: {[k: string]: v};"); +} + } // end namespace tooling } // end namespace clang diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index 6e3f7efaf2..631a3dca27 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/unittests/Format/FormatTestJava.cpp @@ -433,7 +433,7 @@ TEST_F(FormatTestJava, NeverAlignAfterReturn) { getStyleWithColumns(40)); verifyFormat("return aaaaaaaaaaaaaaaaaaa()\n" " .bbbbbbbbbbbbbbbbbbb(\n" - " ccccccccccccccc)\n" + " ccccccccccccccc)\n" " .ccccccccccccccccccc();", getStyleWithColumns(40)); } diff --git a/unittests/Format/FormatTestProto.cpp b/unittests/Format/FormatTestProto.cpp index 3a2f97e875..d55fe8cf09 100644 --- a/unittests/Format/FormatTestProto.cpp +++ b/unittests/Format/FormatTestProto.cpp @@ -94,6 +94,11 @@ TEST_F(FormatTestProto, MessageFieldAttributes) { " bbbbbbbbbbbbbbbb: BBBBBBBBBB\n" "}];"); verifyFormat("repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {\n" + " type: \"AAAAAAAAAA\"\n" + " is: \"AAAAAAAAAA\"\n" + " or: \"BBBBBBBBBB\"\n" + "}];"); + verifyFormat("repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {\n" " aaaaaaaaaaaaaaaa: AAAAAAAAAA,\n" " bbbbbbb: BBBB,\n" " bbbb: BBB\n" diff --git a/unittests/Frontend/FrontendActionTest.cpp b/unittests/Frontend/FrontendActionTest.cpp index 5581c4487e..90afd774f1 100644 --- a/unittests/Frontend/FrontendActionTest.cpp +++ b/unittests/Frontend/FrontendActionTest.cpp @@ -35,15 +35,16 @@ public: bool ActOnEndOfTranslationUnit; std::vector<std::string> decl_names; - virtual bool BeginSourceFileAction(CompilerInstance &ci, StringRef filename) { + bool BeginSourceFileAction(CompilerInstance &ci, + StringRef filename) override { if (EnableIncrementalProcessing) ci.getPreprocessor().enableIncrementalProcessing(); return ASTFrontendAction::BeginSourceFileAction(ci, filename); } - virtual std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { + std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override { return llvm::make_unique<Visitor>(CI, ActOnEndOfTranslationUnit, decl_names); } @@ -56,7 +57,7 @@ private: CI(CI), ActOnEndOfTranslationUnit(ActOnEndOfTranslationUnit), decl_names_(decl_names) {} - virtual void HandleTranslationUnit(ASTContext &context) { + void HandleTranslationUnit(ASTContext &context) override { if (ActOnEndOfTranslationUnit) { CI.getSema().ActOnEndOfTranslationUnit(); } diff --git a/unittests/Lex/PPCallbacksTest.cpp b/unittests/Lex/PPCallbacksTest.cpp index bb27bac6ed..da641a7afb 100644 --- a/unittests/Lex/PPCallbacksTest.cpp +++ b/unittests/Lex/PPCallbacksTest.cpp @@ -54,15 +54,11 @@ class VoidModuleLoader : public ModuleLoader { // Stub to collect data from InclusionDirective callbacks. class InclusionDirectiveCallbacks : public PPCallbacks { public: - void InclusionDirective(SourceLocation HashLoc, - const Token &IncludeTok, - StringRef FileName, - bool IsAngled, - CharSourceRange FilenameRange, - const FileEntry *File, - StringRef SearchPath, - StringRef RelativePath, - const Module *Imported) { + void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, + StringRef FileName, bool IsAngled, + CharSourceRange FilenameRange, const FileEntry *File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported) override { this->HashLoc = HashLoc; this->IncludeTok = IncludeTok; this->FileName = FileName.str(); @@ -95,9 +91,10 @@ public: PragmaOpenCLExtensionCallbacks() : Name("Not called."), State(99) {}; - void PragmaOpenCLExtension( - clang::SourceLocation NameLoc, const clang::IdentifierInfo *Name, - clang::SourceLocation StateLoc, unsigned State) { + void PragmaOpenCLExtension(clang::SourceLocation NameLoc, + const clang::IdentifierInfo *Name, + clang::SourceLocation StateLoc, + unsigned State) override { this->NameLoc = NameLoc; this->Name = Name->getName(); this->StateLoc = StateLoc; diff --git a/unittests/Sema/ExternalSemaSourceTest.cpp b/unittests/Sema/ExternalSemaSourceTest.cpp index 3a93fc77fb..703e97b4ac 100644 --- a/unittests/Sema/ExternalSemaSourceTest.cpp +++ b/unittests/Sema/ExternalSemaSourceTest.cpp @@ -30,7 +30,7 @@ class CompleteTypeDiagnoser : public clang::ExternalSemaSource { public: CompleteTypeDiagnoser(bool MockResult) : CallCount(0), Result(MockResult) {} - virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation L, QualType T) { + bool MaybeDiagnoseMissingCompleteType(SourceLocation L, QualType T) override { ++CallCount; return Result; } @@ -54,8 +54,8 @@ public: ToNS.append("'"); } - virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, - const Diagnostic &Info) { + void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, + const Diagnostic &Info) override { if (Chained) Chained->HandleDiagnostic(DiagLevel, Info); if (Info.getID() - 1 == diag::err_using_directive_member_suggest) { @@ -66,13 +66,13 @@ public: } } - virtual void clear() { + void clear() override { DiagnosticConsumer::clear(); if (Chained) Chained->clear(); } - virtual bool IncludeInDiagnosticCounts() const { + bool IncludeInDiagnosticCounts() const override { if (Chained) return Chained->IncludeInDiagnosticCounts(); return false; @@ -97,16 +97,15 @@ public: NamespaceTypoProvider(StringRef From, StringRef To) : CorrectFrom(From), CorrectTo(To), CurrentSema(nullptr), CallCount(0) {} - virtual void InitializeSema(Sema &S) { CurrentSema = &S; } + void InitializeSema(Sema &S) override { CurrentSema = &S; } - virtual void ForgetSema() { CurrentSema = nullptr; } + void ForgetSema() override { CurrentSema = nullptr; } - virtual TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, - int LookupKind, Scope *S, CXXScopeSpec *SS, - CorrectionCandidateCallback &CCC, - DeclContext *MemberContext, - bool EnteringContext, - const ObjCObjectPointerType *OPT) { + TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, int LookupKind, + Scope *S, CXXScopeSpec *SS, + CorrectionCandidateCallback &CCC, + DeclContext *MemberContext, bool EnteringContext, + const ObjCObjectPointerType *OPT) override { ++CallCount; if (CurrentSema && Typo.getName().getAsString() == CorrectFrom) { DeclContext *DestContext = nullptr; @@ -140,13 +139,13 @@ class ExternalSemaSourceInstaller : public clang::ASTFrontendAction { std::unique_ptr<DiagnosticConsumer> OwnedClient; protected: - virtual std::unique_ptr<clang::ASTConsumer> + std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance &Compiler, - llvm::StringRef /* dummy */) { + llvm::StringRef /* dummy */) override { return llvm::make_unique<clang::ASTConsumer>(); } - virtual void ExecuteAction() { + void ExecuteAction() override { CompilerInstance &CI = getCompilerInstance(); ASSERT_FALSE(CI.hasSema()); CI.createSema(getTranslationUnitKind(), nullptr); diff --git a/unittests/Tooling/CommentHandlerTest.cpp b/unittests/Tooling/CommentHandlerTest.cpp index 117dfc36fe..da5604524c 100644 --- a/unittests/Tooling/CommentHandlerTest.cpp +++ b/unittests/Tooling/CommentHandlerTest.cpp @@ -30,11 +30,11 @@ class CommentHandlerVisitor : public TestVisitor<CommentHandlerVisitor>, public: CommentHandlerVisitor() : base(), PP(nullptr), Verified(false) {} - ~CommentHandlerVisitor() { + ~CommentHandlerVisitor() override { EXPECT_TRUE(Verified) << "CommentVerifier not accessed"; } - virtual bool HandleComment(Preprocessor &PP, SourceRange Loc) { + bool HandleComment(Preprocessor &PP, SourceRange Loc) override { assert(&PP == this->PP && "Preprocessor changed!"); SourceLocation Start = Loc.getBegin(); @@ -56,7 +56,7 @@ public: CommentVerifier GetVerifier(); protected: - virtual ASTFrontendAction* CreateTestAction() { + ASTFrontendAction *CreateTestAction() override { return new CommentHandlerAction(this); } @@ -70,8 +70,8 @@ private: CommentHandlerAction(CommentHandlerVisitor *Visitor) : TestAction(Visitor) { } - virtual bool BeginSourceFileAction(CompilerInstance &CI, - StringRef FileName) { + bool BeginSourceFileAction(CompilerInstance &CI, + StringRef FileName) override { CommentHandlerVisitor *V = static_cast<CommentHandlerVisitor*>(this->Visitor); V->PP = &CI.getPreprocessor(); @@ -79,7 +79,7 @@ private: return true; } - virtual void EndSourceFileAction() { + void EndSourceFileAction() override { CommentHandlerVisitor *V = static_cast<CommentHandlerVisitor*>(this->Visitor); V->PP->removeCommentHandler(V); diff --git a/unittests/Tooling/CompilationDatabaseTest.cpp b/unittests/Tooling/CompilationDatabaseTest.cpp index 8866e751fc..3e5a589caf 100644 --- a/unittests/Tooling/CompilationDatabaseTest.cpp +++ b/unittests/Tooling/CompilationDatabaseTest.cpp @@ -127,8 +127,8 @@ static CompileCommand findCompileArgsInJsonDatabase(StringRef FileName, } struct FakeComparator : public PathComparator { - virtual ~FakeComparator() {} - virtual bool equivalent(StringRef FileA, StringRef FileB) const { + ~FakeComparator() override {} + bool equivalent(StringRef FileA, StringRef FileB) const override { return FileA.equals_lower(FileB); } }; diff --git a/unittests/Tooling/RefactoringTest.cpp b/unittests/Tooling/RefactoringTest.cpp index a026a94261..7e643fa66d 100644 --- a/unittests/Tooling/RefactoringTest.cpp +++ b/unittests/Tooling/RefactoringTest.cpp @@ -213,7 +213,7 @@ class FlushRewrittenFilesTest : public ::testing::Test { public: FlushRewrittenFilesTest() {} - ~FlushRewrittenFilesTest() { + ~FlushRewrittenFilesTest() override { for (llvm::StringMap<std::string>::iterator I = TemporaryFiles.begin(), E = TemporaryFiles.end(); I != E; ++I) { @@ -287,7 +287,7 @@ private: public: FindConsumer(TestVisitor *Visitor) : Visitor(Visitor) {} - virtual void HandleTranslationUnit(clang::ASTContext &Context) { + void HandleTranslationUnit(clang::ASTContext &Context) override { Visitor->TraverseDecl(Context.getTranslationUnitDecl()); } @@ -299,9 +299,9 @@ private: public: TestAction(TestVisitor *Visitor) : Visitor(Visitor) {} - virtual std::unique_ptr<clang::ASTConsumer> + std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance &compiler, - llvm::StringRef dummy) { + llvm::StringRef dummy) override { Visitor->SM = &compiler.getSourceManager(); /// TestConsumer will be deleted by the framework calling us. return llvm::make_unique<FindConsumer>(Visitor); diff --git a/unittests/Tooling/TestVisitor.h b/unittests/Tooling/TestVisitor.h index d4416950f2..f4a0039448 100644 --- a/unittests/Tooling/TestVisitor.h +++ b/unittests/Tooling/TestVisitor.h @@ -82,7 +82,7 @@ protected: public: FindConsumer(TestVisitor *Visitor) : Visitor(Visitor) {} - virtual void HandleTranslationUnit(clang::ASTContext &Context) { + void HandleTranslationUnit(clang::ASTContext &Context) override { Visitor->Context = &Context; Visitor->TraverseDecl(Context.getTranslationUnitDecl()); } @@ -95,8 +95,8 @@ protected: public: TestAction(TestVisitor *Visitor) : Visitor(Visitor) {} - virtual std::unique_ptr<clang::ASTConsumer> - CreateASTConsumer(CompilerInstance &, llvm::StringRef dummy) { + std::unique_ptr<clang::ASTConsumer> + CreateASTConsumer(CompilerInstance &, llvm::StringRef dummy) override { /// TestConsumer will be deleted by the framework calling us. return llvm::make_unique<FindConsumer>(Visitor); } @@ -133,7 +133,7 @@ public: } /// \brief Checks that all expected matches have been found. - virtual ~ExpectedLocationVisitor() { + ~ExpectedLocationVisitor() override { for (typename std::vector<ExpectedMatch>::const_iterator It = ExpectedMatches.begin(), End = ExpectedMatches.end(); It != End; ++It) { diff --git a/unittests/Tooling/ToolingTest.cpp b/unittests/Tooling/ToolingTest.cpp index 5a93e38c80..4b14ebb2c3 100644 --- a/unittests/Tooling/ToolingTest.cpp +++ b/unittests/Tooling/ToolingTest.cpp @@ -35,8 +35,9 @@ public: : TestConsumer(std::move(TestConsumer)) {} protected: - virtual std::unique_ptr<clang::ASTConsumer> - CreateASTConsumer(clang::CompilerInstance &compiler, StringRef dummy) { + std::unique_ptr<clang::ASTConsumer> + CreateASTConsumer(clang::CompilerInstance &compiler, + StringRef dummy) override { /// TestConsumer will be deleted by the framework calling us. return std::move(TestConsumer); } @@ -49,7 +50,7 @@ class FindTopLevelDeclConsumer : public clang::ASTConsumer { public: explicit FindTopLevelDeclConsumer(bool *FoundTopLevelDecl) : FoundTopLevelDecl(FoundTopLevelDecl) {} - virtual bool HandleTopLevelDecl(clang::DeclGroupRef DeclGroup) { + bool HandleTopLevelDecl(clang::DeclGroupRef DeclGroup) override { *FoundTopLevelDecl = true; return true; } @@ -72,7 +73,7 @@ class FindClassDeclXConsumer : public clang::ASTConsumer { public: FindClassDeclXConsumer(bool *FoundClassDeclX) : FoundClassDeclX(FoundClassDeclX) {} - virtual bool HandleTopLevelDecl(clang::DeclGroupRef GroupRef) { + bool HandleTopLevelDecl(clang::DeclGroupRef GroupRef) override { if (CXXRecordDecl* Record = dyn_cast<clang::CXXRecordDecl>( *GroupRef.begin())) { if (Record->getName() == "X") { @@ -184,14 +185,11 @@ TEST(ToolInvocation, TestVirtualModulesCompilation) { struct VerifyEndCallback : public SourceFileCallbacks { VerifyEndCallback() : BeginCalled(0), EndCalled(0), Matched(false) {} - virtual bool handleBeginSource(CompilerInstance &CI, - StringRef Filename) override { + bool handleBeginSource(CompilerInstance &CI, StringRef Filename) override { ++BeginCalled; return true; } - virtual void handleEndSource() override { - ++EndCalled; - } + void handleEndSource() override { ++EndCalled; } std::unique_ptr<ASTConsumer> newASTConsumer() { return llvm::make_unique<FindTopLevelDeclConsumer>(&Matched); } @@ -225,15 +223,15 @@ TEST(newFrontendActionFactory, InjectsSourceFileCallbacks) { struct SkipBodyConsumer : public clang::ASTConsumer { /// Skip the 'skipMe' function. - virtual bool shouldSkipFunctionBody(Decl *D) { + bool shouldSkipFunctionBody(Decl *D) override { FunctionDecl *F = dyn_cast<FunctionDecl>(D); return F && F->getNameAsString() == "skipMe"; } }; struct SkipBodyAction : public clang::ASTFrontendAction { - virtual std::unique_ptr<ASTConsumer> - CreateASTConsumer(CompilerInstance &Compiler, StringRef) { + std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &Compiler, + StringRef) override { Compiler.getFrontendOpts().SkipFunctionBodies = true; return llvm::make_unique<SkipBodyConsumer>(); } @@ -312,8 +310,8 @@ TEST(ClangToolTest, BuildASTs) { struct TestDiagnosticConsumer : public DiagnosticConsumer { TestDiagnosticConsumer() : NumDiagnosticsSeen(0) {} - virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, - const Diagnostic &Info) { + void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, + const Diagnostic &Info) override { ++NumDiagnosticsSeen; } unsigned NumDiagnosticsSeen; diff --git a/unittests/libclang/LibclangTest.cpp b/unittests/libclang/LibclangTest.cpp index a21881429e..e827ebc0da 100644 --- a/unittests/libclang/LibclangTest.cpp +++ b/unittests/libclang/LibclangTest.cpp @@ -357,7 +357,7 @@ public: CXTranslationUnit ClangTU; unsigned TUFlags; - void SetUp() { + void SetUp() override { llvm::SmallString<256> Dir; ASSERT_FALSE(llvm::sys::fs::createUniqueDirectory("libclang-test", Dir)); TestDir = Dir.str(); @@ -365,7 +365,7 @@ public: clang_defaultEditingTranslationUnitOptions(); Index = clang_createIndex(0, 0); } - void TearDown() { + void TearDown() override { clang_disposeTranslationUnit(ClangTU); clang_disposeIndex(Index); for (const std::string &Path : Files) |