"""Unit tests for ``_evidence_kind_to_role`` (query/form normalization).

Run: cd be0 && python -m unittest tests.test_evidence_kind_parsing -v
"""

from __future__ import annotations

import unittest


class EvidenceKindParsingTests(unittest.TestCase):
    def test_plain_strings(self) -> None:
        from main import _evidence_kind_to_role

        self.assertEqual(_evidence_kind_to_role("research"), "research_evidence")
        self.assertEqual(_evidence_kind_to_role("TextBook"), "textbook_evidence")
        self.assertEqual(_evidence_kind_to_role("TECHNICAL"), "technical_evidence")
        self.assertIsNone(_evidence_kind_to_role("other"))

    def test_prefers_valid_entry_in_list(self) -> None:
        """Duplicate or noisy ``kind=`` values: first matching token wins."""
        from main import _evidence_kind_to_role

        self.assertEqual(_evidence_kind_to_role(["", "bad", "research"]), "research_evidence")
        self.assertEqual(_evidence_kind_to_role(["research", "textbook"]), "research_evidence")

    def test_strips_zwsp_and_bom(self) -> None:
        from main import _evidence_kind_to_role

        self.assertEqual(_evidence_kind_to_role("research\u200b"), "research_evidence")
        self.assertEqual(_evidence_kind_to_role("\ufeffresearch"), "research_evidence")


if __name__ == "__main__":
    unittest.main()
