Exemplo n.º 1
0
def test_dfa():
    for test_case in parser_test_cases:
        parser = RegexParser(dfa=True)
        dfa = parser.run(test_case[0])

        for success in test_case[1]:
            expect(dfa.match_string(success, True),
                   '"{}" should match "{}"'.format(success, test_case[0]))
        for failure in test_case[2]:
            expect(not dfa.match_string(failure, True),
                   '"{}" should not match "{}"'.format(failure, test_case[0]))
    assert_expectations()
Exemplo n.º 2
0
def test_empty_character_class():
    parser = RegexParser()
    with pytest.raises(ValueError):
        parser.run('[]')
Exemplo n.º 3
0
def test_dangling_question():
    parser = RegexParser()
    with pytest.raises(ValueError):
        parser.run('?')
Exemplo n.º 4
0
def test_dangling_star():
    parser = RegexParser()
    with pytest.raises(ValueError):
        parser.run('*')
Exemplo n.º 5
0
def test_dangling_plus():
    parser = RegexParser()
    with pytest.raises(ValueError):
        parser.run('+')
Exemplo n.º 6
0
def test_nfa_intersection_with_dot_no_accepting_state():
    nfa_1 = RegexParser().run('a.c')
    nfa_2 = RegexParser().run('abd')
    intersection_nfa = nfa_1.intersection(nfa_2)
    assert not intersection_nfa.has_accepting_states()