"""Tests for utility functions."""

from yaml_doctor.models import Grade, Severity
from yaml_doctor.utils import grade_color, score_bar, severity_icon, truncate


class TestSeverityIcon:
    def test_critical(self):
        assert severity_icon(Severity.CRITICAL) == "🔴"

    def test_high(self):
        assert severity_icon(Severity.HIGH) == "🟠"

    def test_medium(self):
        assert severity_icon(Severity.MEDIUM) == "🟡"

    def test_low(self):
        assert severity_icon(Severity.LOW) == "🔵"

    def test_info(self):
        assert severity_icon(Severity.INFO) == "⚪"


class TestGradeColor:
    def test_a_plus(self):
        assert grade_color(Grade.A_PLUS) == "green"

    def test_a(self):
        assert grade_color(Grade.A) == "green"

    def test_b(self):
        assert grade_color(Grade.B) == "yellow"

    def test_c(self):
        assert grade_color(Grade.C) == "yellow"

    def test_d(self):
        assert grade_color(Grade.D) == "red"

    def test_f(self):
        assert grade_color(Grade.F) == "red"


class TestScoreBar:
    def test_bar_100(self):
        bar = score_bar(100)
        assert "█" in bar

    def test_bar_50(self):
        bar = score_bar(50)
        assert "█" in bar or "░" in bar

    def test_bar_0(self):
        bar = score_bar(0)
        assert "░" in bar


class TestTruncate:
    def test_short(self):
        assert truncate("hello", 10) == "hello"

    def test_long(self):
        result = truncate("hello world this is long", 10)
        assert len(result) == 11  # 10 + "…"
        assert result.endswith("…")

    def test_exact(self):
        assert truncate("hello", 5) == "hello"
