mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
[css] Address "did you mean" PR feedback
This commit is contained in:
@@ -64,6 +64,7 @@ def test_color_property_parsing(css_value, expectation, expected_color):
|
||||
["backgroundu", "background"],
|
||||
["bckgroundu", "background"],
|
||||
["ofset-x", "offset-x"],
|
||||
["ofst_y", "offset-y"],
|
||||
["colr", "color"],
|
||||
["colour", "color"],
|
||||
["wdth", "width"],
|
||||
@@ -73,7 +74,7 @@ def test_color_property_parsing(css_value, expectation, expected_color):
|
||||
],
|
||||
)
|
||||
def test_did_you_mean_for_css_property_names(
|
||||
css_property_name, expected_property_name_suggestion
|
||||
css_property_name: str, expected_property_name_suggestion
|
||||
):
|
||||
stylesheet = Stylesheet()
|
||||
css = """
|
||||
@@ -90,12 +91,15 @@ def test_did_you_mean_for_css_property_names(
|
||||
stylesheet.parse()
|
||||
|
||||
_, help_text = err.value.errors.rules[0].errors[0] # type: Any, HelpText
|
||||
assert help_text.summary == f"Invalid CSS property [i]{css_property_name}[/]"
|
||||
displayed_css_property_name = css_property_name.replace("_", "-")
|
||||
assert (
|
||||
help_text.summary == f"Invalid CSS property [i]{displayed_css_property_name}[/]"
|
||||
)
|
||||
|
||||
expected_bullets_length = 1 if expected_property_name_suggestion else 0
|
||||
assert len(help_text.bullets) == expected_bullets_length
|
||||
if expected_property_name_suggestion is not None:
|
||||
expected_suggestion_message = (
|
||||
f"Did you mean [i]{expected_property_name_suggestion}[/]?"
|
||||
f'Did you mean "{expected_property_name_suggestion}"?'
|
||||
)
|
||||
assert help_text.bullets[0].markup == expected_suggestion_message
|
||||
|
||||
35
tests/test_suggestions.py
Normal file
35
tests/test_suggestions.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import pytest
|
||||
|
||||
from textual.suggestions import get_suggestion, get_suggestions
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"word, possible_words, expected_result",
|
||||
(
|
||||
["background", ("background",), "background"],
|
||||
["backgroundu", ("background",), "background"],
|
||||
["bkgrund", ("background",), "background"],
|
||||
["llow", ("background",), None],
|
||||
["llow", ("background", "yellow"), "yellow"],
|
||||
["yllow", ("background", "yellow", "ellow"), "yellow"],
|
||||
),
|
||||
)
|
||||
def test_get_suggestion(word, possible_words, expected_result):
|
||||
assert get_suggestion(word, possible_words) == expected_result
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"word, possible_words, count, expected_result",
|
||||
(
|
||||
["background", ("background",), 1, ["background"]],
|
||||
["backgroundu", ("background",), 1, ["background"]],
|
||||
["bkgrund", ("background",), 1, ["background"]],
|
||||
["llow", ("background",), 1, []],
|
||||
["llow", ("background", "yellow"), 1, ["yellow"]],
|
||||
["yllow", ("background", "yellow", "ellow"), 1, ["yellow"]],
|
||||
["yllow", ("background", "yellow", "ellow"), 2, ["yellow", "ellow"]],
|
||||
["yllow", ("background", "yellow", "red"), 2, ["yellow"]],
|
||||
),
|
||||
)
|
||||
def test_get_suggestions(word, possible_words, count, expected_result):
|
||||
assert get_suggestions(word, possible_words, count) == expected_result
|
||||
Reference in New Issue
Block a user