def test_parenthized_alternative_repeated_alternative_tokens_case(self): elements = ['abc', '/', ['2*', ['"def"', '/', '"ghi"']]] edge = Edge('abc', 'abc') edge2 = Edge('def', 'def') edge3 = Edge('ghi', 'ghi') edge2_2 = Edge('def', 'def_2') edge3_2 = Edge('ghi', 'ghi_2') edge2_2 = Edge('def', 'def_2') edge2_e = Edge('def', 'def_2') edge3_2 = Edge('ghi', 'ghi_2') state = State('abc', is_automata=True) state2 = State('def', [edge2_2, edge3_2]) state3 = State('ghi', [edge2_2, edge3_2]) state2_2 = State('def_2', [edge2_2, edge3_2]) state3_2 = State('ghi_2', [edge2_2, edge3_2]) start_edges = [edge, edge2, edge3] end_states = [state, state2_2, state3_2] states = [state, state2, state3, state2_2, state3_2] expected = (start_edges, end_states, states) actual = choices_parser.recursive_parse_elements(elements) logger.debug( f'Actual result:\nin_edges: {actual[0]}\nnew_end_states: {actual[1]}\nnew_states: {actual[2]}' ) logger.debug(f'start_edges') self.assertTrue(edges_equal(actual[0], expected[0])) logger.debug(f'end_states') assert_states_equal(actual[1], expected[1]) logger.debug(f'states') assert_states_equal(actual[2], expected[2])
def test_trivial_case(self): elements = ['abc'] edge = Edge('abc', 'abc') state = State('abc', is_automata=True) start_edges = [edge] end_states = [state] states = [state] expected = (start_edges, end_states, states) actual = choices_parser.recursive_parse_elements(elements) self.assertTrue(edges_equal(actual[0], expected[0])) assert_states_equal(actual[1], expected[1]) assert_states_equal(actual[2], expected[2])
def test_identical_parenthetized_token_case(self): elements = ['abc', ['abc']] edge = Edge('abc', 'abc') edge2 = Edge('abc', 'abc_#2') state = State('abc', edge2, is_automata=True) state2 = State('abc_#2', is_automata=True) start_edges = [edge] end_states = [state2] states = [state, state2] expected = (start_edges, end_states, states) actual = choices_parser.recursive_parse_elements(elements) logger.debug( f'Actual result:\nin_edges: {actual[0]}\nnew_end_states: {actual[1]}\nnew_states: {actual[2]}' ) logger.debug(f'start_edges') self.assertTrue(edges_equal(actual[0], expected[0])) logger.debug(f'end_states') assert_states_equal(actual[1], expected[1]) logger.debug(f'states') assert_states_equal(actual[2], expected[2])
def test_two_alternative_tokens_case(self): elements = ['abc', '/', '"def"'] edge = Edge('abc', 'abc') edge2 = Edge('def', 'def') state = State('abc', is_automata=True) state2 = State('def') start_edges = [edge, edge2] end_states = [state, state2] states = [state, state2] expected = (start_edges, end_states, states) actual = choices_parser.recursive_parse_elements(elements) logger.debug( f'Actual result:\nin_edges: {actual[0]}\nnew_end_states: {actual[1]}\nnew_states: {actual[2]}' ) logger.debug(f'start_edges') self.assertTrue(edges_equal(actual[0], expected[0])) logger.debug(f'end_states') assert_states_equal(actual[1], expected[1]) logger.debug(f'states') assert_states_equal(actual[2], expected[2])
def test_starting_parenthized_tokens_case(self): elements = [['abc', '"def"'], '"ghi"'] edge = Edge('abc', 'abc') edge2 = Edge('def', 'def') edge3 = Edge('ghi', 'ghi') state = State('abc', edge2, is_automata=True) state2 = State('def', edge3) state3 = State('ghi') start_edges = [edge] end_states = [state3] states = [state, state2, state3] expected = (start_edges, end_states, states) actual = choices_parser.recursive_parse_elements(elements) logger.debug( f'Actual result:\nin_edges: {actual[0]}\nnew_end_states: {actual[1]}\nnew_states: {actual[2]}' ) logger.debug(f'start_edges') self.assertTrue(edges_equal(actual[0], expected[0])) logger.debug(f'end_states') assert_states_equal(actual[1], expected[1]) logger.debug(f'states') assert_states_equal(actual[2], expected[2])