"""Corner A — the .tidal score parser. Regression-guards the idiom-blindness
bugs that manufactured false A↔C conflicts."""
import tidal_score as ts


def test_indented_doblock_parses(fixtures):
    """do-block / indented dN must NOT parse to an empty score."""
    m = ts.orbit_sounds(fixtures / "doblock.tidal")
    assert m, "indented do-block parsed to empty — the burn_this_book bug"
    sounds = {d["sound"] for d in m.values()}
    assert "drums_nes" in sounds
    assert "cpluck" in sounds


def test_orbit_override_maps_to_dn_plus_1(fixtures):
    """`# orbit 7` ⇒ d8 (SuperDirt 0-indexed); d5 header must not survive."""
    m = ts.orbit_sounds(fixtures / "doblock.tidal")
    assert 8 in m and m[8]["sound"] == "meth_bass"
    assert 5 not in m
    assert m[8]["orbit_override"] is True


def test_commented_block_ignored(fixtures):
    m = ts.orbit_sounds(fixtures / "doblock.tidal")
    assert 9 not in m, "a -- commented dN block must not parse"


def test_dn_header_rejects_identifiers():
    """`\\b` after the digits keeps degradeBy / d4bass from matching as headers."""
    assert ts.DN_HEADER.match('degradeBy 0.5 $ s "x"') is None
    assert ts.DN_HEADER.match('  d4bass = s "x"') is None
    assert ts.DN_HEADER.match('  d4 $ s "x"') is not None      # indentation OK
    assert ts.DN_HEADER.match('d1 $ s "x"') is not None


def test_real_burn_this_book_regression(repo):
    """The exact file that exposed the col-0-only bug: drums_nes + cpluck ARE
    in the score (metadata was right all along)."""
    m = ts.orbit_sounds(repo / "live/techno/noir/burn_this_book.tidal")
    sounds = {d["sound"] for d in m.values()}
    assert {"drums_nes", "cpluck"} <= sounds
