File: test_comments.py

package info (click to toggle)
textual-textarea 0.17.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 720 kB
  • sloc: python: 3,195; makefile: 25
file content (30 lines) | stat: -rw-r--r-- 895 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pytest
from textual.app import App
from textual.widgets.text_area import Selection

from textual_textarea import TextEditor


@pytest.mark.parametrize(
    "language,expected_marker",
    [
        ("python", "# "),
        ("sql", "-- "),
        # ("mysql", "# "),
        # ("c", "// "),
    ],
)
@pytest.mark.asyncio
async def test_comments(app: App, language: str, expected_marker: str) -> None:
    async with app.run_test() as pilot:
        ta = app.query_one("#ta", expect_type=TextEditor)
        ta.language = language
        original_text = "foo bar baz"
        ta.text = original_text
        ta.selection = Selection((0, 0), (0, 0))

        await pilot.press("ctrl+underscore")  # alias for ctrl+/
        assert ta.text == f"{expected_marker}{original_text}"

        await pilot.press("ctrl+underscore")  # alias for ctrl+/
        assert ta.text == f"{original_text}"