from __future__ import unicode_literals
import pytest
import os
import re
from parglare import get_collector, Parser, Grammar, GrammarError

THIS_FOLDER = os.path.abspath(os.path.dirname(__file__))


def test_action_explicit_get_collector():
    """
    Test the basic usage of `get_collector` API where we don't provide
    actions in a separate python module.
    """

    action = get_collector()

    @action
    def INT(context, value):
        return int(value)

    @action
    def STRING(context, value):
        return "#{}#".format(value)

    grammar = Grammar.from_file(os.path.join(THIS_FOLDER, 'grammar.pg'))
    Parser(grammar, actions=action.all)


def test_action_explicit_get_collector_missing_action():
    """
    Test when `get_collector` has a terminal without defined action nothing
    happens as the default implicit action will be used.
    """

    action = get_collector()

    @action
    def INT(context, value):
        return int(value)

    grammar = Grammar.from_file(os.path.join(THIS_FOLDER, 'grammar.pg'))
    Parser(grammar, actions=action.all)


def test_actions_explicit_get_collector_action_for_unexisting_terminal():
    """
    Test for situation when `get_collector` has an action for un-existing
    terminal.
    """

    action = get_collector()

    @action
    def INT(context, value):
        return int(value)

    @action
    def STRING(context, value):
        return "#{}#".format(value)

    @action
    def STRING2(context, value):
        return "#{}#".format(value)

    grammar = Grammar.from_file(os.path.join(THIS_FOLDER, 'grammar.pg'))
    Parser(grammar, actions=action.all)

@@ -44,34 +44,10 @@
 ort 
-pytest%0Aimport os%0Aimport re
+os
 %0Afro
@@ -98,22 +98,8 @@
 mmar
-, GrammarError
 %0A%0ATH

Fix PEP-8 issues in tests