diff --git a/src/plugins/texteditor/CMakeLists.txt b/src/plugins/texteditor/CMakeLists.txt index 939c313712b..b13823b6ce1 100644 --- a/src/plugins/texteditor/CMakeLists.txt +++ b/src/plugins/texteditor/CMakeLists.txt @@ -119,7 +119,10 @@ add_qtc_plugin(TextEditor extend_qtc_plugin(TextEditor CONDITION WITH_TESTS SOURCES - codeassist/codeassist_test.cpp codeassist/codeassist_test.h - highlighter_test.cpp highlighter_test.h + codeassist/codeassist_test.cpp + codeassist/codeassist_test.h + highlighter_test.cpp + highlighter_test.h texteditor_test.cpp + texteditor_test.h ) diff --git a/src/plugins/texteditor/formattexteditor.cpp b/src/plugins/texteditor/formattexteditor.cpp index 03de5fb4152..98fb1a36355 100644 --- a/src/plugins/texteditor/formattexteditor.cpp +++ b/src/plugins/texteditor/formattexteditor.cpp @@ -329,12 +329,21 @@ void formatEditorAsync(TextEditorWidget *editor, const Command &command, int sta } // namespace TextEditor #ifdef WITH_TESTS -#include "texteditorplugin.h" + #include namespace TextEditor::Internal { -void TextEditorPlugin::testFormatting_data() +class FormatTextTest final : public QObject +{ + Q_OBJECT + +private slots: + void testFormatting_data(); + void testFormatting(); +}; + +void FormatTextTest::testFormatting_data() { QTest::addColumn("code"); QTest::addColumn("result"); @@ -360,7 +369,7 @@ void TextEditorPlugin::testFormatting_data() } } -void TextEditorPlugin::testFormatting() +void FormatTextTest::testFormatting() { QFETCH(QString, code); QFETCH(QString, result); @@ -377,6 +386,13 @@ void TextEditorPlugin::testFormatting() QCOMPARE(editor->toPlainText(), result); } +QObject *createFormatTextTest() +{ + return new FormatTextTest; +} + } // namespace TextEditor::Internal -#endif +#include "formattexteditor.moc" + +#endif // WITH_TESTS diff --git a/src/plugins/texteditor/snippets/snippet.cpp b/src/plugins/texteditor/snippets/snippet.cpp index 0b3bd080e7a..067888523bc 100644 --- a/src/plugins/texteditor/snippets/snippet.cpp +++ b/src/plugins/texteditor/snippets/snippet.cpp @@ -272,13 +272,10 @@ SnippetParseResult Snippet::parse(const QString &snippet) } // Texteditor -using namespace TextEditor; #ifdef WITH_TESTS # include -# include "../texteditorplugin.h" - const char NOMANGLER_ID[] = "TextEditor::NoMangler"; struct SnippetPart @@ -297,9 +294,20 @@ struct SnippetPart }; Q_DECLARE_METATYPE(SnippetPart); +namespace TextEditor::Internal { + using Parts = QList; -void Internal::TextEditorPlugin::testSnippetParsing_data() +class SnippetParserTest final : public QObject +{ + Q_OBJECT + +public slots: + void testSnippetParsing_data(); + void testSnippetParsing(); +}; + +void SnippetParserTest::testSnippetParsing_data() { QTest::addColumn("input"); QTest::addColumn("success"); @@ -384,7 +392,7 @@ void Internal::TextEditorPlugin::testSnippetParsing_data() }; } -void Internal::TextEditorPlugin::testSnippetParsing() +void SnippetParserTest::testSnippetParsing() { QFETCH(QString, input); QFETCH(bool, success); @@ -407,4 +415,14 @@ void Internal::TextEditorPlugin::testSnippetParsing() for (int i = 0; i < parts.size(); ++i) rangesCompare(snippet.parts.at(i), parts.at(i)); } -#endif + +QObject *createSnippetParserTest() +{ + return new SnippetParserTest; +} + +} // TextEditor::Internal + +#include "snippet.moc" + +#endif // WITH_TESTS diff --git a/src/plugins/texteditor/textdocumentlayout.cpp b/src/plugins/texteditor/textdocumentlayout.cpp index 6b98673bf85..1eb18c51f51 100644 --- a/src/plugins/texteditor/textdocumentlayout.cpp +++ b/src/plugins/texteditor/textdocumentlayout.cpp @@ -1,19 +1,15 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#include "textdocumentlayout.h" #include "fontsettings.h" #include "textdocument.h" -#include "texteditorplugin.h" +#include "textdocumentlayout.h" #include "texteditorsettings.h" #include #include #include -#ifdef WITH_TESTS -#include -#endif namespace TextEditor { @@ -871,9 +867,24 @@ TextSuggestion::TextSuggestion() TextSuggestion::~TextSuggestion() = default; +} // TextEditor + + #ifdef WITH_TESTS -void Internal::TextEditorPlugin::testDeletingMarkOnReload() +#include + +namespace TextEditor::Internal { + +class TextDocumentLayoutTest final : public QObject +{ + Q_OBJECT + +private slots: + void testDeletingMarkOnReload(); +}; + +void TextDocumentLayoutTest::testDeletingMarkOnReload() { auto doc = new TextDocument(); doc->setFilePath(Utils::TemporaryDirectory::masterDirectoryFilePath() / "TestMarkDoc.txt"); @@ -888,6 +899,13 @@ void Internal::TextEditorPlugin::testDeletingMarkOnReload() QVERIFY(!doc->marks().contains(mark)); } -#endif +QObject *createTextDocumentTest() +{ + return new TextDocumentLayoutTest; +} -} // namespace TextEditor +} // TextEditor::Internal + +#include "textdocumentlayout.moc" + +#endif // WITH_TESTS diff --git a/src/plugins/texteditor/texteditor.qbs b/src/plugins/texteditor/texteditor.qbs index 4f64752c122..7bbe6716c85 100644 --- a/src/plugins/texteditor/texteditor.qbs +++ b/src/plugins/texteditor/texteditor.qbs @@ -238,6 +238,7 @@ QtcPlugin { "highlighter_test.cpp", "highlighter_test.h", "texteditor_test.cpp", + "texteditor_test.h", ] } } diff --git a/src/plugins/texteditor/texteditor_test.cpp b/src/plugins/texteditor/texteditor_test.cpp index 3b88ac5efb5..c82804ee992 100644 --- a/src/plugins/texteditor/texteditor_test.cpp +++ b/src/plugins/texteditor/texteditor_test.cpp @@ -4,14 +4,13 @@ #ifdef WITH_TESTS #include "tabsettings.h" -#include "texteditorplugin.h" #include #include -namespace TextEditor { +namespace TextEditor::Internal { -QString tabPolicyToString(TabSettings::TabPolicy policy) +static QString tabPolicyToString(TabSettings::TabPolicy policy) { switch (policy) { case TabSettings::SpacesOnlyTabPolicy: @@ -24,7 +23,7 @@ QString tabPolicyToString(TabSettings::TabPolicy policy) return QString(); } -QString continuationAlignBehaviorToString(TabSettings::ContinuationAlignBehavior behavior) +static QString continuationAlignBehaviorToString(TabSettings::ContinuationAlignBehavior behavior) { switch (behavior) { case TabSettings::NoContinuationAlign: @@ -37,13 +36,15 @@ QString continuationAlignBehaviorToString(TabSettings::ContinuationAlignBehavior return QString(); } -struct TabSettingsFlags{ +struct TabSettingsFlags +{ TabSettings::TabPolicy policy; TabSettings::ContinuationAlignBehavior behavior; }; using IsClean = std::function; -void generateTestRows(const QLatin1String &name, const QString &text, IsClean isClean) + +static void generateTestRows(const QLatin1String &name, const QString &text, IsClean isClean) { const QVector allPolicies = { TabSettings::SpacesOnlyTabPolicy, @@ -74,7 +75,16 @@ void generateTestRows(const QLatin1String &name, const QString &text, IsClean is } } -void Internal::TextEditorPlugin::testIndentationClean_data() +class TextEditorTest final : public QObject +{ + Q_OBJECT + +private slots: + void testIndentationClean_data(); + void testIndentationClean(); +}; + +void TextEditorTest::testIndentationClean_data() { QTest::addColumn("policy"); QTest::addColumn("behavior"); @@ -126,7 +136,7 @@ void Internal::TextEditorPlugin::testIndentationClean_data() }); } -void Internal::TextEditorPlugin::testIndentationClean() +void TextEditorTest::testIndentationClean() { // fetch test data QFETCH(TabSettings::TabPolicy, policy); @@ -142,6 +152,13 @@ void Internal::TextEditorPlugin::testIndentationClean() QCOMPARE(settings.isIndentationClean(block, indentSize), clean); } -} // namespace TextEditor +QObject *createTextEditorTest() +{ + return new TextEditorTest; +} -#endif // ifdef WITH_TESTS +} // TextEditor::Internal + +#include "texteditor_test.moc" + +#endif // WITH_TESTS diff --git a/src/plugins/texteditor/texteditor_test.h b/src/plugins/texteditor/texteditor_test.h new file mode 100644 index 00000000000..a1cf53bd596 --- /dev/null +++ b/src/plugins/texteditor/texteditor_test.h @@ -0,0 +1,15 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#pragma once + +#include + +namespace TextEditor::Internal { + +QObject *createTextEditorTest(); +QObject *createTextDocumentTest(); +QObject *createSnippetParserTest(); +QObject *createFormatTextTest(); + +} // TextEditor::Internal diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index 875d9f6e9ea..3091bdd17be 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -16,10 +16,12 @@ #include "markdowneditor.h" #include "outlinefactory.h" #include "plaintexteditorfactory.h" +#include "snippets/snippet.h" #include "snippets/snippetprovider.h" #include "tabsettings.h" #include "textdocument.h" #include "texteditor.h" +#include "texteditor_test.h" #include "texteditorconstants.h" #include "texteditorsettings.h" #include "texteditortr.h" @@ -283,6 +285,13 @@ TextEditorPlugin *TextEditorPlugin::instance() void TextEditorPlugin::initialize() { +#ifdef WITH_TESTS + addTestCreator(createFormatTextTest); + addTestCreator(createTextDocumentTest); + addTestCreator(createTextEditorTest); + addTestCreator(createSnippetParserTest); +#endif + setupOutlineFactory(); d = new TextEditorPluginPrivate; diff --git a/src/plugins/texteditor/texteditorplugin.h b/src/plugins/texteditor/texteditorplugin.h index f5725061950..1df73dcea9d 100644 --- a/src/plugins/texteditor/texteditorplugin.h +++ b/src/plugins/texteditor/texteditorplugin.h @@ -29,20 +29,6 @@ private: void extensionsInitialized() final; class TextEditorPluginPrivate *d = nullptr; - -#ifdef WITH_TESTS -private slots: - void testSnippetParsing_data(); - void testSnippetParsing(); - - void testIndentationClean_data(); - void testIndentationClean(); - - void testFormatting_data(); - void testFormatting(); - - void testDeletingMarkOnReload(); -#endif }; } // namespace Internal