Beispiel #1
0
def test_Choice():
    assert (Choice(Literal('a'),
                   Dot()) == Def(Op.CHC, ([Literal('a'), Dot()], )))
    assert Choice('foo', 'bar') == Choice(Literal('foo'), Literal('bar'))
    # simple optimizations
    assert Choice(Dot()) == Dot()
    assert Choice(Choice('a', 'b'), 'c') == Choice('a', 'b', 'c')
Beispiel #2
0
def test_Sequence():
    assert (Sequence(Literal('a'),
                     Dot()) == Def(Op.SEQ, ([Literal('a'), Dot()], )))
    assert Sequence('foo', 'bar') == Sequence(Literal('foo'), Literal('bar'))
    # simple optimizations
    assert Sequence(Dot()) == Dot()
    assert Sequence(Sequence('a', 'b'), 'c') == Sequence('a', 'b', 'c')
Beispiel #3
0
def test_Bind():
    assert Bind(Dot(), name='x') == Def(Op.BND, (Dot(), 'x'))
    assert Bind('foo', name='bar') == Bind(Literal('foo'), name='bar')
Beispiel #4
0
def test_Capture():
    assert Capture(Dot()) == Def(Op.CAP, (Dot(), ))
    assert Capture('foo') == Capture(Literal('foo'))
Beispiel #5
0
def test_Not():
    assert Not(Dot()) == Def(Op.NOT, (Dot(), ))
    assert Not('foo') == Not(Literal('foo'))
Beispiel #6
0
def test_And():
    assert And(Dot()) == Def(Op.AND, (Dot(), ))
    assert And('foo') == And(Literal('foo'))
Beispiel #7
0
def test_Nonterminal():
    assert Nonterminal('A') == Def(Op.SYM, ('A', ))
Beispiel #8
0
def test_Plus():
    assert Plus(Dot()) == Def(Op.PLS, (Dot(), ))
    assert Plus('foo') == Plus(Literal('foo'))
Beispiel #9
0
def test_Star():
    assert Star(Dot()) == Def(Op.STR, (Dot(), ))
    assert Star('foo') == Star(Literal('foo'))
Beispiel #10
0
def test_Optional():
    assert Optional(Dot()) == Def(Op.OPT, (Dot(), ))
    assert Optional('foo') == Optional(Literal('foo'))
Beispiel #11
0
def test_Regex():
    assert Regex('foo') == Def(Op.RGX, ('foo', 0))
    assert Regex('foo', flags=1) == Def(Op.RGX, ('foo', 1))
Beispiel #12
0
def test_Class():
    assert Class('foo') == Def(Op.CLS, ([('f', None), ('o', None),
                                         ('o', None)], False))
    assert Class('f') == Def(Op.CLS, ([('f', None)], False))
    assert Class('f', negate=True) == Def(Op.CLS, ([('f', None)], True))
Beispiel #13
0
def test_Literal():
    assert Literal('foo') == Def(Op.LIT, ('foo', ))
Beispiel #14
0
def test_Dot():
    assert Dot() == Def(Op.DOT, ())