File: accept01.t

package info (click to toggle)
perl 5.40.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 126,152 kB
  • sloc: ansic: 668,539; perl: 525,522; sh: 72,038; pascal: 6,925; xml: 2,428; yacc: 1,410; makefile: 1,191; cpp: 208; lisp: 1
file content (82 lines) | stat: -rw-r--r-- 2,568 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
# Testing accept_codes
use strict;
use warnings;
use Test::More tests => 11;

#use Pod::Simple::Debug (6);

use Pod::Simple::DumpAsXML;
use Pod::Simple::XMLOutStream;
print "# Pod::Simple version $Pod::Simple::VERSION\n";

BEGIN {
  require FindBin;
  unshift @INC, $FindBin::Bin . '/lib';
}
use helpers;

my $x = 'Pod::Simple::XMLOutStream';
sub accept_N { $_[0]->accept_codes('N') }

print "# Some sanity tests...\n";
is( $x->_out( "=pod\n\nI like pie.\n"), # without acceptor
  '<Document><Para>I like pie.</Para></Document>'
);
is( $x->_out( \&accept_N, "=pod\n\nI like pie.\n"),
  '<Document><Para>I like pie.</Para></Document>'
);
is( $x->_out( "=pod\n\nB<foo\t>\n"), # without acceptor
  '<Document><Para><B>foo </B></Para></Document>'
);
is( $x->_out( \&accept_N,  "=pod\n\nB<foo\t>\n"),
  '<Document><Para><B>foo </B></Para></Document>'
);

print "# Some real tests...\n";

is( $x->_out( \&accept_N,  "=pod\n\nN<foo\t>\n"),
  '<Document><Para><N>foo </N></Para></Document>'
);
is( $x->_out( \&accept_N,  "=pod\n\nB<N<foo\t>>\n"),
  '<Document><Para><B><N>foo </N></B></Para></Document>'
);
isnt( $x->_out( "=pod\n\nB<N<foo\t>>\n"), # without the mutor
  '<Document><Para><B><N>foo </N></B></Para></Document>'
  # make sure it DOESN'T pass thru the N<...> when not accepted
);
is( $x->_out( \&accept_N,  "=pod\n\nB<pieF<zorch>N<foo>I<pling>>\n"),
  '<Document><Para><B>pie<F>zorch</F><N>foo</N><I>pling</I></B></Para></Document>'
);

print "# Tests of nonacceptance...\n";

sub starts_with {
  my($large, $small) = @_;
  print("# supahstring is undef\n"),
   return '' unless defined $large;
  print("# supahstring $large is smaller than target-starter $small\n"),
   return '' if length($large) < length($small);
  if( substr($large, 0, length($small)) eq $small ) {
    #print "# Supahstring $large\n#  indeed starts with $small\n";
    return 1;
  } else {
    print "# Supahstring $large\n#  !starts w/ $small\n";
    return '';
  }
}


ok( starts_with( $x->_out( "=pod\n\nB<N<foo\t>>\n"), # without the mutor
  '<Document><Para><B>foo </B></Para>'
  # make sure it DOESN'T pass thru the N<...>, when not accepted
));

ok( starts_with( $x->_out( "=pod\n\nB<pieF<zorch>N<foo>I<pling>>\n"), # !mutor
  '<Document><Para><B>pie<F>zorch</F>foo<I>pling</I></B></Para>'
  # make sure it DOESN'T pass thru the N<...>, when not accepted
));

ok( starts_with( $x->_out( "=pod\n\nB<pieF<zorch>N<C<foo>>I<pling>>\n"), # !mutor
  '<Document><Para><B>pie<F>zorch</F><C>foo</C><I>pling</I></B></Para>'
  # make sure it DOESN'T pass thru the N<...>, when not accepted
));