8 use lib $Bin, "$Bin/t";
15 name => 'seniority(), prev_sibling(), next_sibling()',
16 filter_elements => 'Org::Element::Headline',
24 test_after_parse => sub {
26 my $h = $args{elements};
27 is($h->[0]->seniority, 0, "h1's seniority=0");
28 is($h->[1]->seniority, 0, "h2a's seniority=0");
29 is($h->[2]->seniority, 1, "h2b's seniority=1");
30 is($h->[3]->seniority, 2, "h2c's seniority=2");
32 ok(!defined($h->[0]->prev_sibling), "h1 doesnt have prev_sibling");
33 ok(!defined($h->[1]->prev_sibling), "h2a doesnt have prev_sibling");
34 is($h->[2]->prev_sibling->title->as_string, "h2a",
35 "h2b's prev_sibling=h2a");
36 is($h->[3]->prev_sibling->title->as_string, "h2b",
37 "h2c's pre_sibling=h2b");
39 ok(!defined($h->[0]->prev_sibling), "h1 doesnt have next_sibling");
40 is($h->[1]->next_sibling->title->as_string, "h2b",
41 "h2a's next_sibling=h2b");
42 is($h->[2]->next_sibling->title->as_string, "h2c",
43 "h2b's next_sibling=h2c");
44 ok(!defined($h->[3]->next_sibling), "h2c doesnt have next_sibling");
55 test_after_parse => sub {
57 my $doc = $args{result};
60 $doc->walk(sub{$n++});
61 # +1 is for document itself
62 # timestamp not walked (part of headline)
63 is($n, 3+1, "num of walked elements");
68 name => 'find(), walk_parents(), headline()',
77 test_after_parse => sub {
79 my $doc = $args{result};
82 $_[0]->isa('Org::Element::Headline') &&
83 $_[0]->title->as_string =~ /^d/;
85 is(scalar(@res), 2, "find num results");
86 ok($res[1]->isa("Org::Element::Headline") &&
87 $res[1]->title->as_string eq 'd2', "find result #2");
93 my ($el, $parent) = @_;
94 return if $parent->isa('Org::Document');
95 $res .= $parent->title->as_string;
97 is($res, "cba", "walk_parents()");
99 is($d->headline->title->as_string, "c", "headline() 1");
100 is($d->children->[0]->headline->title->as_string, "d", "headline() 2");
113 filter_elements => 'Org::Element::Headline',
115 test_after_parse => sub {
117 my $doc = $args{result};
118 my $elems = $args{elements};
119 my ($a, $b, $b2, $b3, $c) = @$elems;
122 my @res = $doc->find('Headline');
123 is(scalar(@res), 2, "remove() removes children");
124 is(scalar(@{$doc->children}), 2,
125 "remove() removes from parent's children");
126 is($a->next_sibling, $c, "a's next_sibling becomes c");
127 is($c->prev_sibling, $a, "c's prev_sibling becomes a");