mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Fix regex, fix some broken tests around HSL support
This commit is contained in:
@@ -63,7 +63,7 @@ RE_COLOR = re.compile(
|
|||||||
rgb{OPEN_BRACE}({DECIMAL}{COMMA}{DECIMAL}{COMMA}{DECIMAL}){CLOSE_BRACE}$|
|
rgb{OPEN_BRACE}({DECIMAL}{COMMA}{DECIMAL}{COMMA}{DECIMAL}){CLOSE_BRACE}$|
|
||||||
rgba{OPEN_BRACE}({DECIMAL}{COMMA}{DECIMAL}{COMMA}{DECIMAL}{COMMA}{DECIMAL}){CLOSE_BRACE}$|
|
rgba{OPEN_BRACE}({DECIMAL}{COMMA}{DECIMAL}{COMMA}{DECIMAL}{COMMA}{DECIMAL}){CLOSE_BRACE}$|
|
||||||
hsl{OPEN_BRACE}({DECIMAL}{COMMA}{PERCENT}{COMMA}{PERCENT}){CLOSE_BRACE}$|
|
hsl{OPEN_BRACE}({DECIMAL}{COMMA}{PERCENT}{COMMA}{PERCENT}){CLOSE_BRACE}$|
|
||||||
hsla{OPEN_BRACE}({DECIMAL}{COMMA}{PERCENT}{COMMA}{PERCENT}{COMMA}{DECIMAL}){CLOSE_BRACE}$|
|
hsla{OPEN_BRACE}({DECIMAL}{COMMA}{PERCENT}{COMMA}{PERCENT}{COMMA}{DECIMAL}){CLOSE_BRACE}$
|
||||||
""",
|
""",
|
||||||
re.VERBOSE,
|
re.VERBOSE,
|
||||||
)
|
)
|
||||||
@@ -290,7 +290,11 @@ class Color(NamedTuple):
|
|||||||
if color_match is None:
|
if color_match is None:
|
||||||
error_message = f"failed to parse {color_text!r} as a color"
|
error_message = f"failed to parse {color_text!r} as a color"
|
||||||
suggested_color = None
|
suggested_color = None
|
||||||
if not color_text.startswith("#") and not color_text.startswith("rgb"):
|
if (
|
||||||
|
not color_text.startswith("#")
|
||||||
|
and not color_text.startswith("rgb")
|
||||||
|
and not color_text.startswith("hsl")
|
||||||
|
):
|
||||||
# Seems like we tried to use a color name: let's try to find one that is close enough:
|
# Seems like we tried to use a color name: let's try to find one that is close enough:
|
||||||
suggested_color = get_suggestion(color_text, COLOR_NAME_TO_RGB.keys())
|
suggested_color = get_suggestion(color_text, COLOR_NAME_TO_RGB.keys())
|
||||||
if suggested_color:
|
if suggested_color:
|
||||||
|
|||||||
@@ -32,9 +32,6 @@ from textual.css.tokenizer import TokenizeError
|
|||||||
["red 4", pytest.raises(StylesheetParseError), None], # space in it
|
["red 4", pytest.raises(StylesheetParseError), None], # space in it
|
||||||
["1", pytest.raises(StylesheetParseError), None], # invalid value
|
["1", pytest.raises(StylesheetParseError), None], # invalid value
|
||||||
["()", pytest.raises(TokenizeError), None], # invalid tokens
|
["()", pytest.raises(TokenizeError), None], # invalid tokens
|
||||||
# TODO: allow spaces in rgb/rgba expressions?
|
|
||||||
["rgb(200, 90, 30)", pytest.raises(TokenizeError), None],
|
|
||||||
["rgba(200,90,30, 0.4)", pytest.raises(TokenizeError), None],
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_color_property_parsing(css_value, expectation, expected_color):
|
def test_color_property_parsing(css_value, expectation, expected_color):
|
||||||
|
|||||||
Reference in New Issue
Block a user