Skip to content

Commit

Permalink
Cover a few more cases when testing #4301
Browse files Browse the repository at this point in the history
Co-authored-by: TomJGooding <[email protected]>
  • Loading branch information
davep and TomJGooding committed Mar 19, 2024
1 parent 6da3087 commit 7d06a12
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions tests/text_area/test_issue_4301.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from itertools import product

import pytest

from textual.app import App, ComposeResult
from textual.widgets import TextArea
from textual.widgets.text_area import Selection

TEST_TEXT = "\n".join(f"01234567890 - {n}" for n in range(10))
TEST_SELECTION = Selection((2, 5), (0, 5))
TEST_SELECTED_TEXT = "567890 - 0\n01234567890 - 1\n01234"
TEST_REPLACEMENT = "A"
TEST_RESULT_TEXT = TEST_TEXT.replace(TEST_SELECTED_TEXT, TEST_REPLACEMENT)


class TextAreaApp(App[None]):
Expand All @@ -15,14 +16,23 @@ def compose(self) -> ComposeResult:
yield TextArea(TEST_TEXT)


async def test_issue_4301_reproduction() -> None:
@pytest.mark.parametrize(
"selection, edit",
product(
[Selection((0, 5), (2, 5)), Selection((2, 5), (0, 5))],
["A", "delete", "backspace"],
),
)
async def test_issue_4301_reproduction(selection: Selection, edit: str) -> None:
"""Test https://github.com/Textualize/textual/issues/4301"""

async with (app := TextAreaApp()).run_test() as pilot:
assert app.query_one(TextArea).text == TEST_TEXT
app.query_one(TextArea).selection = TEST_SELECTION
app.query_one(TextArea).selection = selection
assert app.query_one(TextArea).selected_text == TEST_SELECTED_TEXT
await pilot.press("A")
assert app.query_one(TextArea).text == TEST_RESULT_TEXT
await pilot.press(edit)
await pilot.press("ctrl+z")
assert app.query_one(TextArea).text == TEST_TEXT
# Note that the real test here is that the following code doesn't
# result in a crash; everything above should really be a given.
await pilot.press(*(["down"] * 10))

0 comments on commit 7d06a12

Please sign in to comment.