diff --git a/src/plugins/clangformat/clangformatplugin.cpp b/src/plugins/clangformat/clangformatplugin.cpp index 5d34be67200..2272d998e94 100644 --- a/src/plugins/clangformat/clangformatplugin.cpp +++ b/src/plugins/clangformat/clangformatplugin.cpp @@ -86,7 +86,7 @@ void ClangFormatPlugin::initialize() } #ifdef WITH_TESTS - addTest(); + addTestCreator(Internal::createClangFormatTest); #endif } diff --git a/src/plugins/clangformat/tests/clangformat-test.cpp b/src/plugins/clangformat/tests/clangformat-test.cpp index a4a85cf9065..51f78f90aff 100644 --- a/src/plugins/clangformat/tests/clangformat-test.cpp +++ b/src/plugins/clangformat/tests/clangformat-test.cpp @@ -35,6 +35,93 @@ private: bool formatWhileTyping() const override { return true; } }; +class ClangFormatTest final : public QObject +{ + Q_OBJECT + +public: + ClangFormatTest(); + ~ClangFormatTest(); + +private slots: + void testIndentBasicFile(); + void testIndentEmptyLine(); + void testIndentLambda(); + void testIndentNestedIfElse(); + void testIndentInitializerListInArguments(); + void testIndentLambdaWithReturnType(); + void testIndentFunctionArgumentLambdaWithNextLineScope(); + void testIndentScopeAsFunctionArgument(); + void testIndentInsideStructuredBinding(); + void testIndentMacrosWithoutSemicolon(); + void testIndentAfterSquareBracesInsideBraceInitialization(); + void testIndentStringLiteralContinuation(); + void testIndentTemplateparameters(); + void testNoExtraIndentAfterStatementInsideSquareBraces(); + void testNoExtraIndentAfterBraceInitialization(); + void testIndentMultipleEmptyLines(); + void testIndentEmptyLineAndKeepPreviousEmptyLines(); + void testIndentOnElectricCharacterButNotRemoveEmptyLinesBefore(); + void testIndentAfterExtraSpaceInpreviousLine(); + void testIndentEmptyLineInsideParentheses(); + void testIndentInsideIf(); + void testIndentInsideIf2(); + void testIndentInsideIf3(); + void testEmptyLineInInitializerList(); + void testIndentClosingBraceAfterComma(); + void testDoNotIndentClosingBraceAfterSemicolon(); + void testIndentAfterIf(); + void testIndentAfterElse(); + void testSameIndentAfterSecondNewLineAfterIf(); + void testIndentAfterNewLineInsideIfWithFunctionCall(); + void testSameIndentAfterSecondNewLineInsideIfWithFunctionCall(); + void testSameIndentAfterSecondNonEmptyNewLineInsideIfWithFunctionCall(); + void testSameIndentsOnNewLinesAfterComments(); + void testIndentAfterEmptyLineAfterAngledIncludeDirective(); + void testIndentAfterEmptyLineAfterQuotedIncludeDirective(); + void testIndentAfterLineComment(); + void testIndentAfterBlockComment(); + void testIndentAfterIfdef(); + void testIndentAfterEmptyLineInTheFileBeginning(); + void testIndentFunctionBodyButNotFormatBeforeIt(); + void testIndentAfterFunctionBodyAndNotFormatBefore(); + void testReformatToEmptyFunction(); + void testReformatToNonEmptyFunction(); + void testIndentClosingScopeAndFormatBeforeIt(); + void testDoNotFormatAfterTheFirstColon(); + void testOnlyIndentIncompleteStatementOnElectricalCharacter(); + void testIndentAndFormatCompleteStatementOnSemicolon(); + void testIndentAndFormatCompleteStatementOnClosingScope(); + void testOnlyIndentClosingParenthesis(); + void testEquallyIndentInsideParenthesis(); + void testFormatBasicFile(); + void testFormatEmptyLine(); + void testFormatLambda(); + void testFormatInitializerListInArguments(); + void testFormatFunctionArgumentLambdaWithScope(); + void testFormatScopeAsFunctionArgument(); + void testFormatStructuredBinding(); + void testFormatStringLiteralContinuation(); + void testFormatTemplateparameters(); + void testSortIncludes(); + void testChainedMemberFunctionCalls(); + void testCommentBlock(); + void testClassIndentStructure(); + void testIndentInitializeVector(); + void testIndentFunctionArgumentOnNewLine(); + void testIndentCommentOnNewLine(); + void testUtf8SymbolLine(); + +private: + void insertLines(const std::vector &lines); + std::vector documentLines() const; + + QTextDocument * const m_doc; + QTextCursor * const m_cursor; + ClangFormatBaseIndenter * const m_indenter; + ClangFormatBaseIndenter * const m_extendedIndenter; +}; + ClangFormatTest::ClangFormatTest() : m_doc(new QTextDocument(this)), m_cursor(new QTextCursor(m_doc)), @@ -746,4 +833,11 @@ void ClangFormatTest::testUtf8SymbolLine() "}"})); } +QObject *createClangFormatTest() +{ + return new ClangFormatTest; +} + } // namespace ClangFormat::Internal + +#include "clangformat-test.moc" diff --git a/src/plugins/clangformat/tests/clangformat-test.h b/src/plugins/clangformat/tests/clangformat-test.h index d1dba9a13f2..5d21f56fcc3 100644 --- a/src/plugins/clangformat/tests/clangformat-test.h +++ b/src/plugins/clangformat/tests/clangformat-test.h @@ -4,104 +4,9 @@ #pragma once #include -#include -QT_BEGIN_NAMESPACE -class QString; -class QTextCursor; -class QTextDocument; -QT_END_NAMESPACE +namespace ClangFormat::Internal { -namespace ClangFormat { -class ClangFormatBaseIndenter; +QObject *createClangFormatTest(); -namespace Internal { - -class ClangFormatTest : public QObject -{ - Q_OBJECT -public: - ClangFormatTest(); - ~ClangFormatTest(); - -private slots: - void testIndentBasicFile(); - void testIndentEmptyLine(); - void testIndentLambda(); - void testIndentNestedIfElse(); - void testIndentInitializerListInArguments(); - void testIndentLambdaWithReturnType(); - void testIndentFunctionArgumentLambdaWithNextLineScope(); - void testIndentScopeAsFunctionArgument(); - void testIndentInsideStructuredBinding(); - void testIndentMacrosWithoutSemicolon(); - void testIndentAfterSquareBracesInsideBraceInitialization(); - void testIndentStringLiteralContinuation(); - void testIndentTemplateparameters(); - void testNoExtraIndentAfterStatementInsideSquareBraces(); - void testNoExtraIndentAfterBraceInitialization(); - void testIndentMultipleEmptyLines(); - void testIndentEmptyLineAndKeepPreviousEmptyLines(); - void testIndentOnElectricCharacterButNotRemoveEmptyLinesBefore(); - void testIndentAfterExtraSpaceInpreviousLine(); - void testIndentEmptyLineInsideParentheses(); - void testIndentInsideIf(); - void testIndentInsideIf2(); - void testIndentInsideIf3(); - void testEmptyLineInInitializerList(); - void testIndentClosingBraceAfterComma(); - void testDoNotIndentClosingBraceAfterSemicolon(); - void testIndentAfterIf(); - void testIndentAfterElse(); - void testSameIndentAfterSecondNewLineAfterIf(); - void testIndentAfterNewLineInsideIfWithFunctionCall(); - void testSameIndentAfterSecondNewLineInsideIfWithFunctionCall(); - void testSameIndentAfterSecondNonEmptyNewLineInsideIfWithFunctionCall(); - void testSameIndentsOnNewLinesAfterComments(); - void testIndentAfterEmptyLineAfterAngledIncludeDirective(); - void testIndentAfterEmptyLineAfterQuotedIncludeDirective(); - void testIndentAfterLineComment(); - void testIndentAfterBlockComment(); - void testIndentAfterIfdef(); - void testIndentAfterEmptyLineInTheFileBeginning(); - void testIndentFunctionBodyButNotFormatBeforeIt(); - void testIndentAfterFunctionBodyAndNotFormatBefore(); - void testReformatToEmptyFunction(); - void testReformatToNonEmptyFunction(); - void testIndentClosingScopeAndFormatBeforeIt(); - void testDoNotFormatAfterTheFirstColon(); - void testOnlyIndentIncompleteStatementOnElectricalCharacter(); - void testIndentAndFormatCompleteStatementOnSemicolon(); - void testIndentAndFormatCompleteStatementOnClosingScope(); - void testOnlyIndentClosingParenthesis(); - void testEquallyIndentInsideParenthesis(); - void testFormatBasicFile(); - void testFormatEmptyLine(); - void testFormatLambda(); - void testFormatInitializerListInArguments(); - void testFormatFunctionArgumentLambdaWithScope(); - void testFormatScopeAsFunctionArgument(); - void testFormatStructuredBinding(); - void testFormatStringLiteralContinuation(); - void testFormatTemplateparameters(); - void testSortIncludes(); - void testChainedMemberFunctionCalls(); - void testCommentBlock(); - void testClassIndentStructure(); - void testIndentInitializeVector(); - void testIndentFunctionArgumentOnNewLine(); - void testIndentCommentOnNewLine(); - void testUtf8SymbolLine(); - -private: - void insertLines(const std::vector &lines); - std::vector documentLines() const; - - QTextDocument * const m_doc; - QTextCursor * const m_cursor; - ClangFormatBaseIndenter * const m_indenter; - ClangFormatBaseIndenter * const m_extendedIndenter; -}; - -} // namespace Internal -} // namespace ClangFormat +} // ClangFormat::Internal