Skip to content

Commit

Permalink
Test nested CSS worked at higher level.
Browse files Browse the repository at this point in the history
Addresses review feedback. See the three comments starting at #4040 (comment).
  • Loading branch information
rodrigogiraoserrao committed Feb 15, 2024
1 parent 3313787 commit 3c18e47
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 181 deletions.
48 changes: 48 additions & 0 deletions tests/css/test_nested_css.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,54 @@ async def test_nest_app():
assert app.query_one("#foo .paul").styles.background == Color.parse("blue")


class ListOfNestedSelectorsApp(App[None]):
CSS = """
Label {
&.foo, &.bar {
background: red;
}
}
"""

def compose(self) -> ComposeResult:
yield Label("one", classes="foo")
yield Label("two", classes="bar")
yield Label("three", classes="heh")


async def test_lists_of_selectors_in_nested_css() -> None:
"""Regression test for https://github.com/Textualize/textual/issues/3969."""
app = ListOfNestedSelectorsApp()
red = Color.parse("red")
async with app.run_test():
assert app.query_one(".foo").styles.background == red
assert app.query_one(".bar").styles.background == red
assert app.query_one(".heh").styles.background != red


class DeclarationAfterNestedApp(App[None]):
# css = "Screen{Label{background:red;}background:green;}"
CSS = """
Screen {
Label {
background: red;
}
background: green;
}
"""

def compose(self) -> ComposeResult:
yield Label("one")


async def test_rule_declaration_after_nested() -> None:
"""Regression test for https://github.com/Textualize/textual/issues/3999."""
app = DeclarationAfterNestedApp()
async with app.run_test():
assert app.screen.styles.background == Color.parse("green")
assert app.query_one(Label).styles.background == Color.parse("red")


@pytest.mark.parametrize(
("css", "exception"),
[
Expand Down
181 changes: 0 additions & 181 deletions tests/css/test_tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,184 +898,3 @@ def test_allow_new_lines():
),
]
assert list(tokenize(css, ("", ""))) == expected


def test_nested_css_selector_list_with_ampersand():
"""Regression test for https://github.com/Textualize/textual/issues/3969."""
css = "Label{&.foo,&.bar{border:solid red;}}"
tokens = list(tokenize(css, ("", "")))
assert tokens == [
Token(
name="selector_start",
value="Label",
read_from=("", ""),
code=css,
location=(0, 0),
),
Token(
name="declaration_set_start",
value="{",
read_from=("", ""),
code=css,
location=(0, 5),
),
Token(name="nested", value="&", read_from=("", ""), code=css, location=(0, 6)),
Token(
name="selector_class",
value=".foo",
read_from=("", ""),
code=css,
location=(0, 7),
),
Token(
name="new_selector",
value=",",
read_from=("", ""),
code=css,
location=(0, 11),
),
Token(name="nested", value="&", read_from=("", ""), code=css, location=(0, 12)),
Token(
name="selector_class",
value=".bar",
read_from=("", ""),
code=css,
location=(0, 13),
),
Token(
name="declaration_set_start",
value="{",
read_from=("", ""),
code=css,
location=(0, 17),
),
Token(
name="declaration_name",
value="border:",
read_from=("", ""),
code=css,
location=(0, 18),
),
Token(
name="token", value="solid", read_from=("", ""), code=css, location=(0, 25)
),
Token(
name="whitespace", value=" ", read_from=("", ""), code=css, location=(0, 30)
),
Token(
name="token", value="red", read_from=("", ""), code=css, location=(0, 31)
),
Token(
name="declaration_end",
value=";",
read_from=("", ""),
code=css,
location=(0, 34),
),
Token(
name="declaration_set_end",
value="}",
read_from=("", ""),
code=css,
location=(0, 35),
),
Token(
name="declaration_set_end",
value="}",
read_from=("", ""),
code=css,
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),
),
]

0 comments on commit 3c18e47

Please sign in to comment.