File: 15-parentage.t

package info (click to toggle)
libsvg-perl 2.87-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 464 kB
  • sloc: perl: 2,789; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,453 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use strict;
use warnings;

use Test::More tests => 18;
use SVG;

# test: getFirstChild, getLastChild, getParent, getChildren

my $svg    = SVG->new;
my $parent = $svg->group();
my $child1 = $parent->text->cdata("I am the first child");
my $child2 = $parent->text->cdata("I am the second child");
my $child3 = $parent->text->cdata("I am the third child");

is( $parent->getFirstChild(), $child1, "getFirstChild" );
is( $child1->getParent(),     $parent, "getParent 1" );
is( $parent->getLastChild(),  $child3, "getLastChild" );
is( $child2->getParent(),     $parent, "getParent 2" );
ok( $parent->hasChildren(), "hasChildren" );

my @children = $parent->getChildren();
is( scalar(@children), 3,       "correct number of children" );
is( $children[0],      $child1, "getChildren 1" );
is( $children[1],      $child2, "getChildren 2" );
is( $children[2],      $child3, "getChildren 3" );

is( $parent->removeChild($child1),    $child1, 'removeChild1' );
is( $parent->removeChild($child3),    $child3, 'removeChild3' );
is( $parent->removeChild($child2),    $child2, 'removeChild2' );
is( $parent->removeChild($child1),    0,       'no such child' );
is( $parent->findChildIndex($child1), -1,      'child1 is gone' );

is( $parent->insertAtIndex( $child1, 0 ), 1 );
is( $parent->findChildIndex($child1),     0, 'child1 is back' );
is( $parent->removeAtIndex(0),            $child1 );
is( $parent->findChildIndex($child1),     -1, 'child1 is gone again' );