File: gather.t

package info (click to toggle)
libpod-elemental-perl 0.103004-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 408 kB
  • ctags: 84
  • sloc: perl: 1,507; makefile: 7
file content (125 lines) | stat: -rw-r--r-- 2,332 bytes parent folder | download | duplicates (3)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!perl
use strict;
use warnings;

use Test::More;
use Test::Differences;

use Pod::Eventual::Simple;
use Pod::Elemental;
use Pod::Elemental::Selectors -all;
use Pod::Elemental::Transformer::Pod5;
use Pod::Elemental::Transformer::Nester;
use Pod::Elemental::Transformer::Gatherer;

my $str = do { local $/; <DATA> };

my $document = Pod::Elemental->read_string($str);

Pod::Elemental::Transformer::Pod5->transform_node($document);

my $nester = Pod::Elemental::Transformer::Nester->new({
  top_selector => s_command([ qw(head1 method) ]),
  content_selectors => [
    s_flat,
    s_command( [ qw(head2 head3 head4 over item back) ]),
  ],
});

my $gatherer = Pod::Elemental::Transformer::Gatherer->new({
  gather_selector => s_command([ qw(method) ]),
  container       => Pod::Elemental::Element::Nested->new({
    command => 'head1',
    content => "METHODS\n",
  }),
});

$nester->transform_node($document);
$gatherer->transform_node($document);

$_->command('head2')
  foreach grep { s_command('method')->($_) } @{ $gatherer->container->children };

my @children = @{ $document->children };

is(@children, 4, "the nested document has 4 top-level elements"); 

ok(s_flat($children[0]), "the first paragraph is a flat/text paragraph");

ok(
  $children[1]->isa('Pod::Elemental::Element::Nested'),
  "the second paragraph is a nested command node",
);

{
  my @children = @{ $children[1]->children };
  is(@children, 1, "...which has 1 child");
}

ok(
  $children[2]->isa('Pod::Elemental::Element::Nested'),
  "the third paragraph is a nested command node",
);

{
  my @children = @{ $children[2]->children };
  is(@children, 2, "...which has 2 children");

  {
    my @children = @{ $children[0]->children };
    is(@children, 10, "...the first of which which has 10 children");
  }
}

ok(
  $children[3]->isa('Pod::Elemental::Element::Nested'),
  "the fourth paragraph is a nested command node",
);

{
  my @children = @{ $children[3]->children };
  is(@children, 1, "...which has 1 child");
}

done_testing;

__DATA__
=pod

Ordinary Paragraph 1.1

=head1 Header 1.1

=head2 Header 2.1

=method foo

Ordinary Paragraph 2.1

=over 2

=item * bar

=back

=head2 Header 2.2

Ordinary Paragraph 2.2

=head3 Header 3.1

=over 4

=item * foo

=back

=head1 Header 1.2

Ordinary Paragraph 2.3

=method quux

Ordinary Paragraph 2.4

=cut