diff options
| author | godosa <godosa@godosa.eu> | 2026-10-07 07:27:17 +0200 |
|---|---|---|
| committer | godosa <godosa@godosa.eu> | 2026-10-07 07:27:17 +0200 |
| commit | 81d4e80fd5aabe4e80f58e960affa795cf7d34ec (patch) | |
| tree | e98eeac2af6af63aa4287bba1f6d4a3af26b5727 /tests/test_search.py | |
| download | workflow-81d4e80fd5aabe4e80f58e960affa795cf7d34ec.tar.gz workflow-81d4e80fd5aabe4e80f58e960affa795cf7d34ec.zip | |
workflow: initial public history
Diffstat (limited to 'tests/test_search.py')
| -rw-r--r-- | tests/test_search.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/test_search.py b/tests/test_search.py new file mode 100644 index 0000000..4c02520 --- /dev/null +++ b/tests/test_search.py @@ -0,0 +1,78 @@ +import sys +import unittest +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) +from wflib import search as S +from wflib import tasks as T + +TASKS = """\ +## Awaiting your decision + +## Pending + +- **t-guards** [P2] (1h): Guards notice lock picking. Port the notify function. + - Steps: reaction drop + Ref: docs/ai.md + +- **t-throw** [P2] (5h): Thrown weapons and grenades. NPCs throw items. + - Steps: guard against throwing into allies + +- **t-upgrade** [P3] (1h): Shop upgrenade typo. Fix spelling. + +## Needs human + +## Deferred +""" +ARCHIVE = "# Archive\n\n- 2026-09-01 **t-wear** Weapon wear — guards bust weapons\n- old entry about grenades\n" +DOCS = { + "docs/ai.md": "# AI notes\n\nIntro.\n\n## Guards and thieves\n\nText about catching.\n\n## Combat\n\nA guard attacks. Grenade use.\n", +} + + +def run(*words, **kw): + return S.search(list(words), T.parse(TASKS), ARCHIVE, DOCS, **kw) + + +class SearchTest(unittest.TestCase): + def test_title_outranks_body(self): + hits = run("guard", kinds={"task"}) + self.assertEqual([h.where for h in hits], ["t-guards", "t-throw"]) + self.assertEqual(hits[0].line, "Guards notice lock picking. Port the notify function.") + self.assertEqual(hits[1].line, "- Steps: guard against throwing into allies") + + def test_prefix_matches_word_start_only(self): + self.assertEqual([h.where for h in run("grenad", kinds={"task"})], ["t-throw"]) + + def test_all_words_outrank_one_strong_word(self): + hits = run("throwing", "allies", "guards", kinds={"task"}) + self.assertEqual([h.where for h in hits], ["t-throw", "t-guards"]) + + def test_kinds_and_tie_order(self): + hits = run("guard") + self.assertEqual([(h.kind, h.where) for h in hits], + [("task", "t-guards"), ("doc", "docs/ai.md:5"), ("archive", "archive:3"), + ("task", "t-throw"), ("doc", "docs/ai.md:9")]) + self.assertEqual(hits[1].label, "Guards and thieves") + self.assertEqual(hits[4].line, "A guard attacks. Grenade use.") + + def test_archive_filter(self): + hits = run("grenades", kinds={"archive"}) + self.assertEqual([(h.where, h.line) for h in hits], [("archive:4", "old entry about grenades")]) + + def test_limit(self): + self.assertEqual(len(run("guard", limit=2)), 2) + + def test_case_and_regex_chars(self): + self.assertEqual([h.where for h in run("GUARD", kinds={"task"})], ["t-guards", "t-throw"]) + self.assertEqual(run("a.i", "(x"), []) + + def test_id_matches(self): + self.assertEqual([h.where for h in run("t-throw", kinds={"task"})], ["t-throw"]) + + def test_no_words(self): + self.assertEqual(run(), []) + + +if __name__ == "__main__": + unittest.main() |
