"""Unit tests for blog slugify utility."""
from __future__ import annotations

import pytest

from blog.bp.post.services.markets import slugify


class TestSlugify:
    def test_basic_ascii(self):
        assert slugify("Hello World") == "hello-world"

    def test_unicode_stripped(self):
        assert slugify("café") == "cafe"

    def test_slashes_to_dashes(self):
        assert slugify("foo/bar") == "foo-bar"

    def test_special_chars(self):
        assert slugify("foo!!bar") == "foo-bar"

    def test_multiple_dashes_collapsed(self):
        assert slugify("foo---bar") == "foo-bar"

    def test_leading_trailing_dashes_stripped(self):
        assert slugify("--foo--") == "foo"

    def test_empty_string_fallback(self):
        assert slugify("") == "market"

    def test_none_fallback(self):
        assert slugify(None) == "market"

    def test_max_len_truncation(self):
        result = slugify("a" * 300, max_len=10)
        assert len(result) <= 10

    def test_truncation_no_trailing_dash(self):
        # "abcde-fgh" truncated to 5 should not end with dash
        result = slugify("abcde fgh", max_len=5)
        assert not result.endswith("-")

    def test_already_clean(self):
        assert slugify("hello-world") == "hello-world"

    def test_numbers_preserved(self):
        assert slugify("item-42") == "item-42"

    def test_accented_characters(self):
        assert slugify("über straße") == "uber-strae"
