"""Tests for the input parser."""

from tests.conftest import send


def test_direction_shortcut_n(game):
    state, parser, _ = game
    result = parser.parse("n", state)
    assert result is not None
    assert result.verb == "walk"
    assert result.direction == "NORTH"


def test_direction_shortcut_s(game):
    state, parser, _ = game
    result = parser.parse("s", state)
    assert result is not None
    assert result.verb == "walk"
    assert result.direction == "SOUTH"


def test_direction_shortcut_e(game):
    state, parser, _ = game
    result = parser.parse("e", state)
    assert result is not None
    assert result.verb == "walk"
    assert result.direction == "EAST"


def test_direction_go_north(game):
    state, parser, _ = game
    result = parser.parse("go north", state)
    assert result is not None
    assert result.verb == "walk"
    assert result.direction == "NORTH"


def test_compound_verb_get_out(game):
    state, parser, _ = game
    result = parser.parse("get out of bed", state)
    assert result is not None
    assert result.verb == "get out"


def test_compound_verb_turn_on(game):
    state, parser, _ = game
    result = parser.parse("turn on light", state)
    assert result is not None
    assert result.verb == "turn on"


def test_compound_verb_turn_off(game):
    state, parser, _ = game
    result = parser.parse("turn off light", state)
    assert result is not None
    assert result.verb == "turn off"


def test_compound_verb_look_in(game):
    state, parser, _ = game
    result = parser.parse("look in pocket", state)
    assert result is not None
    assert result.verb == "look in"


def test_compound_verb_look_at(game):
    state, parser, _ = game
    result = parser.parse("look at bed", state)
    assert result is not None
    assert result.verb == "examine"


def test_compound_verb_pick_up(game):
    state, parser, _ = game
    result = parser.parse("pick up gown", state)
    assert result is not None
    assert result.verb == "take"


def test_compound_verb_stand_up(game):
    state, parser, _ = game
    result = parser.parse("stand up", state)
    assert result is not None
    assert result.verb == "stand up"


def test_compound_verb_lie_down(game):
    state, parser, _ = game
    result = parser.parse("lie down", state)
    assert result is not None
    assert result.verb == "lie down"


def test_compound_verb_put_on(game):
    state, parser, _ = game
    result = parser.parse("put on gown", state)
    assert result is not None
    assert result.verb == "put on"


def test_compound_verb_take_off(game):
    state, parser, _ = game
    result = parser.parse("take off gown", state)
    assert result is not None
    assert result.verb == "take off"


def test_preposition_splitting(game):
    state, parser, _ = game
    # Need objects in scope for "put X in Y" — use gown (in bedroom) and bed
    result = parser.parse("put gown in bed", state)
    assert result is not None
    assert result.prep == "in"


def test_again_command(game):
    state, parser, _ = game
    # First command
    result1 = parser.parse("look", state)
    assert result1 is not None
    # Again via "g"
    result2 = parser.parse("g", state)
    assert result2 is result1
    # Again via "again"
    result3 = parser.parse("again", state)
    assert result3 is result1


def test_buzz_word_stripping(game):
    state, parser, _ = game
    result = parser.parse("take the gown", state)
    assert result is not None
    assert result.verb == "take"
    # "the" should be stripped, object should resolve to GOWN
    assert result.direct_obj is not None
    assert result.direct_obj.id == "GOWN"


def test_verb_synonym_grab(game):
    state, parser, _ = game
    result = parser.parse("grab gown", state)
    assert result is not None
    assert result.verb == "take"


def test_verb_synonym_x(game):
    state, parser, _ = game
    result = parser.parse("x bed", state)
    assert result is not None
    assert result.verb == "examine"


def test_verb_synonym_i(game):
    state, parser, _ = game
    result = parser.parse("i", state)
    assert result is not None
    assert result.verb == "inventory"


def test_negation(game):
    state, parser, _ = game
    result = parser.parse("don't panic", state)
    assert result is not None
    assert result.is_negated is True
    assert result.verb == "panic"


def test_empty_input_returns_none(game):
    state, parser, _ = game
    result = parser.parse("", state)
    assert result is None


def test_only_buzz_words_returns_none(game):
    state, parser, _ = game
    result = parser.parse("the a an", state)
    assert result is None
