Skip to content

Commit

Permalink
Github Issue #174: Added unit test to check if the code block symbols…
Browse files Browse the repository at this point in the history
… are being deleted properly using backspace key
  • Loading branch information
AngryFender committed Jun 9, 2024
1 parent b9ee18e commit 2c11d2e
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions CatchTests/MkEdit_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1708,3 +1708,71 @@ TEST_CASE("MkEdit pressing delete as the end of the text block, undo/redo", "[Mk
text = edit.toPlainText();
REQUIRE("**bold***italic*" == text);
}

TEST_CASE("MkEdit pressing backspace to delele the code block symbols, undo/redo", "[MkEdit]")
{
MkTextDocument doc;
MkEdit edit;

doc.setPlainText("```\n```");
edit.setDocument(&doc);
int initialPosition = 3;
int secondPosition = 7;

QObject::connect(&edit,&MkEdit::cursorPosChanged,
&doc,&MkTextDocument::cursorPosChangedHandle);

QObject::connect(&edit,&MkEdit::removeAllMkData,
&doc,&MkTextDocument::removeAllMkDataHandle);

QObject::connect(&edit,&MkEdit::applyAllMkData,
&doc,&MkTextDocument::applyAllMkDataHandle);

QObject::connect(&edit,&MkEdit::undoStackPushSignal,
&doc,&MkTextDocument::undoStackPush);

QObject::connect(&edit,&MkEdit::undoStackUndoSignal,
&doc,&MkTextDocument::undoStackUndo);

QObject::connect(&edit,&MkEdit::undoStackRedoSignal,
&doc,&MkTextDocument::undoStackRedo);

QObject::connect(&edit,&MkEdit::saveSingleRawBlock,
&doc,&MkTextDocument::saveSingleRawBlockHandler);

QObject::connect(&edit,&MkEdit::saveRawDocument,
&doc,&MkTextDocument::saveRawDocumentHandler);

QObject::connect(&edit,&MkEdit::enterKeyPressed,
&doc,&MkTextDocument::enterKeyPressedHandle);

QObject::connect(&edit,&MkEdit::quoteLeftKeyPressed,
&doc,&MkTextDocument::quoteLeftKeyPressedHandle);

QTextCursor cursor = edit.textCursor();
cursor.setPosition(initialPosition, QTextCursor::MoveAnchor);
edit.setTextCursor(cursor);
QString text = edit.toPlainText();

QScopedPointer<QKeyEvent> keyPressEvent (new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier));
edit.keyPressEvent(keyPressEvent.data());

text = edit.toPlainText();
REQUIRE("``\n```" == text);

QScopedPointer<QKeyEvent> undoKeyPressEvent (new QKeyEvent(QEvent::KeyPress, Qt::Key_Z, Qt::ControlModifier));
edit.keyPressEvent(undoKeyPressEvent.data());
text = edit.toPlainText();
REQUIRE("```\n```" == text);

cursor.setPosition(secondPosition, QTextCursor::MoveAnchor);
edit.setTextCursor(cursor);

edit.keyPressEvent(keyPressEvent.data());
text = edit.toPlainText();
REQUIRE("```\n``" == text);

edit.keyPressEvent(undoKeyPressEvent.data());
text = edit.toPlainText();
REQUIRE("```\n```" == text);
}

0 comments on commit 2c11d2e

Please sign in to comment.