Пример #1
0
def test_parse_partial():
    node = Node("$", "123")
    given = [node, node]
    with pytest.raises(ValueError):
        parse(term("$"), given)
Пример #2
0
import pytest
from katana.utils import Node, Pair, prepare
from katana.term import term, null


K = term('k')
N = Node('k', 'data')
B = Node('b', 'data')


def test_null():
    given = prepare([N])
    after = given
    assert null(given) == after


def test_term():
    given = prepare([N])
    after = Pair([N], [])
    assert K(given) == after


def test_term_multiple():
    given = prepare([N,B])
    after = Pair([N], [B])
    assert K(given) == after


def test_term_no_match():
    given = prepare([B])
    with pytest.raises(ValueError):
Пример #3
0
def test_parse():
    node = Node("$", "123")
    given = [node]
    after = [node]
    assert parse(term("$"), given) == after
Пример #4
0
import pytest
from pyrsistent import v
from katana.utils import Node, Pair, prepare
from katana.compound import sequence, group, repeat, option, maybe
from katana.term import term


Ta, Tb, Tc = [term(k) for k in 'abc']
Na, Nb, Nc = [Node(k, 'data') for k in 'abc']


def test_sequence():
    s = sequence(Ta, Tb)

    given = prepare([Na, Nb])
    after = Pair([Na, Nb], [])
    assert s(given) == after


def test_group():
    g = group(Ta)
    given = prepare([Na])
    after = Pair([Node(g, [Na])], [])
    assert g(given) == after


def test_group_with_prefix():
    g = group(Ta)
    given = Pair(v(Nb), v(Na))
    after = Pair([Nb, Node(g, [Na])], [])
    assert g(given) == after