2
use Test::More tests => 48;
6
use HTML::StripScripts;
8
my %tags_b = ( 'undef' => undef,
11
'sub' => \&b_callback,
13
'tag_sub' => { tag => \&b_callback }
15
my %tags_default = ( 'undef' => undef,
18
'sub' => \&default_callback,
20
'tag_0' => { tag => 0 },
21
'tag_1' => { tag => 1 },
22
'tag_sub' => { tag => \&default_callback }
27
foreach my $b (qw(undef 0 1 sub hash tag_sub)) {
28
foreach my $default (qw(undef 0 1 sub hash tag_0 tag_1 tag_sub)) {
29
my $test = "${b} :: ${default}";
30
test_tag( $test, $tags_b{$b}, $tags_default{$default},
35
#===================================
37
#===================================
38
my ( $test, $b, $default, $result ) = @_;
44
if ( defined $default ) {
45
$Rules{'*'} = $default;
48
my $f = HTML::StripScripts->new( { Rules => \%Rules } );
50
$f->input_start_document;
51
$f->input_start('<b>');
52
$f->input_text('foo');
53
$f->input_end('</b>');
54
$f->input_start('<i>');
55
$f->input_text('bar');
56
$f->input_end('</i>');
57
$f->input_end_document;
58
is( $f->filtered_document, $result, "$test" );
61
#===================================
63
#===================================
64
my ( $filter, $e ) = @_;
66
= "[B : tag='$e->{tag}', content='$e->{content}']" . $e->{content};
70
#===================================
71
sub default_callback {
72
#===================================
73
my ( $filter, $e ) = @_;
74
$e->{content} = "[DEFAULT : tag='$e->{tag}', content='$e->{content}']"
82
my $filt = '<!--filtered-->';
83
my $def_b = "[DEFAULT : tag='b', content='foo']";
84
my $def_i = "[DEFAULT : tag='i', content='bar']";
85
my $b = "[B : tag='b', content='foo']";
88
'undef :: undef' => "<b>foo</b><i>bar</i>",
89
'undef :: 0' => "${filt}foo${filt}${filt}bar${filt}",
90
'undef :: 1' => "<b>foo</b><i>bar</i>",
91
'undef :: sub' => "<b>${def_b}foo</b><i>${def_i}bar</i>",
92
'undef :: hash' => "<b>foo</b><i>bar</i>",
93
'undef :: tag_0' => "${filt}foo${filt}${filt}bar${filt}",
94
'undef :: tag_1' => "<b>foo</b><i>bar</i>",
95
'undef :: tag_sub' => "<b>${def_b}foo</b><i>${def_i}bar</i>",
96
'0 :: undef' => "${filt}foo${filt}<i>bar</i>",
97
'0 :: 0' => "${filt}foo${filt}${filt}bar${filt}",
98
'0 :: 1' => "${filt}foo${filt}<i>bar</i>",
99
'0 :: sub' => "${filt}foo${filt}<i>${def_i}bar</i>",
100
'0 :: hash' => "${filt}foo${filt}<i>bar</i>",
101
'0 :: tag_0' => "${filt}foo${filt}${filt}bar${filt}",
102
'0 :: tag_1' => "${filt}foo${filt}<i>bar</i>",
103
'0 :: tag_sub' => "${filt}foo${filt}<i>${def_i}bar</i>",
104
'1 :: undef' => "<b>foo</b><i>bar</i>",
105
'1 :: 0' => "<b>foo</b>${filt}bar${filt}",
106
'1 :: 1' => "<b>foo</b><i>bar</i>",
107
'1 :: sub' => "<b>${def_b}foo</b><i>${def_i}bar</i>",
108
'1 :: hash' => "<b>foo</b><i>bar</i>",
109
'1 :: tag_0' => "<b>foo</b>${filt}bar${filt}",
110
'1 :: tag_1' => "<b>foo</b><i>bar</i>",
111
'1 :: tag_sub' => "<b>${def_b}foo</b><i>${def_i}bar</i>",
112
'sub :: undef' => "<b>${b}foo</b><i>bar</i>",
113
'sub :: 0' => "<b>${b}foo</b>${filt}bar${filt}",
114
'sub :: 1' => "<b>${b}foo</b><i>bar</i>",
115
'sub :: sub' => "<b>${b}foo</b><i>${def_i}bar</i>",
116
'sub :: hash' => "<b>${b}foo</b><i>bar</i>",
117
'sub :: tag_0' => "<b>${b}foo</b>${filt}bar${filt}",
118
'sub :: tag_1' => "<b>${b}foo</b><i>bar</i>",
119
'sub :: tag_sub' => "<b>${b}foo</b><i>${def_i}bar</i>",
120
'hash :: undef' => "<b>foo</b><i>bar</i>",
121
'hash :: 0' => "<b>foo</b>${filt}bar${filt}",
122
'hash :: 1' => "<b>foo</b><i>bar</i>",
123
'hash :: sub' => "<b>${def_b}foo</b><i>${def_i}bar</i>",
124
'hash :: hash' => "<b>foo</b><i>bar</i>",
125
'hash :: tag_0' => "<b>foo</b>${filt}bar${filt}",
126
'hash :: tag_1' => "<b>foo</b><i>bar</i>",
127
'hash :: tag_sub' => "<b>${def_b}foo</b><i>${def_i}bar</i>",
128
'tag_sub :: undef' => "<b>${b}foo</b><i>bar</i>",
129
'tag_sub :: 0' => "<b>${b}foo</b>${filt}bar${filt}",
130
'tag_sub :: 1' => "<b>${b}foo</b><i>bar</i>",
131
'tag_sub :: sub' => "<b>${b}foo</b><i>${def_i}bar</i>",
132
'tag_sub :: hash' => "<b>${b}foo</b><i>bar</i>",
133
'tag_sub :: tag_0' => "<b>${b}foo</b>${filt}bar${filt}",
134
'tag_sub :: tag_1' => "<b>${b}foo</b><i>bar</i>",
135
'tag_sub :: tag_sub' => "<b>${b}foo</b><i>${def_i}bar</i>",