Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tobias Hunger
qt-creator
Commits
e76ba64f
Commit
e76ba64f
authored
Apr 09, 2009
by
hjk
Browse files
fakevim: work on autotests
parent
04e2fc12
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/plugins/fakevim/fakevimhandler.cpp
View file @
e76ba64f
...
...
@@ -611,12 +611,12 @@ void FakeVimHandler::Private::moveDown(int n)
// does not work for "hidden" documents like in the autotests
m_tc.movePosition(Down, MoveAnchor, n);
#else
const
QTextBlock
&
block
=
m_tc
.
block
();
const
int
col
=
m_tc
.
position
()
-
block
.
position
();
const
int
line
=
block
.
b
lockNumber
();
const
int
pos
=
m_tc
.
document
()
->
findBlockByNumber
(
line
+
n
)
.
position
();
setPosition
(
pos
+
qMin
(
block
.
length
(),
col
));
setPosition
(
pos
);
const
int
col
=
m_tc
.
position
()
-
m_tc
.
block
().
position
();
const
int
line
=
m_tc
.
block
().
blockNumber
();
const
QTextBlock
&
block
=
m_tc
.
document
()
->
findB
lock
By
Number
(
line
+
n
);
const
int
pos
=
block
.
position
();
setPosition
(
pos
+
qMin
(
block
.
length
()
-
1
,
col
));
moveToTargetColumn
(
);
#endif
}
...
...
@@ -1675,7 +1675,6 @@ void FakeVimHandler::Private::selectRange(int beginLine, int endLine)
void
FakeVimHandler
::
Private
::
handleCommand
(
const
QString
&
cmd
)
{
m_tc
=
EDITOR
(
textCursor
());
init
();
handleExCommand
(
cmd
);
EDITOR
(
setTextCursor
(
m_tc
));
}
...
...
@@ -2042,10 +2041,12 @@ void FakeVimHandler::Private::shiftRegionLeft(int repeat)
void
FakeVimHandler
::
Private
::
moveToTargetColumn
()
{
if
(
m_targetColumn
==
-
1
||
m_tc
.
block
().
length
()
<=
m_targetColumn
)
m_tc
.
movePosition
(
EndOfLine
,
KeepAnchor
);
else
if
(
m_targetColumn
==
-
1
||
m_tc
.
block
().
length
()
<=
m_targetColumn
)
{
const
QTextBlock
&
block
=
m_tc
.
block
();
m_tc
.
setPosition
(
block
.
position
()
+
block
.
length
()
-
1
,
KeepAnchor
);
}
else
{
m_tc
.
setPosition
(
m_tc
.
block
().
position
()
+
m_targetColumn
,
KeepAnchor
);
}
}
static
int
charClass
(
QChar
c
,
bool
simple
)
...
...
tests/auto/fakevim/main.cpp
View file @
e76ba64f
...
...
@@ -62,7 +62,7 @@ private slots:
private:
void
setup
();
void
send
(
const
QString
&
command
)
;
//
send
a
normal command
void
send
(
const
QString
&
command
)
{
send
Ex
(
"
normal
"
+
command
);
}
void
sendEx
(
const
QString
&
command
);
// send an ex command
bool
checkContentsHelper
(
QString
expected
,
const
char
*
file
,
int
line
);
...
...
@@ -84,6 +84,8 @@ private:
};
const
QString
tst_FakeVim
::
lines
=
/* 0 1 2 3 4 */
/* 0123456789012345678901234567890123457890 */
"
\n
"
"#include <QtCore>
\n
"
"#include <QtGui>
\n
"
...
...
@@ -102,19 +104,11 @@ tst_FakeVim::tst_FakeVim(bool usePlainTextEdit)
if
(
usePlainTextEdit
)
{
m_textedit
=
0
;
m_plaintextedit
=
new
QPlainTextEdit
;
m_handler
=
new
FakeVimHandler
(
m_plaintextedit
);
}
else
{
m_textedit
=
new
QTextEdit
;
m_plaintextedit
=
0
;
m_handler
=
new
FakeVimHandler
(
m_textedit
);
}
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
)));
m_handler
=
0
;
}
tst_FakeVim
::~
tst_FakeVim
()
...
...
@@ -126,6 +120,8 @@ tst_FakeVim::~tst_FakeVim()
void
tst_FakeVim
::
setup
()
{
delete
m_handler
;
m_handler
=
0
;
m_statusMessage
.
clear
();
m_statusData
.
clear
();
m_infoMessage
.
clear
();
...
...
@@ -135,24 +131,32 @@ void tst_FakeVim::setup()
tc
.
movePosition
(
QTextCursor
::
Start
,
QTextCursor
::
MoveAnchor
);
m_textedit
->
setTextCursor
(
tc
);
m_textedit
->
setPlainText
(
lines
);
m_handler
=
new
FakeVimHandler
(
m_textedit
);
}
else
{
m_plaintextedit
->
setPlainText
(
lines
);
QTextCursor
tc
=
m_plaintextedit
->
textCursor
();
tc
.
movePosition
(
QTextCursor
::
Start
,
QTextCursor
::
MoveAnchor
);
m_plaintextedit
->
setTextCursor
(
tc
);
m_plaintextedit
->
setPlainText
(
lines
);
m_handler
=
new
FakeVimHandler
(
m_plaintextedit
);
}
QCOMPARE
(
EDITOR
(
toPlainText
()),
lines
);
}
void
tst_FakeVim
::
send
(
const
QString
&
command
)
{
m_handler
->
handleCommand
(
"normal "
+
command
);
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
)));
QCOMPARE
(
EDITOR
(
toPlainText
()),
lines
);
}
void
tst_FakeVim
::
sendEx
(
const
QString
&
command
)
{
m_handler
->
handleCommand
(
command
);
if
(
m_handler
)
m_handler
->
handleCommand
(
command
);
else
qDebug
()
<<
"NO HANDLER YET"
;
}
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
;
needle
.
remove
(
'@'
);
QString
lines0
=
lines
;
lines0
.
replace
(
needle
,
needle
0
);
//qDebug() << "LINES: " << lines0
;
int
pos
=
lines0
.
indexOf
(
needle
);
lines0
.
replace
(
pos
,
needle
.
size
(),
needle0
)
;
return
lines0
;
}
void
tst_FakeVim
::
commandI
()
{
return
;
setup
();
// empty insertion at start of document
...
...
@@ -232,6 +235,8 @@ void tst_FakeVim::commandI()
check
(
"ixxx"
+
escape
,
"xx@x"
+
lines
);
check
(
"u"
,
"@"
+
lines
);
return
;
// combine insertions
check
(
"ia"
+
escape
,
"@a"
+
lines
);
check
(
"ibx"
+
escape
,
"b@xa"
+
lines
);
...
...
@@ -247,7 +252,8 @@ void tst_FakeVim::commandDollar()
{
setup
();
check
(
"j$"
,
insertCursor
(
"<QtCore>@"
));
//check("j", insertCursor("<QtGui>@"));
check
(
"j$"
,
insertCursor
(
"<QtGui>@"
));
check
(
"2j"
,
insertCursor
(
")@"
));
}
void
tst_FakeVim
::
commandDown
()
...
...
@@ -266,14 +272,33 @@ void tst_FakeVim::commandUp()
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
res
=
0
;
QApplication
app
(
argc
,
argv
);
\
// Test with QPlainTextEdit.
tst_FakeVim
plaintextedit
(
true
);
res
+=
QTest
::
qExec
(
&
plaintextedit
,
argc
,
argv
);
#if 0
// Test with QTextEdit, too.
tst_FakeVim textedit(false);
res += QTest::qExec(&textedit, argc, argv);
#endif
return
res
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment