File: nester.t

package info (click to toggle)
libpod-elemental-perl 0.103006-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 396 kB
  • sloc: perl: 1,471; makefile: 7
file content (85 lines) | stat: -rw-r--r-- 1,529 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
#!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;

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('head1'),
  content_selectors => [
    s_flat,
    s_command( [ qw(head2 head3 head4 over item back) ]),
  ],
});

$nester->transform_node($document);

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

is(@children, 3, "the nested document has 3 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, 7, "...which has 7 children");
}

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

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

eq_or_diff($document->as_pod_string, $str, "round-tripped okay");

done_testing;

__DATA__
=pod

Ordinary Paragraph 1.1

=head1 Header 1.1

=head2 Header 2.1

=head2 Header 2.2

Ordinary Paragraph 2.1

=head3 Header 3.1

=over 4

=item * foo

=back

=head1 Header 1.2

Ordinary Paragraph 2.1

=cut