import pytest
from parglare import Grammar
from parglare.exceptions import GrammarError


def test_terminal_nonterminal_conflict():

    # Production A is a terminal ("a") and non-terminal at the same time.
    g = """
    A = "a" | B;
    B = "b";
    """
    try:
        Grammar.from_string(g)
        assert False
    except GrammarError as e:
        assert 'Multiple definition' in str(e)


def test_multiple_terminal_definition():

    g = """
    S = A A;
    A = "a";
    A = "b";
    """
    try:
        Grammar.from_string(g)
        assert False
    except GrammarError as e:
        assert 'Multiple definition' in str(e)

import pytest
from parglare import Grammar


def test_terminal_nonterminal():

    # Production A is a terminal ("a") and non-terminal at the same time.
    # Thus, it must be recognized as non-terminal.
    g = """
    S = A B;
    A = "a" | B;
    B = "b";
    """
    Grammar.from_string(g)

    # Here A shoud be non-terminal while B will be terminal.
    g = """
    S = A B;
    A = B;
    B = "b";
    """

    Grammar.from_string(g)


def test_multiple_terminal_definition():

    # A is defined multiple times as terminal thus it must be recognized
    # as non-terminal with alternative expansions.
    g = """
    S = A A;
    A = "a";
    A = "b";
    """

    Grammar.from_string(g)

Fix in tests for terminal definitions.
Fix in tests for terminal definitions.

  import pytest
  from parglare import Grammar
- from parglare.exceptions import GrammarError
  
  
- def test_terminal_nonterminal_conflict():
+ def test_terminal_nonterminal():
  
      # Production A is a terminal ("a") and non-terminal at the same time.
+     # Thus, it must be recognized as non-terminal.
      g = """
+     S = A B;
      A = "a" | B;
      B = "b";
      """
-     try:
-         Grammar.from_string(g)
+     Grammar.from_string(g)
-         assert False
-     except GrammarError as e:
-         assert 'Multiple definition' in str(e)
+ 
+     # Here A shoud be non-terminal while B will be terminal.
+     g = """
+     S = A B;
+     A = B;
+     B = "b";
+     """
+ 
+     Grammar.from_string(g)
  
  
  def test_multiple_terminal_definition():
  
+     # A is defined multiple times as terminal thus it must be recognized
+     # as non-terminal with alternative expansions.
      g = """
      S = A A;
      A = "a";
      A = "b";
      """
-     try:
-         Grammar.from_string(g)
-         assert False
-     except GrammarError as e:
-         assert 'Multiple definition' in str(e)
  
+     Grammar.from_string(g)
+ 
Fix in tests for terminal definitions.
## Code Before:
import pytest
from parglare import Grammar
from parglare.exceptions import GrammarError


def test_terminal_nonterminal_conflict():

    # Production A is a terminal ("a") and non-terminal at the same time.
    g = """
    A = "a" | B;
    B = "b";
    """
    try:
        Grammar.from_string(g)
        assert False
    except GrammarError as e:
        assert 'Multiple definition' in str(e)


def test_multiple_terminal_definition():

    g = """
    S = A A;
    A = "a";
    A = "b";
    """
    try:
        Grammar.from_string(g)
        assert False
    except GrammarError as e:
        assert 'Multiple definition' in str(e)

## Instruction:
Fix in tests for terminal definitions.
## Code After:
import pytest
from parglare import Grammar


def test_terminal_nonterminal():

    # Production A is a terminal ("a") and non-terminal at the same time.
    # Thus, it must be recognized as non-terminal.
    g = """
    S = A B;
    A = "a" | B;
    B = "b";
    """
    Grammar.from_string(g)

    # Here A shoud be non-terminal while B will be terminal.
    g = """
    S = A B;
    A = B;
    B = "b";
    """

    Grammar.from_string(g)


def test_multiple_terminal_definition():

    # A is defined multiple times as terminal thus it must be recognized
    # as non-terminal with alternative expansions.
    g = """
    S = A A;
    A = "a";
    A = "b";
    """

    Grammar.from_string(g)
