Ejemplo n.º 1
0
    def test_parenthized_alternative_repeated_alternative_tokens_case(self):
        rulename = 'rulename'
        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')
        final_edge = Edge('', FINAL_STATE)
        state = State('abc', final_edge, 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, final_edge])
        state3_2 = State('ghi_2', [edge2_2, edge3_2, final_edge])
        start_state = State(START_STATE, [edge, edge2, edge3])
        final_state = State(FINAL_STATE)

        states = [
            start_state, state, state2, state3, state2_2, state3_2, final_state
        ]
        expected = StateMachine(rulename, states)
        actual = choices_parser.parse_elements(rulename, elements)

        assert_state_machines_equal(actual, expected)
Ejemplo n.º 2
0
    def test_trivial_case(self):
        rulename = 'rulename'
        elements = 'abc'
        edge = Edge('abc', 'abc')
        final_edge = Edge('', FINAL_STATE)
        state = State('abc', final_edge, is_automata=True)
        start_state = State(START_STATE, edge)
        final_state = State(FINAL_STATE)

        states = [start_state, state, final_state]
        expected = StateMachine(rulename, states)
        actual = choices_parser.parse_elements(rulename, elements)

        assert_state_machines_equal(actual, expected)
Ejemplo n.º 3
0
    def test_identical_parenthetized_token_case(self):
        rulename = 'rulename'
        elements = 'abc (abc)'
        edge = Edge('abc', 'abc')
        edge2 = Edge('abc', 'abc_#2')
        final_edge = Edge('', FINAL_STATE)
        state = State('abc', edge2, is_automata=True)
        state2 = State('abc_#2', final_edge, is_automata=True)
        start_state = State(START_STATE, edge)
        final_state = State(FINAL_STATE)

        states = [start_state, state, state2, final_state]
        expected = StateMachine(rulename, states)
        actual = choices_parser.parse_elements(rulename, elements)

        assert_state_machines_equal(actual, expected)
Ejemplo n.º 4
0
    def test_two_alternative_tokens_case(self):
        rulename = 'rulename'
        elements = 'abc / "def"'
        edge = Edge('abc', 'abc')
        edge2 = Edge('def', 'def')
        final_edge = Edge('', FINAL_STATE)
        state = State('abc', final_edge, is_automata=True)
        state2 = State('def', final_edge)
        start_state = State(START_STATE, [edge, edge2])
        final_state = State(FINAL_STATE)

        states = [start_state, state, state2, final_state]
        expected = StateMachine(rulename, states)
        actual = choices_parser.parse_elements(rulename, elements)

        assert_state_machines_equal(actual, expected)
Ejemplo n.º 5
0
    def test_N_repeated_token_case(self):
        rulename = 'rulename'
        elements = 'abc 2"def"'
        edge = Edge('abc', 'abc')
        edge2 = Edge('def', 'def')
        edge2_2 = Edge('def', 'def_2')
        final_edge = Edge('', FINAL_STATE)
        state = State('abc', edge2, is_automata=True)
        state2 = State('def', edge2_2)
        state2_2 = State('def_2', final_edge)
        start_state = State(START_STATE, edge)
        final_state = State(FINAL_STATE)

        states = [start_state, state, state2, state2_2, final_state]
        expected = StateMachine(rulename, states)
        actual = choices_parser.parse_elements(rulename, elements)

        assert_state_machines_equal(actual, expected)
Ejemplo n.º 6
0
    def test_starting_parenthized_tokens_case(self):
        rulename = 'rulename'
        elements = '(abc "def") "ghi"'
        edge = Edge('abc', 'abc')
        edge2 = Edge('def', 'def')
        edge3 = Edge('ghi', 'ghi')
        final_edge = Edge('', FINAL_STATE)
        state = State('abc', edge2, is_automata=True)
        state2 = State('def', edge3)
        state3 = State('ghi', final_edge)
        start_state = State(START_STATE, edge)
        final_state = State(FINAL_STATE)

        states = [start_state, state, state2, state3, final_state]
        expected = StateMachine(rulename, states)
        actual = choices_parser.parse_elements(rulename, elements)

        assert_state_machines_equal(actual, expected)