def test_given_cycle_then_first_cycle_breaking_terminals(self) -> None: grammar = Grammar(Rule('A', ['B']), Rule('A', ['a']), Rule('B', ['A']), Rule('B', ['b'])) first_set = grammar.first(['A']) self.assertEqual({'a', 'b'}, first_set)
def test_given_reference_with_recursion_then_non_recursive_terminals(self) -> None: grammar = Grammar(Rule('X', ['X', 'x']), Rule('X', ['A', 'x']), Rule('A', ['a', 'x'])) first_set = grammar.first(['X']) self.assertEqual({'a'}, first_set)
def test_given_reference_then_first_terminals_of_references(self) -> None: grammar = Grammar(Rule('X', ['A']), Rule('A', ['a']), Rule('A', ['B']), Rule('B', ['b'])) first_set = grammar.first(['X', 'x']) self.assertEqual({'a', 'b'}, first_set)
def test_given_many_terminals_then_first_terminal(self) -> None: grammar = Grammar(Rule('X', ['a']), Rule('X', ['b'])) first_set = grammar.first(['x', 'a', 'b']) self.assertEqual({'x'}, first_set)
def test_given_terminal_then_terminal(self) -> None: grammar = Grammar() first_set = grammar.first(['terminal']) self.assertEqual({'terminal'}, first_set)
def test_given_empty_list_then_empty(self) -> None: grammar = Grammar() first_set = grammar.first([]) self.assertEqual(set(), first_set)