forked from qt-creator/qt-creator
TextEditor: Move test creation closer to tested code
Change-Id: I0f132dddd405bf17161e0e032f9496a90cdc5ab9 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -43,10 +43,10 @@ public:
|
||||
quint64 hash() const override { return 0; } // used to remove duplicates
|
||||
};
|
||||
|
||||
class OpenEditorItem : public TestProposalItem
|
||||
class OpenEditorItem final : public TestProposalItem
|
||||
{
|
||||
public:
|
||||
void apply(TextDocumentManipulatorInterface &, int) const override
|
||||
void apply(TextDocumentManipulatorInterface &, int) const final
|
||||
{
|
||||
m_openedEditor = Core::EditorManager::openEditor(m_filePath,
|
||||
Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
|
||||
@@ -56,10 +56,10 @@ public:
|
||||
Utils::FilePath m_filePath;
|
||||
};
|
||||
|
||||
class TestProposalWidget : public GenericProposalWidget
|
||||
class TestProposalWidget final : public GenericProposalWidget
|
||||
{
|
||||
public:
|
||||
void showProposal(const QString &prefix) override
|
||||
void showProposal(const QString &prefix) final
|
||||
{
|
||||
GenericProposalModelPtr proposalModel = model();
|
||||
if (proposalModel && proposalModel->size() == 1) {
|
||||
@@ -71,30 +71,34 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class TestProposal : public GenericProposal
|
||||
class TestProposal final : public GenericProposal
|
||||
{
|
||||
public:
|
||||
TestProposal(int pos, const QList<AssistProposalItemInterface *> &items)
|
||||
: GenericProposal(pos, items)
|
||||
{}
|
||||
IAssistProposalWidget *createWidget() const override { return new TestProposalWidget; }
|
||||
IAssistProposalWidget *createWidget() const final { return new TestProposalWidget; }
|
||||
};
|
||||
|
||||
class TestProcessor : public AsyncProcessor
|
||||
class TestProcessor final : public AsyncProcessor
|
||||
{
|
||||
public:
|
||||
TestProcessor(const QList<AssistProposalItemInterface *> &items)
|
||||
: m_items(items)
|
||||
{}
|
||||
IAssistProposal *performAsync() override
|
||||
{ return new TestProposal(interface()->position(), m_items); }
|
||||
|
||||
IAssistProposal *performAsync() final
|
||||
{
|
||||
return new TestProposal(interface()->position(), m_items);
|
||||
}
|
||||
|
||||
QList<AssistProposalItemInterface *> m_items;
|
||||
};
|
||||
|
||||
class TestProvider : public CompletionAssistProvider
|
||||
class TestProvider final : public CompletionAssistProvider
|
||||
{
|
||||
public:
|
||||
IAssistProcessor *createProcessor(const AssistInterface *assistInterface) const override
|
||||
IAssistProcessor *createProcessor(const AssistInterface *assistInterface) const final
|
||||
{
|
||||
Q_UNUSED(assistInterface);
|
||||
return new TestProcessor(m_items);
|
||||
@@ -102,6 +106,24 @@ public:
|
||||
QList<AssistProposalItemInterface *> m_items;
|
||||
};
|
||||
|
||||
|
||||
class CodeAssistTests final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
|
||||
void testFollowSymbolBigFile();
|
||||
|
||||
void cleanupTestCase();
|
||||
|
||||
private:
|
||||
TextEditor::BaseTextEditor *m_editor = nullptr;
|
||||
QList<Core::IEditor *> m_editorsToClose;
|
||||
TestProvider *m_testProvider = nullptr;
|
||||
};
|
||||
|
||||
void CodeAssistTests::initTestCase()
|
||||
{
|
||||
Core::IEditor *editor = Core::EditorManager::openEditorWithContents(
|
||||
@@ -147,6 +169,13 @@ void CodeAssistTests::cleanupTestCase()
|
||||
QVERIFY(Core::EditorManager::currentEditor() == nullptr);
|
||||
}
|
||||
|
||||
QObject *createCodeAssistTests()
|
||||
{
|
||||
return new CodeAssistTests;
|
||||
}
|
||||
|
||||
} // namespace TextEditor::Internal
|
||||
|
||||
#include "codeassist_test.moc"
|
||||
|
||||
#endif // ifdef WITH_TESTS
|
||||
|
@@ -7,31 +7,10 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace Core { class IEditor; }
|
||||
namespace TextEditor { class BaseTextEditor; }
|
||||
|
||||
namespace TextEditor::Internal {
|
||||
|
||||
class TestProvider;
|
||||
QObject *createCodeAssistTests();
|
||||
|
||||
class CodeAssistTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
} // TextEditor::Internal
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
|
||||
void testFollowSymbolBigFile();
|
||||
|
||||
void cleanupTestCase();
|
||||
|
||||
private:
|
||||
TextEditor::BaseTextEditor *m_editor = nullptr;
|
||||
QList<Core::IEditor *> m_editorsToClose;
|
||||
TestProvider *m_testProvider = nullptr;
|
||||
};
|
||||
|
||||
} // namespace TextEditor::Internal
|
||||
|
||||
#endif
|
||||
#endif // WITH_TESTS
|
||||
|
@@ -34,6 +34,22 @@ constexpr auto json = R"(
|
||||
}
|
||||
)";
|
||||
|
||||
class GenerigHighlighterTests final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void testHighlight_data();
|
||||
void testHighlight();
|
||||
void testChange();
|
||||
void testPreeditText();
|
||||
void cleanupTestCase();
|
||||
|
||||
private:
|
||||
BaseTextEditor *m_editor = nullptr;
|
||||
};
|
||||
|
||||
void GenerigHighlighterTests::initTestCase()
|
||||
{
|
||||
QString title = "test.json";
|
||||
@@ -221,4 +237,11 @@ void GenerigHighlighterTests::cleanupTestCase()
|
||||
QVERIFY(Core::EditorManager::currentEditor() == nullptr);
|
||||
}
|
||||
|
||||
QObject *createGenericHighlighterTests()
|
||||
{
|
||||
return new GenerigHighlighterTests;
|
||||
}
|
||||
|
||||
} // namespace TextEditor::Internal
|
||||
|
||||
#include "highlighter_test.moc"
|
||||
|
@@ -5,23 +5,8 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace TextEditor { class BaseTextEditor; }
|
||||
|
||||
namespace TextEditor::Internal {
|
||||
|
||||
class GenerigHighlighterTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void testHighlight_data();
|
||||
void testHighlight();
|
||||
void testChange();
|
||||
void testPreeditText();
|
||||
void cleanupTestCase();
|
||||
QObject *createGenericHighlighterTests();
|
||||
|
||||
private:
|
||||
TextEditor::BaseTextEditor *m_editor = nullptr;
|
||||
};
|
||||
|
||||
} // namespace TextEditor::Internal
|
||||
} // TextEditor::Internal
|
||||
|
@@ -177,8 +177,8 @@ void TextEditorPlugin::initialize()
|
||||
d->createStandardContextMenu();
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
addTest<CodeAssistTests>();
|
||||
addTest<GenerigHighlighterTests>();
|
||||
addTestCreator(createCodeAssistTests);
|
||||
addTestCreator(createGenericHighlighterTests);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user