"""格式定义测试."""

import pytest
from mcp_docx_thesis_server.formats import (
    get_format,
    list_formats,
    SYSU_FORMAT,
    SCNU_FORMAT,
    GENERIC_FORMAT,
)


class TestFormats:
    """测试格式定义."""

    def test_get_format_sysu(self):
        """测试获取中山大学格式."""
        fmt = get_format("sysu")

        assert fmt.name == "sysu"
        assert "中山大学" in fmt.description
        assert fmt.has_cover_page is True
        assert fmt.has_toc is True

    def test_get_format_scnu(self):
        """测试获取华南师范大学格式."""
        fmt = get_format("scnu")

        assert fmt.name == "scnu"
        assert "华南师范大学" in fmt.description
        assert fmt.has_cover_page is True

    def test_get_format_generic(self):
        """测试获取通用格式."""
        fmt = get_format("generic")

        assert fmt.name == "generic"
        assert fmt.has_cover_page is True

    def test_get_format_invalid(self):
        """测试获取无效格式."""
        with pytest.raises(ValueError) as exc_info:
            get_format("invalid_university")

        assert "不支持的大学代码" in str(exc_info.value)

    def test_list_formats(self):
        """测试列出所有格式."""
        formats = list_formats()

        assert "sysu" in formats
        assert "scnu" in formats
        assert "generic" in formats

    def test_sysu_format_settings(self):
        """测试中山大学格式设置."""
        fmt = SYSU_FORMAT

        # 页面设置
        assert fmt.page.top_margin == 2.54
        assert fmt.page.left_margin == 3.17

        # 字体设置
        assert fmt.title_font.name == "黑体"
        assert fmt.body_font.name == "宋体"

        # 段落设置
        assert fmt.body_paragraph.line_spacing == 1.5
        assert fmt.body_paragraph.first_line_indent == 2.0

    def test_scnu_format_settings(self):
        """测试华南师范大学格式设置."""
        fmt = SCNU_FORMAT

        # 页面设置
        assert fmt.page.left_margin == 3.0

        # 特殊要求
        assert fmt.has_abstract_separate_page is False
