Changeset 2820:162fcc3925fd in livinglogic.python.xist

Show
Ignore:
Timestamp:
07/30/07 16:37:35 (12 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Fix xfind.CSSNthOfTypeSelector and xfind.CSSNthLastOfTypeSelector. Add tests.

xfind._is_nth_node() and xfind._is_nth_last_node need an indexable iterator.
Add tests for the following CSS selectors: nth-child(), nth-last-child(),
nth-of-type(), nth-last-of-type().

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/ll/xist/xfind.py

    r2818 r2820  
    14461446            node = path[-1] 
    14471447            if isinstance(node, xsc.Element): 
    1448                 return _is_nth_node(self._children_of_type(path[-2], node.xmlname), node, self.value) 
     1448                return _is_nth_node(misc.Iterator(_children_of_type(path[-2], node.xmlname)), node, self.value) 
    14491449        return False 
    14501450 
     
    14551455            node = path[-1] 
    14561456            if isinstance(node, xsc.Element): 
    1457                 return _is_nth_last_node(self._children_of_type(path[-2], node.xmlname), node, self.value) 
     1457                return _is_nth_last_node(misc.Iterator(_children_of_type(path[-2], node.xmlname)), node, self.value) 
    14581458        return False 
    14591459 
  • test/test_xfind.py

    r2819 r2820  
    365365    e = xsc.Frag(html.span(html.b("hurz"), "gurk", html.em("hinz"), html.em("kunz")), html.em("hurz"), html.em("hinz"), "nix", html.i("kunz")) 
    366366    assert list(e.walknode(xfind.css("*:only-of-type"))) == [e[0], e[0][0], e[4]] 
     367    assert list(e.walknode(xfind.css("*:nth-child(1)"))) == [e[0], e[0][0]] 
     368    assert list(e.walknode(xfind.css("*:nth-child(2)"))) == [e[0][2], e[1]] 
     369    assert list(e.walknode(xfind.css("*:nth-last-child(1)"))) == [e[0][3], e[4]] 
     370    assert list(e.walknode(xfind.css("*:nth-last-child(2)"))) == [e[0][2], e[2]] 
     371    assert list(e.walknode(xfind.css("*:nth-of-type(1)"))) == [e[0], e[0][0], e[0][2], e[1], e[4]] 
     372    assert list(e.walknode(xfind.css("*:nth-of-type(2)"))) == [e[0][3], e[2]] 
     373    assert list(e.walknode(xfind.css("*:nth-last-of-type(1)"))) == [e[0], e[0][0], e[0][3], e[2], e[4]] 
     374    assert list(e.walknode(xfind.css("*:nth-last-of-type(2)"))) == [e[0][2], e[1]] 
    367375 
    368376    e = xsc.Frag(html.span(html.b("hurz"), "gurk"))