Improve support for declarations after nested rule sets.

Partially fixes #3999.
This commit is contained in:
Rodrigo Girão Serrão 2024-01-17 17:11:30 +00:00
parent 828b383b99
commit 18b8a23fd0
No known key found for this signature in database
GPG key ID: 84116786F3295A35
3 changed files with 95 additions and 1 deletions

View file

@ -26,7 +26,8 @@ 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
- Improve support for selector lists in nested CSS https://github.com/Textualize/textual/issues/3969
- Improve support for selector lists in nested TCSS https://github.com/Textualize/textual/issues/3969
- Improve support for rule declarations after nested TCSS rule sets https://github.com/Textualize/textual/issues/3999
## [0.47.1] - 2023-01-05

View file

@ -64,6 +64,7 @@ expect_root_nested = Expect(
whitespace=r"\s+",
comment_start=COMMENT_START,
comment_line=COMMENT_LINE,
declaration_name=r"[a-zA-Z_\-]+\:",
selector_start_id=r"\#" + IDENTIFIER,
selector_start_class=r"\." + IDENTIFIER,
selector_start_universal=r"\*",

View file

@ -987,3 +987,95 @@ def test_nested_css_selector_list_with_ampersand():
location=(0, 36),
),
]
def test_declaration_after_nested_declaration_set():
"""Regression test for https://github.com/Textualize/textual/issues/3999."""
css = "Screen{Label{background:red;}background:green;}"
tokens = list(tokenize(css, ("", "")))
assert tokens == [
Token(
name="selector_start",
value="Screen",
read_from=("", ""),
code=css,
location=(0, 0),
),
Token(
name="declaration_set_start",
value="{",
read_from=("", ""),
code=css,
location=(0, 6),
),
Token(
name="selector_start",
value="Label",
read_from=("", ""),
code=css,
location=(0, 7),
),
Token(
name="declaration_set_start",
value="{",
read_from=("", ""),
code=css,
location=(0, 12),
),
Token(
name="declaration_name",
value="background:",
read_from=("", ""),
code=css,
location=(0, 13),
),
Token(
name="token",
value="red",
read_from=("", ""),
code=css,
location=(0, 24),
),
Token(
name="declaration_end",
value=";",
read_from=("", ""),
code=css,
location=(0, 27),
),
Token(
name="declaration_set_end",
value="}",
read_from=("", ""),
code=css,
location=(0, 28),
),
Token(
name="declaration_name",
value="background:",
read_from=("", ""),
code=css,
location=(0, 29),
),
Token(
name="token",
value="green",
read_from=("", ""),
code=css,
location=(0, 40),
),
Token(
name="declaration_end",
value=";",
read_from=("", ""),
code=css,
location=(0, 45),
),
Token(
name="declaration_set_end",
value="}",
read_from=("", ""),
code=css,
location=(0, 46),
),
]