// This test makes sure that, // - if you have selected text // - that spans a folded range, // - and the cursor is at the end of the text selection, // - and you type a char, e.g. 'x', // then the resulting text is correct, and changing region // visibility does not mess around with the text cursor. // // See https://bugs.kde.org/show_bug.cgi?id=295632 void KateFoldingTest::testBug295632() { KTextEditor::DocumentPrivate doc; QString text = "oooossssssss\n" "{\n" "\n" "}\n" "ssssss----------"; doc.setText(text); // view must be visible... KTextEditor::ViewPrivate *view = static_cast<KTextEditor::ViewPrivate *>(doc.createView(0)); view->show(); view->resize(400, 300); qint64 foldId = view->textFolding().newFoldingRange(KTextEditor::Range(1, 0, 3, 1)); view->textFolding().foldRange(foldId); QVERIFY(view->textFolding().isLineVisible(0)); QVERIFY(view->textFolding().isLineVisible(1)); QVERIFY(!view->textFolding().isLineVisible(2)); QVERIFY(!view->textFolding().isLineVisible(3)); QVERIFY(view->textFolding().isLineVisible(4)); view->setSelection(Range(Cursor(0, 4), Cursor(4, 6))); view->setCursorPosition(Cursor(4, 6)); QTest::qWait(100); doc.typeChars(view, "x"); QTest::qWait(100); QString line = doc.line(0); QCOMPARE(line, QString("oooox----------")); }
void KateSyntaxTest::testSyntaxHighlighting() { /** * get current test case */ QFETCH(QString, hlTestCase); /** * create a document with a view to be able to export stuff */ KTextEditor::DocumentPrivate doc; auto view = static_cast<KTextEditor::ViewPrivate*>(doc.createView(Q_NULLPTR)); /** * load the test case * enforce UTF-8 to avoid locale problems */ QUrl url; url.setScheme(QLatin1String("file")); url.setPath(hlTestCase); doc.setEncoding(QStringLiteral("UTF-8")); QVERIFY(doc.openUrl(url)); /** * compute needed dirs */ const QFileInfo info(hlTestCase); const QString resultDir(info.absolutePath() + QLatin1String("/results/")); const QString currentResult(resultDir + info.fileName() + QLatin1String(".current.html")); const QString referenceResult(resultDir + info.fileName() + QLatin1String(".reference.html")); /** * export the result */ view->exportHtmlToFile(currentResult); /** * verify the result against reference */ QProcess diff; diff.setProcessChannelMode(QProcess::MergedChannels); QStringList args; args << QLatin1String("-u") << (referenceResult) << (currentResult); diff.start(QLatin1String("diff"), args); diff.waitForFinished(); QByteArray out = diff.readAllStandardOutput(); if (!out.isEmpty()) { printf("DIFF:\n"); QList<QByteArray> outLines = out.split('\n'); Q_FOREACH(const QByteArray &line, outLines) { printf("%s\n", qPrintable(line)); }
void BugTest::tryCrash() { // set up document and view KMainWindow *toplevel = new KMainWindow(); KTextEditor::DocumentPrivate *doc = new KTextEditor::DocumentPrivate(true, false, toplevel); KTextEditor::ViewPrivate *view = static_cast<KTextEditor::ViewPrivate *>(doc->createView(0)); bool outputWasCustomised = false; TestScriptEnv *env = new TestScriptEnv(doc, outputWasCustomised); const QUrl url = QUrl::fromLocalFile(QLatin1String(TEST_DATA_DIR"bug313759.txt")); doc->openUrl(url); // load moveLinesDown and moveLinesUp QFile scriptFile(QLatin1String(JS_DATA_DIR "commands/utils.js")); QVERIFY(scriptFile.exists()); QVERIFY(scriptFile.open(QFile::ReadOnly)); QScriptValue result = env->engine()->evaluate(QString::fromLatin1(scriptFile.readAll()), scriptFile.fileName()); QVERIFY2(!result.isError(), qPrintable(QString(result.toString() + QLatin1String("\nat ") + env->engine()->uncaughtExceptionBacktrace().join(QStringLiteral("\n"))))); // enable on the fly spell checking doc->onTheFlySpellCheckingEnabled(true); // view must be visible... view->show(); view->resize(900, 800); view->setCursorPosition(Cursor(0, 0)); doc->editBegin(); // QTest::qWait(200); // evaluate test-script qDebug() << "attempting crash by moving lines w/ otf spell checking enabled"; QFile sourceFile(QLatin1String(TEST_DATA_DIR"bug313759.js")); QVERIFY(sourceFile.open(QFile::ReadOnly)); QTextStream stream(&sourceFile); stream.setCodec("UTF8"); QString code = stream.readAll(); sourceFile.close(); // execute script result = env->engine()->evaluate(code, QLatin1String(TEST_DATA_DIR"bug313759.txt"), 1); QVERIFY2(!result.isError(), result.toString().toUtf8().constData()); doc->editEnd(); qDebug() << "PASS (no crash)"; }
// This is a unit test for bug 311866 (http://bugs.kde.org/show_bug.cgi?id=311866) // It loads 5 lines of C++ code, places the cursor in line 4, and then folds // the code. // Expected behavior: the cursor should be moved so it stays visible // Buggy behavior: the cursor is hidden, and moving the hidden cursor crashes kate void KateFoldingTest::testCrash311866() { KTextEditor::DocumentPrivate doc; const QUrl url = QUrl::fromLocalFile(QLatin1String(TEST_DATA_DIR"bug311866.cpp")); doc.openUrl(url); doc.setHighlightingMode("C++"); doc.buffer().ensureHighlighted(6); KTextEditor::ViewPrivate *view = static_cast<KTextEditor::ViewPrivate *>(doc.createView(0)); view->show(); view->resize(400, 300); view->setCursorPosition(Cursor(3, 0)); QTest::qWait(100); view->slotFoldToplevelNodes(); doc.buffer().ensureHighlighted(6); qDebug() << "!!! Does the next line crash?"; view->up(); }