feat(tag-prefix): parse_kind_prefix util — IR-style \kind:name\ parser at the input boundary; KNOWN_KINDS = artist/character/fandom/series/meta/rating (excludes default \general\ and system-managed archive/post)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"""parse_kind_prefix — IR-style `kind:name` shortcut at the input boundary."""
|
||||
|
||||
from backend.app.utils.tag_prefix import KNOWN_KINDS, parse_kind_prefix
|
||||
|
||||
|
||||
def test_recognized_kinds_match_user_input_set():
|
||||
# System-managed kinds (archive, post) and the default (general)
|
||||
# are intentionally excluded — the user can't type those at the
|
||||
# input boundary.
|
||||
assert KNOWN_KINDS == frozenset({
|
||||
"artist", "character", "fandom", "series", "meta", "rating",
|
||||
})
|
||||
|
||||
|
||||
def test_character_prefix_parsed():
|
||||
assert parse_kind_prefix("character:Saber") == ("character", "Saber")
|
||||
|
||||
|
||||
def test_case_insensitive_prefix():
|
||||
assert parse_kind_prefix("Character:Saber") == ("character", "Saber")
|
||||
assert parse_kind_prefix("CHARACTER:Saber") == ("character", "Saber")
|
||||
|
||||
|
||||
def test_no_prefix_returns_none_kind():
|
||||
assert parse_kind_prefix("sunset") == (None, "sunset")
|
||||
|
||||
|
||||
def test_unknown_prefix_kept_as_literal():
|
||||
# 'http' is not a known kind — preserve the literal text.
|
||||
assert parse_kind_prefix("http://example.com") == (None, "http://example.com")
|
||||
|
||||
|
||||
def test_whitespace_stripped():
|
||||
assert parse_kind_prefix("artist: Eric ") == ("artist", "Eric")
|
||||
assert parse_kind_prefix(" sunset ") == (None, "sunset")
|
||||
|
||||
|
||||
def test_empty_string():
|
||||
assert parse_kind_prefix("") == (None, "")
|
||||
|
||||
|
||||
def test_just_colon():
|
||||
# Empty prefix → "" not in KNOWN_KINDS → falls through to (None, "...")
|
||||
assert parse_kind_prefix(":foo") == (None, ":foo")
|
||||
Reference in New Issue
Block a user