Skip to content

Commit 20881ed

Browse files
committed
test
1 parent 56ef7a0 commit 20881ed

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/textual/css/parse.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@
4040
"nested": (SelectorType.NESTED, (0, 0, 0)),
4141
}
4242

43-
RE_IDENTIFIER = re.compile(r"\#" + IDENTIFIER)
43+
RE_ID_SELECTOR = re.compile(r"\#" + IDENTIFIER)
4444

4545

4646
@lru_cache(maxsize=128)
4747
def is_id_selector(selector: str) -> bool:
48-
"""Is the selector an ID selector, i.e. "#foo"?
48+
"""Is the selector an single ID selector, i.e. "#foo"?
4949
5050
Args:
5151
selector: A CSS selector.
5252
5353
Returns:
5454
`True` if the selector is a simple ID selector, otherwise `False`.
5555
"""
56-
return RE_IDENTIFIER.fullmatch(selector) is not None
56+
return RE_ID_SELECTOR.fullmatch(selector) is not None
5757

5858

5959
def _add_specificity(

tests/css/test_parse.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from textual.color import Color
66
from textual.css.errors import UnresolvedVariableError
7-
from textual.css.parse import substitute_references
7+
from textual.css.parse import is_id_selector, substitute_references
88
from textual.css.scalar import Scalar, Unit
99
from textual.css.stylesheet import Stylesheet, StylesheetParseError
1010
from textual.css.tokenize import tokenize
@@ -1272,3 +1272,25 @@ def test_parse_bad_pseudo_selector_with_suggestion():
12721272
stylesheet.parse()
12731273

12741274
assert error.value.start == (2, 7)
1275+
1276+
1277+
@pytest.mark.parametrize(
1278+
"selector, expected",
1279+
[
1280+
# True cases
1281+
("#foo", True),
1282+
("#bar", True),
1283+
("#f", True),
1284+
# False cases
1285+
("#", False),
1286+
("Foo", False),
1287+
(".foo", False),
1288+
("#5foo", False),
1289+
("#foo .bar", False),
1290+
("#foo>.bar", False),
1291+
("#foo.bar", False),
1292+
],
1293+
)
1294+
def test_is_id_selector(selector: str, expected: bool):
1295+
"""Test is_id_selector is working as expected"""
1296+
assert is_id_selector(selector) is expected

0 commit comments

Comments
 (0)