"""
Smoke tests for logging utilities to ensure they work correctly.
"""
import pytest


def test__s_sanitizes_arrows():
    """Test that _s() correctly translates Unicode arrows to ASCII."""
    from fmatch.saas.utils import _s
    
    # Test various arrow translations
    assert "<->" in _s("A ↔ B")
    assert "->" in _s("A → B")
    assert "<-" in _s("A ← B")
    assert "->" in _s("A ⇒ B")
    assert "<-" in _s("A ⇐ B")
    assert "<->" in _s("A ⇔ B")
    
    # Test combined arrows
    assert "A -> B <- C" in _s("A → B ← C")
    assert "Start <-> End" in _s("Start ↔ End")
    
    # Test that regular text passes through
    assert "Normal text" in _s("Normal text")
    assert "123456789" in _s(123456789)
    
    # Test encoding safety (no exceptions)
    try:
        result = _s("Complex: → ← ↔ ⇒ ⇐ ⇔ 中文 日本語 한글")
        assert result is not None
        assert isinstance(result, str)
    except Exception:
        pytest.fail("_s() should not raise exceptions")


def test__s_handles_non_strings():
    """Test that _s() correctly handles non-string inputs."""
    from fmatch.saas.utils import _s
    
    # Numbers
    assert "42" in _s(42)
    assert "3.14" in _s(3.14)
    
    # None
    assert "None" in _s(None)
    
    # Lists/dicts
    assert "[1, 2, 3]" in _s([1, 2, 3])
    assert "{'key': 'value'}" in _s({"key": "value"}) or "{'key': 'value'}" == _s({"key": "value"}).replace('"', "'")
    
    # Objects with __str__
    class CustomObj:
        def __str__(self):
            return "CustomObj → instance"
    
    obj = CustomObj()
    result = _s(obj)
    assert "CustomObj" in result
    assert "->" in result  # Arrow should be translated
    assert "→" not in result  # Unicode arrow should be removed


def test__s_windows_compatibility():
    """Test that _s() produces Windows-compatible output."""
    from fmatch.saas.utils import _s
    
    # Test that output can be encoded to cp1252
    test_cases = [
        "Simple ASCII",
        "Arrows: → ← ↔",
        "Mixed: Hello → World ← Universe ↔ Everything",
        "Numbers and symbols: 123 !@#$%^&*()",
    ]
    
    for test_case in test_cases:
        result = _s(test_case)
        try:
            # This should not raise an exception
            encoded = result.encode("cp1252")
            assert encoded is not None
        except UnicodeEncodeError:
            pytest.fail(f"_s() output should be cp1252 compatible, failed on: {test_case}")


if __name__ == "__main__":
    # Run basic smoke test when executed directly
    test__s_sanitizes_arrows()
    test__s_handles_non_strings()
    test__s_windows_compatibility()
    print("✓ All logging utils smoke tests passed!")