/// The '|' in the input denotes the cursor position. void DoxygenTest::runTest(const QByteArray &original, const QByteArray &expected, TextEditor::CommentsSettings *settings, const TestDocuments &includedHeaderDocuments) { // Write files to disk CppTools::Tests::TemporaryDir temporaryDir; QVERIFY(temporaryDir.isValid()); TestDocument testDocument("file.cpp", original, '|'); QVERIFY(testDocument.hasCursorMarker()); testDocument.m_source.remove(testDocument.m_cursorPosition, 1); testDocument.setBaseDirectory(temporaryDir.path()); QVERIFY(testDocument.writeToDisk()); foreach (TestDocument testDocument, includedHeaderDocuments) { testDocument.setBaseDirectory(temporaryDir.path()); QVERIFY(testDocument.writeToDisk()); }
/// The '|' in the input denotes the cursor position. DoxygenTestCase(const QByteArray &original, const QByteArray &expected, CppTools::CommentsSettings *settings = 0) { QVERIFY(succeededSoFar()); TestDocument testDocument("file.cpp", original, '|'); QVERIFY(testDocument.hasCursorMarker()); testDocument.m_source.remove(testDocument.m_cursorPosition, 1); QVERIFY(testDocument.writeToDisk()); // Update Code Model QVERIFY(parseFiles(testDocument.filePath())); // Open Editor QVERIFY(openCppEditor(testDocument.filePath(), &testDocument.m_editor, &testDocument.m_editorWidget)); closeEditorAtEndOfTestCase(testDocument.m_editor); if (settings) { auto *cts = CppTools::CppToolsSettings::instance(); oldSettings.reset(new CppTools::CommentsSettings(cts->commentsSettings())); cts->setCommentsSettings(*settings); } // We want to test documents that start with a comment. By default, the // editor will fold the very first comment it encounters, assuming // it is a license header. Currently unfoldAll() does not work as // expected (some blocks are still hidden in some test cases, so the // cursor movements are not as expected). For the time being, we just // prepend a declaration before the initial test comment. // testDocument.m_editorWidget->unfoldAll(); testDocument.m_editor->setCursorPosition(testDocument.m_cursorPosition); waitForRehighlightedSemanticDocument(testDocument.m_editorWidget); // Send 'ENTER' key press QKeyEvent event(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); QCoreApplication::sendEvent(testDocument.m_editorWidget, &event); const QByteArray result = testDocument.m_editorWidget->document()->toPlainText().toUtf8(); QCOMPARE(QLatin1String(result), QLatin1String(expected)); testDocument.m_editorWidget->undo(); const QString contentsAfterUndo = testDocument.m_editorWidget->document()->toPlainText(); QCOMPARE(contentsAfterUndo, testDocument.m_source); }