2 Script: Selectors.Children.js
3 Specification Examples of Pseudo Selector :children.
9 var Container, Children = [];
11 describe('PSeudo Selector :children', {
13 'before all': function(){
14 Container = new Element('div', {styles: {position: 'absolute', top: 0, left: 0, visibility: 'hidden'}});
15 (10).times(function(i){
16 Children.push(new Element('span', {id: 'child-' + i}).set('html', i));
18 Container.adopt(Children).inject(document.body);
21 'after all': function(){
25 'should use zero-based indexing': function(){
26 value_of(Container.getElement(':children(0)')).should_be(Children[0]);
29 'should use negative indexing': function(){
30 value_of(Container.getElement(':children(-2)')).should_be(Children[8]);
33 'should return a range of child nodes': function(){
34 value_of(Container.getElements(':children(0:2)')).should_be(Children.slice(0,3));
37 'should return a range of child nodes including negative index sorted from first to last node': function(){
38 var children = Children.slice(0,3).extend(Children.slice(8));
39 value_of(Container.getElements(':children(-2:2)')).should_be(children);
40 value_of(Container.getElements(':children(2:-2)')).should_be(Children.slice(2,9));
43 'should return the node and n-number of child nodes to the right': function(){
44 value_of(Container.getElements(':children(3+2)')).should_be(Children.slice(3,6));
47 'should return the node and n-number of child nodes to the right and wrap if necessary and sorting from first to last': function(){
48 var children = Children.slice(0,3).extend(Children.slice(8));
49 value_of(Container.getElements(':children(8+4)')).should_be(children);
52 'should return the node and n-number of child nodes to the left': function(){
53 value_of(Container.getElements(':children(5-5)')).should_be(Children.slice(0,6));
56 'should return the node and n-number of child nodes to the left and wrap if necessary and sorting from first to last': function(){
57 var children = Children.slice(0,3).extend(Children.slice(7));
58 value_of(Container.getElements(':children(2-5)')).should_be(children);