import unittest
from pathlib import Path
from bot.lib import townlong

FIX = Path(__file__).parent / "fixtures"


class TestExtractGlobals(unittest.TestCase):
    def test_extracts_function_keyword_form(self):
        text = (FIX / "townlong-old.lua").read_text(encoding="utf-8")
        names = townlong.extract_global_function_names(text)
        self.assertIn("GetSpellInfo", names)
        self.assertIn("UnitName", names)

    def test_extracts_assignment_form(self):
        text = (FIX / "townlong-old.lua").read_text(encoding="utf-8")
        names = townlong.extract_global_function_names(text)
        self.assertIn("GetSpellDescription", names)

    def test_skips_dotted_or_namespaced_names(self):
        text = (FIX / "townlong-new.lua").read_text(encoding="utf-8")
        names = townlong.extract_global_function_names(text)
        # `C_Spell.GetSpellInfo` is namespaced and intentionally not captured in Phase 1.
        self.assertNotIn("GetSpellInfo", names)
        self.assertNotIn("C_Spell.GetSpellInfo", names)
        self.assertIn("UnitFullName", names)


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