"""Tests for tagger.py — keyword-based tag suggestion.""" import sys import os sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) from tagger import suggest_tags def test_suggest_tags_python(): tags = suggest_tags("Write a python script to parse files") assert "python" in tags def test_suggest_tags_multiple(): tags = suggest_tags("A python script that uses docker and sql") assert "python" in tags assert "docker" in tags assert "sql" in tags def test_suggest_tags_no_match(): tags = suggest_tags("Write a poem about the ocean") assert tags == [] def test_suggest_tags_word_boundary_test(): # "test" should match as it is a whole word tags = suggest_tags("Write a test for the function") assert "testing" in tags def test_suggest_tags_word_boundary_no_false_positive(): # "testing" alone contains "test" as a boundary — \b matches here too # The task spec says "test" is in "testing" and \b does catch it correctly # This verifies that "pythonista" does NOT match "python" tags = suggest_tags("He is a pythonista who loves coding") assert "python" not in tags def test_suggest_tags_rest_maps_to_api(): tags = suggest_tags("Build a REST endpoint") assert "api" in tags def test_suggest_tags_shell_maps_to_bash(): tags = suggest_tags("Write a shell script") assert "bash" in tags def test_suggest_tags_deduplicated(): # "rest" -> api, "api" -> api: should appear only once tags = suggest_tags("Design a REST api endpoint") assert tags.count("api") == 1 def test_suggest_tags_case_insensitive(): tags = suggest_tags("Use PYTHON for this task") assert "python" in tags def test_suggest_tags_returns_sorted(): tags = suggest_tags("Use docker and bash and yaml") assert tags == sorted(tags)