X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fdom.t;h=0a5523954a8e80fe7af63ae66f46f7f76cc9d462;hb=c7cad649fb91d58c980fcf047c47a7dc09e8be6f;hp=e345d2704797fd16452ec47d0264b4612ee8d0a6;hpb=ba90904812100c8408eaa44df5886241e7c13319;p=catagits%2FDOM-Tiny.git
diff --git a/t/dom.t b/t/dom.t
index e345d27..0a55239 100644
--- a/t/dom.t
+++ b/t/dom.t
@@ -243,6 +243,8 @@ is $dom->at('b')->child_nodes->[1]->next, undef, 'no siblings';
is $dom->at('script')->child_nodes->first->wrap(':)')->root,
'', 'right result';
is $dom->at('i')->child_nodes->first->wrap_content('')->root,
+ '', 'no changes';
+is $dom->at('i')->child_nodes->first->wrap('')->root,
'', 'right result';
is $dom->at('b')->child_nodes->first->ancestors->map('tag')->join(','),
'b,i,script', 'right result';
@@ -979,28 +981,28 @@ $dom->find('li:nth-last-child(4n+1)')->each(sub { push @li, shift->text });
is_deeply \@li, [qw(D H)], 'found the right li elements';
@li = ();
$dom->find('li:nth-child(4n+4)')->each(sub { push @li, shift->text });
-is_deeply \@li, [qw(D H)], 'found the right li element';
+is_deeply \@li, [qw(D H)], 'found the right li elements';
@li = ();
$dom->find('li:nth-last-child(4n+4)')->each(sub { push @li, shift->text });
-is_deeply \@li, [qw(A E)], 'found the right li element';
+is_deeply \@li, [qw(A E)], 'found the right li elements';
@li = ();
$dom->find('li:nth-child(4n)')->each(sub { push @li, shift->text });
-is_deeply \@li, [qw(D H)], 'found the right li element';
+is_deeply \@li, [qw(D H)], 'found the right li elements';
@li = ();
$dom->find('li:nth-child( 4n )')->each(sub { push @li, shift->text });
-is_deeply \@li, [qw(D H)], 'found the right li element';
+is_deeply \@li, [qw(D H)], 'found the right li elements';
@li = ();
$dom->find('li:nth-last-child(4n)')->each(sub { push @li, shift->text });
-is_deeply \@li, [qw(A E)], 'found the right li element';
+is_deeply \@li, [qw(A E)], 'found the right li elements';
@li = ();
$dom->find('li:nth-child(5n-2)')->each(sub { push @li, shift->text });
-is_deeply \@li, [qw(C H)], 'found the right li element';
+is_deeply \@li, [qw(C H)], 'found the right li elements';
@li = ();
$dom->find('li:nth-child( 5n - 2 )')->each(sub { push @li, shift->text });
-is_deeply \@li, [qw(C H)], 'found the right li element';
+is_deeply \@li, [qw(C H)], 'found the right li elements';
@li = ();
$dom->find('li:nth-last-child(5n-2)')->each(sub { push @li, shift->text });
-is_deeply \@li, [qw(A F)], 'found the right li element';
+is_deeply \@li, [qw(A F)], 'found the right li elements';
@li = ();
$dom->find('li:nth-child(-n+3)')->each(sub { push @li, shift->text });
is_deeply \@li, [qw(A B C)], 'found first three li elements';
@@ -1029,26 +1031,43 @@ is_deeply \@li, [qw(C F)], 'found every third li elements';
$dom->find('li:Nth-Last-Child(3N)')->each(sub { push @li, shift->text });
is_deeply \@li, [qw(C F)], 'found every third li elements';
@li = ();
-$dom->find('li:nth-child(3)')->each(sub { push @li, shift->text });
+$dom->find('li:nth-child( 3 )')->each(sub { push @li, shift->text });
is_deeply \@li, ['C'], 'found third li element';
@li = ();
-$dom->find('li:nth-last-child(3)')->each(sub { push @li, shift->text });
+$dom->find('li:nth-last-child( +3 )')->each(sub { push @li, shift->text });
is_deeply \@li, ['F'], 'found third last li element';
@li = ();
$dom->find('li:nth-child(1n+0)')->each(sub { push @li, shift->text });
-is_deeply \@li, [qw(A B C D E F G)], 'found first three li elements';
+is_deeply \@li, [qw(A B C D E F G)], 'found all li elements';
+@li = ();
+$dom->find('li:nth-child(1n-0)')->each(sub { push @li, shift->text });
+is_deeply \@li, [qw(A B C D E F G)], 'found all li elements';
+@li = ();
+$dom->find('li:nth-child(n+0)')->each(sub { push @li, shift->text });
+is_deeply \@li, [qw(A B C D E F G)], 'found all li elements';
+@li = ();
+$dom->find('li:nth-child(n)')->each(sub { push @li, shift->text });
+is_deeply \@li, [qw(A B C D E F G)], 'found all li elements';
@li = ();
$dom->find('li:nth-child(n+0)')->each(sub { push @li, shift->text });
-is_deeply \@li, [qw(A B C D E F G)], 'found first three li elements';
+is_deeply \@li, [qw(A B C D E F G)], 'found all li elements';
@li = ();
$dom->find('li:NTH-CHILD(N+0)')->each(sub { push @li, shift->text });
-is_deeply \@li, [qw(A B C D E F G)], 'found first three li elements';
+is_deeply \@li, [qw(A B C D E F G)], 'found all li elements';
@li = ();
$dom->find('li:Nth-Child(N+0)')->each(sub { push @li, shift->text });
-is_deeply \@li, [qw(A B C D E F G)], 'found first three li elements';
+is_deeply \@li, [qw(A B C D E F G)], 'found all li elements';
@li = ();
$dom->find('li:nth-child(n)')->each(sub { push @li, shift->text });
-is_deeply \@li, [qw(A B C D E F G)], 'found first three li elements';
+is_deeply \@li, [qw(A B C D E F G)], 'found all li elements';
+@li = ();
+$dom->find('li:nth-child(0n+1)')->each(sub { push @li, shift->text });
+is_deeply \@li, [qw(A)], 'found first li element';
+is $dom->find('li:nth-child(0n+0)')->size, 0, 'no results';
+is $dom->find('li:nth-child(0)')->size, 0, 'no results';
+is $dom->find('li:nth-child()')->size, 0, 'no results';
+is $dom->find('li:nth-child(whatever)')->size, 0, 'no results';
+is $dom->find('li:whatever(whatever)')->size, 0, 'no results';
# Even more pseudo-classes
$dom = DOM::Tiny->new(<find('ul :nth-child(-n+3):not(li)')->each(sub { push @e, shift->text });
is_deeply \@e, ['B'], 'found first p element';
@e = ();
+$dom->find('ul :nth-child(-n+3):NOT(li)')->each(sub { push @e, shift->text });
+is_deeply \@e, ['B'], 'found first p element';
+@e = ();
$dom->find('ul :nth-child(-n+3):not(:first-child)')
->each(sub { push @e, shift->text });
is_deeply \@e, [qw(B C)], 'found second and third element';
@@ -1250,8 +1272,9 @@ is "$dom", <at('div')->text, 'A-1', 'right text';
is $dom->at('iv'), undef, 'no result';
-$dom->prepend('l')->prepend('alal')->prepend('a');
-is "$dom", <prepend('l')->prepend('alal')->prepend('a')->type, 'root',
+ 'right type';
+is "$dom", <
24A-1
25AA1
23
B
@@ -1259,8 +1282,8 @@ is "$dom", <
D
EOF
-$dom->append('lalala');
-is "$dom", <append('lalala')->type, 'root', 'right type';
+is "$dom", <
24A-1
25AA1
23
B
@@ -2105,7 +2128,10 @@ is $dom->all_text, 'DOM Test', 'right text';
# Wrap elements
$dom = DOM::Tiny->new('Test');
+is "$dom", 'Test', 'right result';
is $dom->wrap('')->type, 'root', 'right type';
+is "$dom", 'Test', 'no changes';
+is $dom->at('a')->wrap('')->type, 'tag', 'right type';
is "$dom", 'Test', 'right result';
is $dom->at('b')->strip->at('a')->wrap('A')->tag, 'a', 'right tag';
is "$dom", 'Test', 'right result';