def test_one_or_more_children_deriv(): schema = After( Choice( EMPTY, OneOrMore( Element( Name({'ns': ''}, 'bar'), EMPTY))), EMPTY) doc = ('x', ElementNode(QName('', 'bar'), tuple(), ())) deriv = strip_children_deriv(schema, doc) assert str(children_deriv(schema, doc)) == str(deriv) x = child_deriv(schema, 'x') y = child_deriv(x, doc[1]) assert str(strip_children_deriv(schema, doc)) == str(y) deriv = text_deriv(schema, 'x') assert str(child_deriv(schema, 'x')) == str(deriv) p1 = Choice( EMPTY, OneOrMore( Element( Name({'ns': ''}, 'bar'), EMPTY))) p2 = EMPTY deriv = after(text_deriv(p1, 'x'), p2) assert str(text_deriv(schema, 'x')) == str(deriv) p11 = EMPTY p12 = OneOrMore( Element( Name({'ns': ''}, 'bar'), EMPTY)) deriv = choice(text_deriv(p11, 'x'), text_deriv(p12, 'x')) assert str(text_deriv(p1, 'x')) == str(deriv) assert str(text_deriv(p11, 'x')) == str(NotAllowed()) p121 = Element( Name({'ns': ''}, 'bar'), EMPTY) deriv = group(text_deriv(p121, 'x'), choice(OneOrMore(p121), EMPTY)) assert str(text_deriv(p12, 'x')) == str(deriv) assert str(text_deriv(p121, 'x')) == str(NotAllowed())
def test_one_or_more_multiple(): schema = Element( Name({'ns': ''}, 'foo'), OneOrMore( Element( Name({'ns': ''}, 'bar'), EMPTY))) doc = ElementNode( QName('', 'foo'), (), ( ElementNode(QName('', 'bar'), (), ()), ElementNode(QName('', 'bar'), (), ()), ElementNode(QName('', 'bar'), (), ()))) qn = QName('', 'foo') d1 = start_tag_open_deriv(schema, qn) m1 = After( OneOrMore( Element( Name({'ns': ''}, 'bar'), EMPTY)), EMPTY) assert str(d1) == str(m1) atts = () d2 = atts_deriv(d1, atts) m2 = m1 assert str(d2) == str(m2) d3 = start_tag_close_deriv(d2) m21 = OneOrMore( Element( Name({'ns': ''}, 'bar'), EMPTY)) m211 = Element( Name({'ns': ''}, 'bar'), EMPTY) m22 = EMPTY m3_1 = after(start_tag_close_deriv(m21), m22) assert str(m3_1) == str(d3) m3_2 = after(start_tag_close_deriv(m21), EMPTY) assert str(m3_2) == str(d3) m3_3 = after(one_or_more(start_tag_close_deriv(m211)), EMPTY) assert str(m3_3) == str(d3) m3_4 = after(one_or_more(m211), EMPTY) m3_4 = After(OneOrMore(m211), EMPTY) m3_4 = After( OneOrMore( Element( Name({'ns': ''}, 'bar'), EMPTY)), EMPTY) assert str(d3) == str(m3_4) children = ( ElementNode(QName('', 'bar'), (), ()), ElementNode(QName('', 'bar'), (), ()), ElementNode(QName('', 'bar'), (), ())) d4 = children_deriv(d3, children) m4_1 = children_deriv(m3_4, children) assert str(d4) == str(m4_1) m4_2 = strip_children_deriv(m3_4, children) assert str(d4) == str(m4_2) child_0 = ElementNode(QName('', 'bar'), (), ()) m4_3 = child_deriv(m3_4, child_0) child_0_qn = QName('', 'bar') m41_1 = start_tag_open_deriv(m3_4, child_0_qn) m31 = OneOrMore( Element( Name({'ns': ''}, 'bar'), EMPTY)) m32 = EMPTY m41_2 = apply_after( partial(flip(after), m32), start_tag_open_deriv(m31, child_0_qn)) assert str(m41_1) == str(m41_2) m5_1 = start_tag_open_deriv(m31, child_0_qn) m311 = Element( Name({'ns': ''}, 'bar'), EMPTY) m5_2 = apply_after( partial(flip(group), choice(OneOrMore(m311), EMPTY)), start_tag_open_deriv(m311, child_0_qn)) assert str(m5_1) == str(m5_2) assert str(d4) == str(m4_3) assert str(child_deriv(schema, doc)) == str(end_tag_deriv(d4)) assert nullable(child_deriv(schema, doc)) is True