More tests
Some checks failed
Lint / test (push) Waiting to run
Trivy / test (push) Waiting to run
CI / test (push) Has been cancelled

This commit is contained in:
Miguel Jacq 2025-12-23 17:53:26 +11:00
parent 5f18b6daec
commit c853be5eff
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9
4 changed files with 244 additions and 3 deletions

View file

@ -3,8 +3,8 @@ from bouquin.code_block_editor_dialog import (
CodeBlockEditorDialog,
CodeEditorWithLineNumbers,
)
from PySide6.QtCore import QRect, QSize
from PySide6.QtGui import QFont, QPaintEvent
from PySide6.QtCore import QRect, QSize, Qt
from PySide6.QtGui import QFont, QPaintEvent, QTextCursor
from PySide6.QtWidgets import QPushButton
@ -323,3 +323,42 @@ def test_code_editor_viewport_margins(qtbot, app):
assert margins.top() == 0
assert margins.right() == 0
assert margins.bottom() == 0
def test_code_editor_retains_indentation_on_enter(qtbot, app):
"""Pressing Enter on an indented line retains indentation in code editor."""
editor = CodeEditorWithLineNumbers()
qtbot.addWidget(editor)
editor.setPlainText("\tfoo")
editor.show()
cursor = editor.textCursor()
cursor.movePosition(QTextCursor.End)
editor.setTextCursor(cursor)
qtbot.keyPress(editor, Qt.Key_Return)
qtbot.wait(0)
assert editor.toPlainText().endswith("\tfoo\n\t")
def test_code_editor_double_enter_on_empty_indent_resets(qtbot, app):
"""Second Enter on an indentation-only line clears the indent in code editor."""
editor = CodeEditorWithLineNumbers()
qtbot.addWidget(editor)
editor.setPlainText("\tfoo")
editor.show()
cursor = editor.textCursor()
cursor.movePosition(QTextCursor.End)
editor.setTextCursor(cursor)
qtbot.keyPress(editor, Qt.Key_Return)
qtbot.wait(0)
assert editor.toPlainText().endswith("\tfoo\n\t")
qtbot.keyPress(editor, Qt.Key_Return)
qtbot.wait(0)
assert editor.toPlainText().endswith("\tfoo\n\n")
assert editor.textCursor().block().text() == ""