File size: 1,837 Bytes
77c25ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""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)