|
| 1 | +import pytest |
| 2 | + |
| 3 | +from textual.geometry import Offset |
| 4 | +from textual.selection import Selection |
| 5 | + |
| 6 | + |
| 7 | +@pytest.mark.parametrize( |
| 8 | + "text,selection,expected", |
| 9 | + [ |
| 10 | + ("Hello", Selection(None, None), "Hello"), |
| 11 | + ("Hello\nWorld", Selection(None, None), "Hello\nWorld"), |
| 12 | + ("Hello\nWorld", Selection(Offset(0, 1), None), "World"), |
| 13 | + ("Hello\nWorld", Selection(None, Offset(5, 0)), "Hello"), |
| 14 | + ("Foo", Selection(Offset(0, 0), Offset(1, 0)), "F"), |
| 15 | + ("Foo", Selection(Offset(1, 0), Offset(2, 0)), "o"), |
| 16 | + ("Foo", Selection(Offset(0, 0), Offset(2, 0)), "Fo"), |
| 17 | + ("Foo", Selection(Offset(0, 0), None), "Foo"), |
| 18 | + ], |
| 19 | +) |
| 20 | +def test_extract(text: str, selection: Selection, expected: str) -> None: |
| 21 | + """Test Selection.extract""" |
| 22 | + assert selection.extract(text) == expected |
0 commit comments