"""Tests for the loop naming convention (engine/naming.py)."""
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

from engine import naming as N


def test_suggest_basic_shape():
    assert N.suggest_name(0, "synth") == "00_synth"
    assert N.suggest_name(3, "bass", character="dark") == "03_bass_dark"
    assert N.suggest_name(12, "keys", section="chorus") == "12_keys_chorus"
    assert N.suggest_name(1, "vocals", section="drop", character="wail") == "01_vocals_drop_wail"


def test_suggest_slugs_and_pads():
    assert N.suggest_name(5, "Brass Lead!") == "05_brasslead"   # slugged, 2-digit
    assert N.suggest_name(7, "KEYS") == "07_keys"


def test_suggest_dedupes_against_taken():
    taken = {"02_synth"}
    assert N.suggest_name(2, "synth", taken=taken) == "02_synth_1"
    assert N.suggest_name(2, "synth", taken={"02_synth", "02_synth_1"}) == "02_synth_2"


def test_stem_of_maps_character_to_stem():
    assert N.stem_of("voice") == "vocals"
    assert N.stem_of("piano") == "other"
    assert N.stem_of("808") == "bass"
    assert N.stem_of("break") == "drums"
    assert N.stem_of("wat") == "other"          # unknown → other


def test_lint_flags_drift():
    assert N.lint("03_keys_brass2") == []
    assert "no NN_ index prefix" in N.lint("crime_synth")
    assert "contains spaces" in N.lint("00 synth loop")
    assert "not lowercase" in N.lint("00_Synth")


def test_lint_ignores_wav_suffix():
    assert N.lint("00_synth.wav") == []
