from krrkt.rules.loader import load_rules, load_patterns, load_config

class TestLoadRules:
    def test_loads_rules_dict(self):
        rules = load_rules()
        assert isinstance(rules, dict)
        assert "categories" in rules
        assert len(rules["categories"]) > 0

    def test_rule_has_required_fields(self):
        rules = load_rules()
        for cat in rules["categories"]:
            assert "name" in cat
            assert "weight" in cat
            assert "style" in cat
            assert "tab" in cat
            assert "description" in cat

    def test_has_known_categories(self):
        rules = load_rules()
        names = [c["name"] for c in rules["categories"]]
        assert "Канцеляризм" in names
        assert "Усилитель" in names
        assert "Корпоративный штамп" in names

class TestLoadPatterns:
    def test_loads_patterns(self):
        patterns = load_patterns()
        assert "phrases" in patterns
        assert "lemmas" in patterns
        assert len(patterns["phrases"]) > 0
        assert len(patterns["lemmas"]) > 0

    def test_phrase_has_required_fields(self):
        patterns = load_patterns()
        for p in patterns["phrases"]:
            assert "pattern" in p
            assert "rule" in p
            assert "weight" in p

    def test_lemma_has_required_fields(self):
        patterns = load_patterns()
        for l in patterns["lemmas"]:
            assert "lemma" in l
            assert "rule" in l
            assert "weight" in l

    def test_has_regex(self):
        patterns = load_patterns()
        assert "regex" in patterns
        assert len(patterns["regex"]) > 0

class TestLoadConfig:
    def test_loads_config(self):
        config = load_config()
        assert "model" in config
        assert "server" in config
        assert "scoring" in config

    def test_default_model(self):
        config = load_config()
        assert config["model"] == "claude-sonnet-4-6"
