Changeset View
Changeset View
Standalone View
Standalone View
autotests/src/kateview_test.cpp
Show All 25 Lines | |||||
26 | #include <ktexteditor/movingcursor.h> | 26 | #include <ktexteditor/movingcursor.h> | ||
27 | #include <kateconfig.h> | 27 | #include <kateconfig.h> | ||
28 | #include <katebuffer.h> | 28 | #include <katebuffer.h> | ||
29 | #include <ktexteditor/message.h> | 29 | #include <ktexteditor/message.h> | ||
30 | 30 | | |||
31 | #include <QtTestWidgets> | 31 | #include <QtTestWidgets> | ||
32 | #include <QTemporaryFile> | 32 | #include <QTemporaryFile> | ||
33 | 33 | | |||
34 | #define testNewRow() (QTest::newRow(QString("line %1").arg(__LINE__).toLatin1().data())) | ||||
35 | | ||||
34 | using namespace KTextEditor; | 36 | using namespace KTextEditor; | ||
35 | 37 | | |||
36 | QTEST_MAIN(KateViewTest) | 38 | QTEST_MAIN(KateViewTest) | ||
37 | 39 | | |||
38 | KateViewTest::KateViewTest() | 40 | KateViewTest::KateViewTest() | ||
39 | : QObject() | 41 | : QObject() | ||
40 | { | 42 | { | ||
41 | KTextEditor::EditorPrivate::enableUnitTestMode(); | 43 | KTextEditor::EditorPrivate::enableUnitTestMode(); | ||
▲ Show 20 Lines • Show All 220 Lines • ▼ Show 20 Line(s) | 190 | { | |||
262 | QCoreApplication::sendEvent(internalView, new QMouseEvent(QEvent::MouseButtonRelease, afterB, | 264 | QCoreApplication::sendEvent(internalView, new QMouseEvent(QEvent::MouseButtonRelease, afterB, | ||
263 | Qt::LeftButton, Qt::LeftButton, | 265 | Qt::LeftButton, Qt::LeftButton, | ||
264 | Qt::ShiftModifier)); | 266 | Qt::ShiftModifier)); | ||
265 | 267 | | |||
266 | QCOMPARE(view->cursorPosition(), Cursor(1, 1)); | 268 | QCOMPARE(view->cursorPosition(), Cursor(1, 1)); | ||
267 | QCOMPARE(view->selectionRange(), Range(1, 1, 2, 1)); | 269 | QCOMPARE(view->selectionRange(), Range(1, 1, 2, 1)); | ||
268 | } | 270 | } | ||
269 | 271 | | |||
272 | void KateViewTest::testDeselectByArrowKeys_data() | ||||
273 | { | ||||
274 | QTest::addColumn<QString>("text"); | ||||
275 | | ||||
276 | testNewRow() << "foobarhaz"; | ||||
277 | testNewRow() << "كلسشمن يتبكسب"; // We all win, translates Google | ||||
278 | } | ||||
279 | | ||||
280 | void KateViewTest::testDeselectByArrowKeys() | ||||
281 | { | ||||
282 | QFETCH(QString, text); | ||||
283 | | ||||
284 | KTextEditor::DocumentPrivate doc; | ||||
285 | doc.setText(text); | ||||
286 | KTextEditor::ViewPrivate *view = new KTextEditor::ViewPrivate(&doc, nullptr); | ||||
287 | KTextEditor::Cursor cur1(0, 3); // Start of bar: foo|barhaz | ||||
288 | KTextEditor::Cursor cur2(0, 6); // End of bar: foobar|haz | ||||
289 | KTextEditor::Cursor curDelta(0, 1); | ||||
290 | Range range(cur1, cur2); // Select "bar" | ||||
291 | | ||||
292 | // RTL drives me nuts! | ||||
293 | KTextEditor::Cursor help; | ||||
294 | if (text.isRightToLeft()) { | ||||
295 | help = cur1; | ||||
296 | cur1 = cur2; | ||||
297 | cur2 = help; | ||||
298 | } | ||||
299 | | ||||
300 | view->setSelection(range); | ||||
301 | view->setCursorPositionInternal(cur1); | ||||
302 | view->cursorLeft(); | ||||
303 | QCOMPARE(view->cursorPosition(), cur1); // Be at begin: foo|barhaz | ||||
304 | QCOMPARE(view->selection(), false); | ||||
305 | | ||||
306 | view->setSelection(range); | ||||
307 | view->setCursorPositionInternal(cur1); | ||||
308 | view->cursorRight(); | ||||
309 | QCOMPARE(view->cursorPosition(), cur2); // Be at end: foobar|haz | ||||
310 | QCOMPARE(view->selection(), false); | ||||
311 | | ||||
312 | view->config()->setPersistentSelection(true); | ||||
313 | | ||||
314 | view->setSelection(range); | ||||
315 | view->setCursorPositionInternal(cur1); | ||||
316 | view->cursorLeft(); | ||||
317 | // RTL drives me nuts! | ||||
318 | help = text.isRightToLeft() ? (cur1 + curDelta): (cur1 - curDelta); | ||||
319 | QCOMPARE(view->cursorPosition(), help); // Be one left: fo|obarhaz | ||||
320 | QCOMPARE(view->selection(), true); | ||||
321 | | ||||
322 | view->setSelection(range); | ||||
323 | view->setCursorPositionInternal(cur1); | ||||
324 | view->cursorRight(); | ||||
325 | // RTL drives me nuts! | ||||
326 | help = text.isRightToLeft() ? (cur1 - curDelta): (cur1 + curDelta); | ||||
327 | QCOMPARE(view->cursorPosition(), help); // Be one right: foob|arhaz | ||||
328 | QCOMPARE(view->selection(), true); | ||||
329 | } | ||||
330 | | ||||
270 | void KateViewTest::testKillline() | 331 | void KateViewTest::testKillline() | ||
271 | { | 332 | { | ||
272 | KTextEditor::DocumentPrivate doc; | 333 | KTextEditor::DocumentPrivate doc; | ||
273 | doc.insertLines(0, { "foo", "bar", "baz" }); | 334 | doc.insertLines(0, { "foo", "bar", "baz" }); | ||
274 | 335 | | |||
275 | KTextEditor::ViewPrivate *view = new KTextEditor::ViewPrivate(&doc, nullptr); | 336 | KTextEditor::ViewPrivate *view = new KTextEditor::ViewPrivate(&doc, nullptr); | ||
276 | 337 | | |||
277 | view->setCursorPositionInternal(KTextEditor::Cursor(1, 2)); | 338 | view->setCursorPositionInternal(KTextEditor::Cursor(1, 2)); | ||
▲ Show 20 Lines • Show All 193 Lines • Show Last 20 Lines |