ClangFormat: Move test creation out-of-sight

Change-Id: I6403f5e0ab4783075ff6e87299317dc1988140db
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2024-01-19 13:48:39 +01:00
parent 5f9b36b45a
commit f2fb88df2e
3 changed files with 98 additions and 99 deletions

View File

@@ -86,7 +86,7 @@ void ClangFormatPlugin::initialize()
}
#ifdef WITH_TESTS
addTest<Internal::ClangFormatTest>();
addTestCreator(Internal::createClangFormatTest);
#endif
}

View File

@@ -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<QString> &lines);
std::vector<QString> 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"

View File

@@ -4,104 +4,9 @@
#pragma once
#include <QObject>
#include <vector>
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<QString> &lines);
std::vector<QString> documentLines() const;
QTextDocument * const m_doc;
QTextCursor * const m_cursor;
ClangFormatBaseIndenter * const m_indenter;
ClangFormatBaseIndenter * const m_extendedIndenter;
};
} // namespace Internal
} // namespace ClangFormat
} // ClangFormat::Internal