32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
"""语言规则生成函数测试。"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
|
|
|
|
from prompt import language_rule
|
|
|
|
|
|
class TestLanguageRule:
|
|
"""测试语言规则生成函数。"""
|
|
|
|
def test_explicit_language(self) -> None:
|
|
"""测试显式指定语言时,提示中包含该语言名称。"""
|
|
result = language_rule("test content", "Chinese")
|
|
assert "Chinese" in result
|
|
|
|
def test_auto_with_chinese_content(self) -> None:
|
|
"""测试中文内容自动检测。"""
|
|
result = language_rule("这是一段中文内容", None)
|
|
assert "简体中文" in result
|
|
|
|
def test_auto_with_english_content(self) -> None:
|
|
"""测试英文内容自动检测。"""
|
|
result = language_rule("This is English content", None)
|
|
assert "源文档" in result
|
|
|
|
def test_auto_detection_string(self) -> None:
|
|
"""测试传入 "auto" 字符串时触发自动检测。"""
|
|
result = language_rule("test", "auto")
|
|
assert "源文档" in result |