"""Tests for voice command parser (Issue #409)."""

from saltybot_voice_command.voice_command_parser import parse


def test_follow_me():
    """Test 'follow me' command."""
    r = parse("follow me")
    assert r.intent == "nav.follow_me"
    assert r.confidence == 1.0

    r = parse("come with me")
    assert r.intent == "nav.follow_me"
    assert r.confidence == 1.0


def test_stop():
    """Test 'stop' command."""
    r = parse("stop")
    assert r.intent == "nav.stop"
    assert r.confidence == 1.0

    r = parse("halt")
    assert r.intent == "nav.stop"
    assert r.confidence == 1.0


def test_come_here():
    """Test 'come here' command."""
    r = parse("come here")
    assert r.intent == "nav.come_here"
    assert r.confidence == 1.0

    r = parse("approach me")
    assert r.intent == "nav.come_here"
    assert r.confidence == 1.0


def test_go_home():
    """Test 'go home' command."""
    r = parse("go home")
    assert r.intent == "nav.go_home"
    assert r.confidence == 1.0

    r = parse("return home")
    assert r.intent == "nav.go_home"
    assert r.confidence == 1.0


def test_battery():
    """Test 'battery' command."""
    r = parse("battery")
    assert r.intent == "system.battery"
    assert r.confidence == 1.0

    r = parse("battery status")
    assert r.intent == "system.battery"
    assert r.confidence == 1.0


def test_spin():
    """Test 'spin' command."""
    r = parse("spin")
    assert r.intent == "nav.spin"
    assert r.confidence == 1.0

    r = parse("turn around")
    assert r.intent == "nav.spin"
    assert r.confidence == 1.0


def test_quiet_mode():
    """Test 'quiet mode' command."""
    r = parse("quiet mode")
    assert r.intent == "system.quiet_mode"
    assert r.confidence == 1.0

    r = parse("be quiet")
    assert r.intent == "system.quiet_mode"
    assert r.confidence == 1.0


def test_fallback():
    """Test unrecognized commands."""
    r = parse("xyzabc")
    assert r.intent == "fallback"
    assert r.confidence == 0.0

    r = parse("")
    assert r.intent == "fallback"
    assert r.confidence == 0.0


def test_fuzzy_matching():
    """Test fuzzy matching for similar commands."""
    # Similar but not exact
    r = parse("stap")  # Typo for "stop"
    assert r.intent == "nav.stop"
    assert r.confidence > 0.7

    r = parse("comhere")  # Slurred version
    assert r.intent in ("nav.come_here", "fallback")


def test_normalization():
    """Test text normalization."""
    r = parse("FOLLOW ME!")
    assert r.intent == "nav.follow_me"
    assert r.confidence == 1.0

    r = parse("  go   home  ")
    assert r.intent == "nav.go_home"
    assert r.confidence == 1.0


if __name__ == "__main__":
    test_follow_me()
    test_stop()
    test_come_here()
    test_go_home()
    test_battery()
    test_spin()
    test_quiet_mode()
    test_fallback()
    test_fuzzy_matching()
    test_normalization()
    print("All tests passed!")
