Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
a few more sibling tests
  • Loading branch information
kraih committed Oct 31, 2012
1 parent d3f92df commit be8cfc7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Mojo/DOM.pm
Expand Up @@ -355,11 +355,11 @@ sub _sibling {
return undef unless my $parent = $self->parent;

# Find previous or next sibling
my ($candidate, $current);
my ($previous, $current);
for my $child ($parent->children->each) {
++$current and next if $child->tree eq $self->tree;
return $next ? $child : $candidate if $current;
$candidate = $child;
return $next ? $child : $previous if $current;
$previous = $child;
}

# No siblings
Expand Down
4 changes: 4 additions & 0 deletions t/mojo/dom.t
Expand Up @@ -650,6 +650,10 @@ is_deeply \@div, [qw(A C)], 'found all div elements with the right atributes';
$dom->find('div[foo^="b"][foo$="r"]')->each(sub { push @div, shift->text });
is_deeply \@div, [qw(A B C)],
'found all div elements with the right atributes';
is $dom->at('[foo="bar"]')->previous, undef, 'no previous sibling';
is $dom->at('[foo="bar"]')->next->text, 'B', 'right text';
is $dom->at('[foo="bar"]')->next->previous->text, 'A', 'right text';
is $dom->at('[foo="bar"]')->next->next->next->next, undef, 'no next sibling';

# Pseudo classes
$dom = Mojo::DOM->new->parse(<<EOF);
Expand Down

0 comments on commit be8cfc7

Please sign in to comment.