Changeset View
Changeset View
Standalone View
Standalone View
autotests/src/katedocument_test.cpp
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | 262 | { | |||
---|---|---|---|---|---|
275 | QVERIFY(doc.isEmpty()); | 275 | QVERIFY(doc.isEmpty()); | ||
276 | doc.insertText(Cursor(100, 0), "foobar"); | 276 | doc.insertText(Cursor(100, 0), "foobar"); | ||
277 | QCOMPARE(doc.line(100), QString("foobar")); | 277 | QCOMPARE(doc.line(100), QString("foobar")); | ||
278 | 278 | | |||
279 | doc.setText("nY\nnYY\n"); | 279 | doc.setText("nY\nnYY\n"); | ||
280 | QVERIFY(doc.removeText(Range(0, 0, 0, 1000))); | 280 | QVERIFY(doc.removeText(Range(0, 0, 0, 1000))); | ||
281 | } | 281 | } | ||
282 | 282 | | |||
283 | void KateDocumentTest::testAutoBrackets() | ||||
284 | { | ||||
285 | KTextEditor::DocumentPrivate doc; | ||||
286 | auto view = static_cast<KTextEditor::ViewPrivate*>(doc.createView(nullptr)); | ||||
287 | | ||||
288 | auto reset = [&]() { | ||||
289 | doc.setText(""); | ||||
290 | view->setCursorPosition(Cursor(0, 0)); | ||||
291 | }; | ||||
292 | | ||||
293 | auto typeText = [&](const QString &text) { | ||||
294 | for (int i = 0; i < text.size(); ++i) { | ||||
295 | doc.typeChars(view, text.at(i)); | ||||
296 | } | ||||
297 | }; | ||||
298 | | ||||
299 | doc.setHighlightingMode ("Normal"); // Just to be sure | ||||
300 | view->config()->setAutoBrackets(true); | ||||
301 | | ||||
302 | QString testInput; | ||||
303 | | ||||
304 | testInput = ("("); | ||||
305 | typeText(testInput); | ||||
306 | qDebug() << doc.text(); | ||||
307 | QCOMPARE(doc.text(), "()"); | ||||
308 | | ||||
309 | reset(); | ||||
310 | testInput = ("\""); | ||||
311 | typeText(testInput); | ||||
312 | qDebug() << doc.text(); | ||||
313 | QCOMPARE(doc.text(), "\"\""); | ||||
314 | | ||||
315 | reset(); | ||||
316 | testInput = ("'"); | ||||
317 | typeText(testInput); | ||||
318 | qDebug() << doc.text(); | ||||
319 | QCOMPARE(doc.text(), "'"); // In Normal mode there is only one quote to expect | ||||
320 | | ||||
321 | // | ||||
322 | // Switch over to some other mode | ||||
323 | // | ||||
324 | doc.setHighlightingMode ("C++"); | ||||
325 | | ||||
326 | reset(); | ||||
327 | typeText(testInput); | ||||
328 | qDebug() << doc.text(); | ||||
329 | QCOMPARE(doc.text(), "''"); // Now it must be two | ||||
330 | | ||||
331 | reset(); | ||||
332 | testInput = "('\')"; | ||||
333 | typeText(testInput); | ||||
334 | qDebug() << doc.text(); | ||||
335 | // Known bad behaviour | ||||
336 | QCOMPARE(doc.text(), "('\'))"); // FIXME/TODO should be "('\')" like testInput | ||||
337 | | ||||
338 | reset(); | ||||
339 | testInput = ("foo \"bar\" haz"); | ||||
340 | typeText(testInput); | ||||
341 | qDebug() << doc.text(); | ||||
342 | QCOMPARE(doc.text(), testInput); | ||||
343 | // Simulate afterwards to add quotes, bug 405089 | ||||
344 | doc.setText("foo \"bar"); | ||||
345 | typeText("\" haz"); | ||||
346 | qDebug() << doc.text(); | ||||
347 | QCOMPARE(doc.text(), testInput); | ||||
348 | | ||||
349 | // doc.setText("foo bar haz"); | ||||
350 | | ||||
351 | } | ||||
352 | | ||||
283 | void KateDocumentTest::testReplaceTabs() | 353 | void KateDocumentTest::testReplaceTabs() | ||
284 | { | 354 | { | ||
285 | KTextEditor::DocumentPrivate doc; | 355 | KTextEditor::DocumentPrivate doc; | ||
286 | auto view = static_cast<KTextEditor::ViewPrivate*>(doc.createView(nullptr)); | 356 | auto view = static_cast<KTextEditor::ViewPrivate*>(doc.createView(nullptr)); | ||
287 | 357 | | |||
288 | auto reset = [&]() { | 358 | auto reset = [&]() { | ||
289 | doc.setText(" Hi!"); | 359 | doc.setText(" Hi!"); | ||
290 | view->setCursorPosition(Cursor(0, 0)); | 360 | view->setCursorPosition(Cursor(0, 0)); | ||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |