Skip to content

Commit

Permalink
Add regression tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigogiraoserrao committed Jan 16, 2024
1 parent 5f0af2d commit 2d0591a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- `SelectionList` option IDs are usable as soon as the widget is instantiated https://github.com/Textualize/textual/issues/3903
- Fix issue with `Strip.crop` when crop window start aligned with strip end https://github.com/Textualize/textual/pull/3998
- Fixed Strip.crop_extend https://github.com/Textualize/textual/pull/4011
- Widgets could be created with IDs that you couldn't query back https://github.com/Textualize/textual/issues/3954


## [0.47.1] - 2023-01-05
Expand Down
41 changes: 39 additions & 2 deletions tests/css/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pytest

from textual.color import Color
from textual.css.errors import UnresolvedVariableError
from textual.css.parse import substitute_references
from textual.css.errors import InvalidIDError, UnresolvedVariableError
from textual.css.parse import substitute_references, validate_identifier
from textual.css.scalar import Scalar, Unit
from textual.css.stylesheet import Stylesheet, StylesheetParseError
from textual.css.tokenize import tokenize
Expand Down Expand Up @@ -1272,3 +1272,40 @@ def test_parse_bad_pseudo_selector_with_suggestion():
stylesheet.parse()

assert error.value.start == (2, 7)


@pytest.mark.parametrize(
"identifier",
[
"the",
"quick",
"brown",
"f0x",
"jump5",
"ov3r",
"_the__",
"l4zy_",
"_d0g",
],
)
def test_identifier_validation_passes(identifier: str):
assert validate_identifier(identifier) == identifier


@pytest.mark.parametrize(
"identifier",
[
" the",
"quick ",
"bro wn",
"f0x&",
"+jump5",
"0v3r",
"—the",
"läzy_",
"_d0g!",
],
)
def test_identifier_validation_fails(identifier: str):
with pytest.raises(InvalidIDError):
validate_identifier(identifier)
23 changes: 22 additions & 1 deletion tests/test_dom.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from textual.css.errors import StyleValueError
from textual.css.errors import InvalidIDError, StyleValueError
from textual.dom import BadIdentifier, DOMNode


Expand Down Expand Up @@ -259,3 +259,24 @@ def test_walk_children_with_self_breadth(search):
]

assert children == ["f", "e", "d", "c", "b", "a"]


@pytest.mark.parametrize(
"identifier",
[
" bad",
" terrible ",
"worse! ",
"&ampersand",
"amper&sand",
"ampersand&",
"2_leading_digits",
"água", # water
"cão", # dog
"@'/.23",
],
)
def test_id_validation(identifier: str):
"""Regression test for https://github.com/Textualize/textual/issues/3954."""
with pytest.raises(InvalidIDError):
DOMNode(id=identifier)

0 comments on commit 2d0591a

Please sign in to comment.