Changeset View
Changeset View
Standalone View
Standalone View
autotests/src/completion_test.cpp
Show All 20 Lines | |||||
21 | #include "codecompletiontestmodels.h" | 21 | #include "codecompletiontestmodels.h" | ||
22 | //#include "codecompletiontestmodels.moc" | 22 | //#include "codecompletiontestmodels.moc" | ||
23 | 23 | | |||
24 | #include <ksycoca.h> | 24 | #include <ksycoca.h> | ||
25 | 25 | | |||
26 | #include <ktexteditor/document.h> | 26 | #include <ktexteditor/document.h> | ||
27 | #include <ktexteditor/editor.h> | 27 | #include <ktexteditor/editor.h> | ||
28 | 28 | | |||
29 | #include <katedocument.h> | ||||
29 | #include <kateglobal.h> | 30 | #include <kateglobal.h> | ||
30 | #include <kateview.h> | 31 | #include <kateview.h> | ||
31 | #include <katecompletionwidget.h> | 32 | #include <katecompletionwidget.h> | ||
32 | #include <katecompletionmodel.h> | 33 | #include <katecompletionmodel.h> | ||
33 | #include <katecompletiontree.h> | 34 | #include <katecompletiontree.h> | ||
34 | #include <katerenderer.h> | 35 | #include <katerenderer.h> | ||
35 | #include <kateconfig.h> | 36 | #include <kateconfig.h> | ||
36 | 37 | | |||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 160 | { | |||
165 | 166 | | |||
166 | QCOMPARE(countItems(model), 14); | 167 | QCOMPARE(countItems(model), 14); | ||
167 | QVERIFY(m_view->completionWidget()->isCompletionActive()); | 168 | QVERIFY(m_view->completionWidget()->isCompletionActive()); | ||
168 | 169 | | |||
169 | m_view->insertText(QStringLiteral(".")); | 170 | m_view->insertText(QStringLiteral(".")); | ||
170 | verifyCompletionAborted(m_view); | 171 | verifyCompletionAborted(m_view); | ||
171 | } | 172 | } | ||
172 | 173 | | |||
174 | void CompletionTest::testCompletionBlockSelection() | ||||
175 | { | ||||
176 | QString textBlock = QStringLiteral("First line contains some words\n" | ||||
177 | "2nd line consists of some text\n" | ||||
178 | "thrice is just a space filler\n" | ||||
179 | "a fourth makes them four"); | ||||
180 | | ||||
181 | m_doc->setText(textBlock); | ||||
182 | m_view->setBlockSelection(true); | ||||
183 | KTextEditor::Range range(Cursor(0, 0), Cursor(2, 4)); | ||||
184 | m_view->setSelection(range); | ||||
185 | const int lines = m_doc->lines(); | ||||
186 | // get the text on the fourth line to make sure the | ||||
187 | // completion doesn't touch it | ||||
188 | const QString &text4 = m_view->doc()->line(3); | ||||
189 | | ||||
190 | // test with remove tail enabled | ||||
191 | m_view->config()->setWordCompletionRemoveTail(true); | ||||
192 | m_view->doc()->typeChars(m_view, QStringLiteral("fil")); | ||||
193 | QTest::qWait(1000); | ||||
194 | // select the first completion, "filler" | ||||
195 | QTest::keyClick(m_view->focusProxy(), Qt::Key_Return); | ||||
196 | | ||||
197 | QCOMPARE(lines, m_doc->lines()); | ||||
198 | | ||||
199 | for (int i = m_view->selectionRange().start().line(); i <= m_view->selectionRange().end().line(); ++i) { | ||||
200 | const QString &line = m_view->doc()->line(i); | ||||
201 | QVERIFY(line.startsWith(QStringLiteral("filler "))); | ||||
202 | } | ||||
203 | | ||||
204 | QCOMPARE(m_view->doc()->line(3), text4); | ||||
205 | | ||||
206 | // test with remove tail disabled | ||||
207 | m_doc->setText(textBlock); | ||||
208 | m_view->setSelection(range); | ||||
209 | m_view->config()->setWordCompletionRemoveTail(false); | ||||
210 | m_view->doc()->typeChars(m_view, QStringLiteral("fil")); | ||||
211 | QTest::qWait(1000); | ||||
212 | QTest::keyClick(m_view->focusProxy(), Qt::Key_Return); | ||||
213 | | ||||
214 | const int startLine = m_view->selectionRange().start().line(); | ||||
215 | | ||||
216 | QVERIFY(m_view->doc()->line(startLine).startsWith(QStringLiteral("fillert "))); | ||||
217 | QVERIFY(m_view->doc()->line(startLine + 1).startsWith(QStringLiteral("fillerline "))); | ||||
218 | QVERIFY(m_view->doc()->line(startLine + 2).startsWith(QStringLiteral("fillerce "))); | ||||
219 | } | ||||
220 | | ||||
173 | void CompletionTest::testCustomRange1() | 221 | void CompletionTest::testCustomRange1() | ||
174 | { | 222 | { | ||
175 | m_doc->setText(QStringLiteral("$aa bb cc\ndd")); | 223 | m_doc->setText(QStringLiteral("$aa bb cc\ndd")); | ||
176 | KateCompletionModel *model = m_view->completionWidget()->model(); | 224 | KateCompletionModel *model = m_view->completionWidget()->model(); | ||
177 | 225 | | |||
178 | CodeCompletionTestModel *testModel = new CustomRangeModel(m_view, QStringLiteral("$a")); | 226 | CodeCompletionTestModel *testModel = new CustomRangeModel(m_view, QStringLiteral("$a")); | ||
179 | m_view->setCursorPosition(Cursor(0, 3)); | 227 | m_view->setCursorPosition(Cursor(0, 3)); | ||
180 | invokeCompletionBox(m_view); | 228 | invokeCompletionBox(m_view); | ||
▲ Show 20 Lines • Show All 319 Lines • Show Last 20 Lines |