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)
- 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)
