mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
[css] Add a "Did you mean" suggestion when the value of a color is wrong but we can find a close one
This commit is contained in:
@@ -101,3 +101,47 @@ def test_did_you_mean_for_css_property_names(
|
||||
f'Did you mean "{expected_property_name_suggestion}"?'
|
||||
)
|
||||
assert help_text.bullets[0].markup == expected_suggestion_message
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"css_property_name,css_property_value,expected_color_suggestion",
|
||||
[
|
||||
["color", "blu", "blue"],
|
||||
["background", "chartruse", "chartreuse"],
|
||||
["tint", "ansi_whi", "ansi_white"],
|
||||
["scrollbar-color", "transprnt", "transparent"],
|
||||
["color", "xkcd", None],
|
||||
],
|
||||
)
|
||||
def test_did_you_mean_for_color_names(
|
||||
css_property_name: str, css_property_value: str, expected_color_suggestion
|
||||
):
|
||||
stylesheet = Stylesheet()
|
||||
css = """
|
||||
* {
|
||||
border: blue;
|
||||
${PROPERTY}: ${VALUE};
|
||||
}
|
||||
""".replace(
|
||||
"${PROPERTY}", css_property_name
|
||||
).replace(
|
||||
"${VALUE}", css_property_value
|
||||
)
|
||||
|
||||
stylesheet.add_source(css)
|
||||
with pytest.raises(StylesheetParseError) as err:
|
||||
stylesheet.parse()
|
||||
|
||||
_, help_text = err.value.errors.rules[0].errors[0] # type: Any, HelpText
|
||||
displayed_css_property_name = css_property_name.replace("_", "-")
|
||||
assert (
|
||||
help_text.summary
|
||||
== f"Invalid value for the [i]{displayed_css_property_name}[/] property"
|
||||
)
|
||||
|
||||
first_bullet = help_text.bullets[0]
|
||||
if expected_color_suggestion is not None:
|
||||
expected_suggestion_message = f'Did you mean "{expected_color_suggestion}"?'
|
||||
assert first_bullet.markup == expected_suggestion_message
|
||||
else:
|
||||
assert "Did you mean" not in first_bullet.markup
|
||||
|
||||
Reference in New Issue
Block a user