forked from qt-creator/qt-creator
fakevim: work on auto tests
This commit is contained in:
@@ -796,6 +796,7 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
|
||||
|
||||
void DebuggerPlugin::extensionsInitialized()
|
||||
{
|
||||
// time gdb -i mi -ex 'debuggerplugin.cpp:800' -ex r -ex q bin/qtcreator.bin
|
||||
}
|
||||
|
||||
/*! Activates the previous mode when the current mode is the debug mode. */
|
||||
|
||||
@@ -213,6 +213,7 @@ public:
|
||||
|
||||
EventResult handleEvent(QKeyEvent *ev);
|
||||
bool wantsOverride(QKeyEvent *ev);
|
||||
void handleCommand(const QString &cmd); // sets m_tc + handleExCommand
|
||||
void handleExCommand(const QString &cmd);
|
||||
|
||||
void installEventFilter();
|
||||
@@ -350,6 +351,7 @@ public:
|
||||
bool m_needMoreUndo;
|
||||
|
||||
// extra data for '.'
|
||||
void replay(const QString &text);
|
||||
QString m_dotCommand;
|
||||
bool m_inReplay; // true if we are executing a '.'
|
||||
|
||||
@@ -1007,11 +1009,7 @@ EventResult FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
|
||||
qDebug() << "REPEATING" << m_dotCommand;
|
||||
QString savedCommand = m_dotCommand;
|
||||
m_dotCommand.clear();
|
||||
m_inReplay = true;
|
||||
for (int i = count(); --i >= 0; )
|
||||
foreach (QChar c, savedCommand)
|
||||
handleKey(c.unicode(), c.unicode(), QString(c));
|
||||
m_inReplay = false;
|
||||
replay(savedCommand);
|
||||
enterCommandMode();
|
||||
m_dotCommand = savedCommand;
|
||||
} else if (key == '<' && m_visualMode == NoVisualMode) {
|
||||
@@ -1643,6 +1641,13 @@ void FakeVimHandler::Private::selectRange(int beginLine, int endLine)
|
||||
setPosition(firstPositionInLine(endLine + 1));
|
||||
}
|
||||
|
||||
void FakeVimHandler::Private::handleCommand(const QString &cmd)
|
||||
{
|
||||
m_tc = EDITOR(textCursor());
|
||||
handleExCommand(cmd);
|
||||
EDITOR(setTextCursor(m_tc));
|
||||
}
|
||||
|
||||
void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
|
||||
{
|
||||
QString cmd = cmd0;
|
||||
@@ -1665,10 +1670,11 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
|
||||
|
||||
//qDebug() << "RANGE: " << beginLine << endLine << cmd << cmd0 << m_marks;
|
||||
|
||||
static QRegExp reWrite("^w!?( (.*))?$");
|
||||
static QRegExp reDelete("^d( (.*))?$");
|
||||
static QRegExp reSet("^set?( (.*))?$");
|
||||
static QRegExp reHistory("^his(tory)?( (.*))?$");
|
||||
static QRegExp reNormal("^norm(al)?( (.*))?$");
|
||||
static QRegExp reSet("^set?( (.*))?$");
|
||||
static QRegExp reWrite("^w!?( (.*))?$");
|
||||
|
||||
if (cmd.isEmpty()) {
|
||||
setPosition(firstPositionInLine(beginLine));
|
||||
@@ -1769,6 +1775,9 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
|
||||
redo();
|
||||
enterCommandMode();
|
||||
updateMiniBuffer();
|
||||
} else if (reNormal.indexIn(cmd) != -1) { // :normal
|
||||
enterCommandMode();
|
||||
replay(reNormal.cap(3));
|
||||
} else if (reSet.indexIn(cmd) != -1) { // :set
|
||||
showBlackMessage(QString());
|
||||
QString arg = reSet.cap(2);
|
||||
@@ -2341,6 +2350,15 @@ void FakeVimHandler::Private::handleStartOfLine()
|
||||
moveToFirstNonBlankOnLine();
|
||||
}
|
||||
|
||||
void FakeVimHandler::Private::replay(const QString &command)
|
||||
{
|
||||
//qDebug() << "REPLAY: " << command;
|
||||
m_inReplay = true;
|
||||
for (int i = count(); --i >= 0; )
|
||||
foreach (QChar c, command)
|
||||
handleKey(c.unicode(), c.unicode(), QString(c));
|
||||
m_inReplay = false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -2403,7 +2421,7 @@ void FakeVimHandler::restoreWidget()
|
||||
|
||||
void FakeVimHandler::handleCommand(const QString &cmd)
|
||||
{
|
||||
d->handleExCommand(cmd);
|
||||
d->handleCommand(cmd);
|
||||
}
|
||||
|
||||
void FakeVimHandler::setCurrentFileName(const QString &fileName)
|
||||
|
||||
+150
-1
@@ -29,16 +29,165 @@
|
||||
|
||||
#include "fakevimhandler.h"
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
#include <QtCore/QSet>
|
||||
#include <QtGui/QPlainTextEdit>
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
using namespace FakeVim;
|
||||
using namespace FakeVim::Internal;
|
||||
|
||||
|
||||
class tst_FakeVim : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
tst_FakeVim();
|
||||
|
||||
void setup();
|
||||
void send(const QString &command); // send a normal command
|
||||
void sendEx(const QString &command); // send an ex command
|
||||
|
||||
QString cleaned(QString wanted) { wanted.remove('$'); return wanted; }
|
||||
|
||||
public slots:
|
||||
void changeStatusData(const QString &info) { m_statusData = info; }
|
||||
void changeStatusMessage(const QString &info) { m_statusMessage = info; }
|
||||
void changeExtraInformation(const QString &info) { m_infoMessage = info; }
|
||||
|
||||
public:
|
||||
QString m_statusMessage;
|
||||
QString m_statusData;
|
||||
QString m_infoMessage;
|
||||
|
||||
private slots:
|
||||
void commandI();
|
||||
void commandDollar();
|
||||
|
||||
private:
|
||||
QPlainTextEdit m_editor;
|
||||
FakeVimHandler m_handler;
|
||||
QList<QTextEdit::ExtraSelection> m_selection;
|
||||
|
||||
static const QString lines;
|
||||
static const QString escape;
|
||||
};
|
||||
|
||||
const QString tst_FakeVim::lines =
|
||||
"\n"
|
||||
"#include <QtCore>\n"
|
||||
"#include <QtGui>\n"
|
||||
"\n"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
"{\n"
|
||||
" QApplication app(argc, argv);\n"
|
||||
"\n"
|
||||
" return app.exec();\n"
|
||||
"}\n";
|
||||
|
||||
const QString tst_FakeVim::escape = QChar(27);
|
||||
|
||||
tst_FakeVim::tst_FakeVim()
|
||||
: m_handler(&m_editor, this)
|
||||
{
|
||||
|
||||
QObject::connect(&m_handler, SIGNAL(commandBufferChanged(QString)),
|
||||
this, SLOT(changeStatusMessage(QString)));
|
||||
QObject::connect(&m_handler, SIGNAL(extraInformationChanged(QString)),
|
||||
this, SLOT(changeExtraInformation(QString)));
|
||||
QObject::connect(&m_handler, SIGNAL(statusDataChanged(QString)),
|
||||
this, SLOT(changeStatusData(QString)));
|
||||
}
|
||||
|
||||
void tst_FakeVim::setup()
|
||||
{
|
||||
m_statusMessage.clear();
|
||||
m_statusData.clear();
|
||||
m_infoMessage.clear();
|
||||
m_editor.setPlainText(lines);
|
||||
QCOMPARE(m_editor.toPlainText(), lines);
|
||||
}
|
||||
|
||||
void tst_FakeVim::send(const QString &command)
|
||||
{
|
||||
m_handler.handleCommand("normal " + command);
|
||||
}
|
||||
|
||||
void tst_FakeVim::sendEx(const QString &command)
|
||||
{
|
||||
m_handler.handleCommand(command);
|
||||
}
|
||||
|
||||
#define checkContents(wanted) \
|
||||
do { QString want = cleaned(wanted); \
|
||||
QString got = m_editor.toPlainText(); \
|
||||
QStringList wantlist = want.split('\n'); \
|
||||
QStringList gotlist = got.split('\n'); \
|
||||
QCOMPARE(gotlist.size(), wantlist.size()); \
|
||||
for (int i = 0; i < wantlist.size() && i < gotlist.size(); ++i) { \
|
||||
QString g = QString("line %1: %2").arg(i + 1).arg(gotlist.at(i)); \
|
||||
QString w = QString("line %1: %2").arg(i + 1).arg(wantlist.at(i)); \
|
||||
QCOMPARE(g, w); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define checkText(cmd, wanted) \
|
||||
do { \
|
||||
send(cmd); \
|
||||
checkContents(wanted); \
|
||||
int p = (wanted).indexOf('$'); \
|
||||
QCOMPARE(m_editor.textCursor().position(), p); \
|
||||
} while (0)
|
||||
|
||||
#define checkTextEx(cmd, wanted) \
|
||||
do { \
|
||||
sendEx(cmd); \
|
||||
checkContents(wanted); \
|
||||
int p = (wanted).indexOf('$'); \
|
||||
QCOMPARE(m_editor.textCursor().position(), p); \
|
||||
} while (0)
|
||||
|
||||
#define checkPosition(cmd, pos) \
|
||||
do { \
|
||||
send(cmd); \
|
||||
QCOMPARE(m_editor.textCursor().position(), pos); \
|
||||
} while (0)
|
||||
|
||||
void tst_FakeVim::commandI()
|
||||
{
|
||||
setup();
|
||||
|
||||
// empty insertion at start of document
|
||||
checkText("i" + escape, "$" + lines);
|
||||
checkText("u", "$" + lines);
|
||||
|
||||
// small insertion at start of document
|
||||
checkText("ix" + escape, "$x" + lines);
|
||||
checkText("u", "$" + lines);
|
||||
|
||||
// small insertion at start of document
|
||||
checkText("ixxx" + escape, "xx$x" + lines);
|
||||
checkText("u", "$" + lines);
|
||||
|
||||
// combine insertions
|
||||
checkText("ia" + escape, "$a" + lines);
|
||||
checkText("ibx" + escape, "b$xa" + lines);
|
||||
checkText("icyy" + escape, "bcy$yxa" + lines);
|
||||
checkText("u", "b$xa" + lines);
|
||||
checkText("u", "$a" + lines); // undo broken
|
||||
checkTextEx("redo", "b$xa" + lines);
|
||||
checkText("u", "$a" + lines);
|
||||
checkText("u", "$" + lines);
|
||||
}
|
||||
|
||||
void tst_FakeVim::commandDollar()
|
||||
{
|
||||
setup();
|
||||
checkPosition("$", 0);
|
||||
checkPosition("j", 2);
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(tst_FakeVim)
|
||||
|
||||
|
||||
@@ -1078,7 +1078,8 @@ struct QMetaTypeId<QHostAddress>
|
||||
{
|
||||
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0);
|
||||
if (!metatype_id)
|
||||
metatype_id = qRegisterMetaType<QHostAddress>("myns::QHostAddress");
|
||||
metatype_id = qRegisterMetaType<QHostAddress>
|
||||
("myns::QHostAddress");
|
||||
return metatype_id; \
|
||||
} \
|
||||
};
|
||||
@@ -1091,7 +1092,8 @@ struct QMetaTypeId< QMap<uint, QStringList> >
|
||||
{
|
||||
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0);
|
||||
if (!metatype_id)
|
||||
metatype_id = qRegisterMetaType< QMap<uint, QStringList> >("myns::QMap<uint, myns::QStringList>");
|
||||
metatype_id = qRegisterMetaType< QMap<uint, QStringList> >
|
||||
("myns::QMap<uint, myns::QStringList>");
|
||||
return metatype_id; \
|
||||
} \
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user