File tree Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -128,16 +128,17 @@ def slug_for_tcss_id(text: str) -> str:
128128 Returns:
129129 A slugified version of text suitable for use as a TCSS id.
130130 """
131+
131132 slug = "" .join (
132133 (
133134 character
134135 if character in VALID_ID_CHARACTERS
135136 else ord (character ).__format__ ("x" )
136137 )
137- for character in text
138+ for character in text . casefold (). replace ( " " , "-" )
138139 )
139140 if not slug :
140- return "- "
141+ return "_ "
141142 if slug [0 ].isdecimal ():
142- return f"- { slug } "
143+ return f"_ { slug } "
143144 return slug
Original file line number Diff line number Diff line change 11import pytest
22
3- from textual ._slug import TrackedSlugs , slug_for_tcss_id
3+ from textual ._slug import TrackedSlugs , slug , slug_for_tcss_id
4+ from textual .dom import check_identifiers
45
56
67@pytest .mark .xdist_group ("group1" )
3132)
3233def test_simple_slug (text : str , expected : str ) -> None :
3334 """The simple slug function should produce the expected slug."""
34- assert slug_for_tcss_id (text ) == expected
35+ assert slug (text ) == expected
3536
3637
3738@pytest .fixture (scope = "module" )
@@ -64,3 +65,24 @@ def tracker() -> TrackedSlugs:
6465def test_tracked_slugs (tracker : TrackedSlugs , text : str , expected : str ) -> None :
6566 """The tracked slugging class should produce the expected slugs."""
6667 assert tracker .slug (text ) == expected
68+
69+
70+ @pytest .mark .parametrize (
71+ "text, expected" ,
72+ [
73+ ("" , "_" ),
74+ (" " , "-" ),
75+ ("5" , "_5" ),
76+ ("a" , "a" ),
77+ ("hello world" , "hello-world" ),
78+ ("🙂" , "_1f642" ),
79+ ("🙂🙂" , "_1f6421f642" ),
80+ ("Foo🙂" , "foo1f642" ),
81+ ("ß" , "ss" ),
82+ ],
83+ )
84+ def test_slug_for_tcss_id (text : str , expected : str ) -> None :
85+ """Test the slug_for_tcss_id"""
86+ slug = slug_for_tcss_id (text )
87+ assert slug == expected
88+ check_identifiers (slug )
You can’t perform that action at this time.
0 commit comments