1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
import pytest
from textual._slug import TrackedSlugs, slug
@pytest.mark.xdist_group("group1")
@pytest.mark.parametrize(
"text, expected",
[
("test", "test"),
("Test", "test"),
(" Test ", "test"),
("-test-", "-test-"),
("!test!", "test"),
("test!!test", "testtest"),
("test! !test", "test-test"),
("test test", "test-test"),
("test test", "test--test"),
("test test", "test----------test"),
("--test", "--test"),
("test--", "test--"),
("--test--test--", "--test--test--"),
("test!\"#$%&'()*+,-./:;<=>?@[]^_`{|}~test", "test-_test"),
("tëst", "t%C3%ABst"),
("test🙂test", "testtest"),
("test🤷test", "testtest"),
("test🤷🏻♀️test", "testtest"),
],
)
def test_simple_slug(text: str, expected: str) -> None:
"""The simple slug function should produce the expected slug."""
assert slug(text) == expected
@pytest.fixture(scope="module")
def tracker() -> TrackedSlugs:
return TrackedSlugs()
@pytest.mark.xdist_group("group2")
@pytest.mark.parametrize(
"text, expected",
[
("test", "test"),
("test", "test-1"),
("test", "test-2"),
("-test-", "-test-"),
("-test-", "-test--1"),
("test!\"#$%&'()*+,-./:;<=>?@[]^_`{|}~test", "test-_test"),
("test!\"#$%&'()*+,-./:;<=>?@[]^_`{|}~test", "test-_test-1"),
("tëst", "t%C3%ABst"),
("tëst", "t%C3%ABst-1"),
("tëst", "t%C3%ABst-2"),
("test🙂test", "testtest"),
("test🤷test", "testtest-1"),
("test🤷🏻♀️test", "testtest-2"),
("test", "test-3"),
("test", "test-4"),
(" test ", "test-5"),
],
)
def test_tracked_slugs(tracker: TrackedSlugs, text: str, expected: str) -> None:
"""The tracked slugging class should produce the expected slugs."""
assert tracker.slug(text) == expected
|