Beispiel #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()
Beispiel #2
0
def test_empty_character_class():
    parser = RegexParser()
    with pytest.raises(ValueError):
        parser.run('[]')
Beispiel #3
0
def test_dangling_question():
    parser = RegexParser()
    with pytest.raises(ValueError):
        parser.run('?')
Beispiel #4
0
def test_dangling_star():
    parser = RegexParser()
    with pytest.raises(ValueError):
        parser.run('*')
Beispiel #5
0
def test_dangling_plus():
    parser = RegexParser()
    with pytest.raises(ValueError):
        parser.run('+')
Beispiel #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()