fakevim: work on autotests

This commit is contained in:
hjk
2009-04-09 15:44:51 +02:00
parent 04e2fc1217
commit e76ba64f68
2 changed files with 56 additions and 30 deletions

View File

@@ -611,12 +611,12 @@ void FakeVimHandler::Private::moveDown(int n)
// does not work for "hidden" documents like in the autotests // does not work for "hidden" documents like in the autotests
m_tc.movePosition(Down, MoveAnchor, n); m_tc.movePosition(Down, MoveAnchor, n);
#else #else
const QTextBlock &block = m_tc.block(); const int col = m_tc.position() - m_tc.block().position();
const int col = m_tc.position() - block.position(); const int line = m_tc.block().blockNumber();
const int line = block.blockNumber(); const QTextBlock &block = m_tc.document()->findBlockByNumber(line + n);
const int pos = m_tc.document()->findBlockByNumber(line + n).position(); const int pos = block.position();
setPosition(pos + qMin(block.length(), col)); setPosition(pos + qMin(block.length() - 1, col));
setPosition(pos); moveToTargetColumn();
#endif #endif
} }
@@ -1675,7 +1675,6 @@ void FakeVimHandler::Private::selectRange(int beginLine, int endLine)
void FakeVimHandler::Private::handleCommand(const QString &cmd) void FakeVimHandler::Private::handleCommand(const QString &cmd)
{ {
m_tc = EDITOR(textCursor()); m_tc = EDITOR(textCursor());
init();
handleExCommand(cmd); handleExCommand(cmd);
EDITOR(setTextCursor(m_tc)); EDITOR(setTextCursor(m_tc));
} }
@@ -2042,11 +2041,13 @@ void FakeVimHandler::Private::shiftRegionLeft(int repeat)
void FakeVimHandler::Private::moveToTargetColumn() void FakeVimHandler::Private::moveToTargetColumn()
{ {
if (m_targetColumn == -1 || m_tc.block().length() <= m_targetColumn) if (m_targetColumn == -1 || m_tc.block().length() <= m_targetColumn) {
m_tc.movePosition(EndOfLine, KeepAnchor); const QTextBlock &block = m_tc.block();
else m_tc.setPosition(block.position() + block.length() - 1, KeepAnchor);
} else {
m_tc.setPosition(m_tc.block().position() + m_targetColumn, KeepAnchor); m_tc.setPosition(m_tc.block().position() + m_targetColumn, KeepAnchor);
} }
}
static int charClass(QChar c, bool simple) static int charClass(QChar c, bool simple)
{ {

View File

@@ -62,7 +62,7 @@ private slots:
private: private:
void setup(); void setup();
void send(const QString &command); // send a normal command void send(const QString &command) { sendEx("normal " + command); }
void sendEx(const QString &command); // send an ex command void sendEx(const QString &command); // send an ex command
bool checkContentsHelper(QString expected, const char* file, int line); bool checkContentsHelper(QString expected, const char* file, int line);
@@ -84,6 +84,8 @@ private:
}; };
const QString tst_FakeVim::lines = const QString tst_FakeVim::lines =
/* 0 1 2 3 4 */
/* 0123456789012345678901234567890123457890 */
"\n" "\n"
"#include <QtCore>\n" "#include <QtCore>\n"
"#include <QtGui>\n" "#include <QtGui>\n"
@@ -102,19 +104,11 @@ tst_FakeVim::tst_FakeVim(bool usePlainTextEdit)
if (usePlainTextEdit) { if (usePlainTextEdit) {
m_textedit = 0; m_textedit = 0;
m_plaintextedit = new QPlainTextEdit; m_plaintextedit = new QPlainTextEdit;
m_handler = new FakeVimHandler(m_plaintextedit);
} else { } else {
m_textedit = new QTextEdit; m_textedit = new QTextEdit;
m_plaintextedit = 0; m_plaintextedit = 0;
m_handler = new FakeVimHandler(m_textedit);
} }
m_handler = 0;
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)));
} }
tst_FakeVim::~tst_FakeVim() tst_FakeVim::~tst_FakeVim()
@@ -126,6 +120,8 @@ tst_FakeVim::~tst_FakeVim()
void tst_FakeVim::setup() void tst_FakeVim::setup()
{ {
delete m_handler;
m_handler = 0;
m_statusMessage.clear(); m_statusMessage.clear();
m_statusData.clear(); m_statusData.clear();
m_infoMessage.clear(); m_infoMessage.clear();
@@ -135,24 +131,32 @@ void tst_FakeVim::setup()
tc.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor); tc.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
m_textedit->setTextCursor(tc); m_textedit->setTextCursor(tc);
m_textedit->setPlainText(lines); m_textedit->setPlainText(lines);
m_handler = new FakeVimHandler(m_textedit);
} else { } else {
m_plaintextedit->setPlainText(lines); m_plaintextedit->setPlainText(lines);
QTextCursor tc = m_plaintextedit->textCursor(); QTextCursor tc = m_plaintextedit->textCursor();
tc.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor); tc.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
m_plaintextedit->setTextCursor(tc); m_plaintextedit->setTextCursor(tc);
m_plaintextedit->setPlainText(lines); m_plaintextedit->setPlainText(lines);
} m_handler = new FakeVimHandler(m_plaintextedit);
QCOMPARE(EDITOR(toPlainText()), lines);
} }
void tst_FakeVim::send(const QString &command) QObject::connect(m_handler, SIGNAL(commandBufferChanged(QString)),
{ this, SLOT(changeStatusMessage(QString)));
m_handler->handleCommand("normal " + command); QObject::connect(m_handler, SIGNAL(extraInformationChanged(QString)),
this, SLOT(changeExtraInformation(QString)));
QObject::connect(m_handler, SIGNAL(statusDataChanged(QString)),
this, SLOT(changeStatusData(QString)));
QCOMPARE(EDITOR(toPlainText()), lines);
} }
void tst_FakeVim::sendEx(const QString &command) void tst_FakeVim::sendEx(const QString &command)
{ {
if (m_handler)
m_handler->handleCommand(command); m_handler->handleCommand(command);
else
qDebug() << "NO HANDLER YET";
} }
bool tst_FakeVim::checkContentsHelper(QString want, const char* file, int line) bool tst_FakeVim::checkContentsHelper(QString want, const char* file, int line)
@@ -210,14 +214,13 @@ QString tst_FakeVim::insertCursor(const QString &needle0)
QString needle = needle0; QString needle = needle0;
needle.remove('@'); needle.remove('@');
QString lines0 = lines; QString lines0 = lines;
lines0.replace(needle, needle0); int pos = lines0.indexOf(needle);
//qDebug() << "LINES: " << lines0; lines0.replace(pos, needle.size(), needle0);
return lines0; return lines0;
} }
void tst_FakeVim::commandI() void tst_FakeVim::commandI()
{ {
return;
setup(); setup();
// empty insertion at start of document // empty insertion at start of document
@@ -232,6 +235,8 @@ void tst_FakeVim::commandI()
check("ixxx" + escape, "xx@x" + lines); check("ixxx" + escape, "xx@x" + lines);
check("u", "@" + lines); check("u", "@" + lines);
return;
// combine insertions // combine insertions
check("ia" + escape, "@a" + lines); check("ia" + escape, "@a" + lines);
check("ibx" + escape, "b@xa" + lines); check("ibx" + escape, "b@xa" + lines);
@@ -247,7 +252,8 @@ void tst_FakeVim::commandDollar()
{ {
setup(); setup();
check("j$", insertCursor("<QtCore>@")); check("j$", insertCursor("<QtCore>@"));
//check("j", insertCursor("<QtGui>@")); check("j$", insertCursor("<QtGui>@"));
check("2j", insertCursor(")@"));
} }
void tst_FakeVim::commandDown() void tst_FakeVim::commandDown()
@@ -266,14 +272,33 @@ void tst_FakeVim::commandUp()
check("4j", insertCursor("@ return app.exec()")); check("4j", insertCursor("@ return app.exec()"));
} }
/*
#include <QtCore>
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
return app.exec();
}
*/
int main(int argc, char *argv[]) \ int main(int argc, char *argv[]) \
{ {
int res = 0; int res = 0;
QApplication app(argc, argv); \ QApplication app(argc, argv); \
// Test with QPlainTextEdit.
tst_FakeVim plaintextedit(true); tst_FakeVim plaintextedit(true);
res += QTest::qExec(&plaintextedit, argc, argv); res += QTest::qExec(&plaintextedit, argc, argv);
#if 0
// Test with QTextEdit, too.
tst_FakeVim textedit(false); tst_FakeVim textedit(false);
res += QTest::qExec(&textedit, argc, argv); res += QTest::qExec(&textedit, argc, argv);
#endif
return res; return res;
} }