This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Pod-Simple to CPAN version 3.18
[perl5.git] / cpan / Pod-Simple / t / linkclas.t
1 # Testing the LinkSection class
2 BEGIN {
3     if($ENV{PERL_CORE}) {
4         chdir 't';
5         @INC = '../lib';
6     }
7 }
8
9 ### Test the basic sanity of the link-section treelet class
10
11 use strict;
12 use Test;
13 BEGIN { plan tests => 8 };
14
15 #use Pod::Simple::Debug (6);
16
17 ok 1;
18
19 use Pod::Simple::LinkSection;
20 use Pod::Simple::BlackBox; # for its pretty()
21
22 my $bare_treelet =
23   ['B', {'pie' => 'no'},
24    'a',
25    ['C', {'bzrok' => 'plip'},
26     'b'
27    ],
28    'c'
29   ]
30 ;
31 my $treelet = Pod::Simple::LinkSection->new($bare_treelet);
32
33 # Make sure they're not the same
34
35 ok ref($bare_treelet), 'ARRAY';
36 ok ref($treelet), 'Pod::Simple::LinkSection';
37
38 print "# Testing stringification...\n";
39
40 ok $treelet->stringify, 'abc';  # explicit
41 ok join('', $treelet),  'abc';  # implicit
42
43
44 print "# Testing non-coreferentiality...\n";
45 {
46   my @stack = ($bare_treelet);
47   my $this;
48   while(@stack) {
49     $this = shift @stack;
50     if(ref($this || '') eq 'ARRAY') {
51       push @stack, splice @$this;
52       push @$this, ("BAD!") x 3;
53     } elsif(ref($this || '') eq 'Pod::Simple::LinkSection') {
54       push @stack, splice @$this;
55       push @$this, ("BAD!") x 3;
56     } elsif(ref($this || '') eq 'HASH') {
57       %$this = ();
58     }
59   }
60   # These will fail if $treelet and $bare_treelet are coreferential,
61   # since we just conspicuously nuked $bare_treelet
62   
63   ok $treelet->stringify, 'abc';  # explicit
64   ok join('', $treelet),  'abc';  # implicit
65 }
66
67
68 print "# Byebye...\n";
69 ok 1;
70 print "# --- Done with ", __FILE__, " --- \n";
71