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
|
#!/usr/bin/perl
use lib qw (../lib lib);
use Test::More 'no_plan';
use strict;
use warnings;
use MKDoc::XML::Token;
use MKDoc::XML::Stripper;
# let's test this _node_to_tag business
{
my $r;
$r = MKDoc::XML::Stripper::_node_to_tag ( { _tag => 'b', _open => 1 } );
is ($r, '<b>');
$r = MKDoc::XML::Stripper::_node_to_tag ( { _tag => 'b', _close => 1 } );
is ($r, '</b>');
$r = MKDoc::XML::Stripper::_node_to_tag ( { _tag => 'b', _open => 1, _close => 1 } );
is ($r, '<b />');
$r = MKDoc::XML::Stripper::_node_to_tag ( { _tag => 'b', _open => 1, extra => "foo" } );
is ($r, '<b extra="foo">');
$r = MKDoc::XML::Stripper::_node_to_tag ( { _tag => 'b', _close => 1, extra => "foo" } );
is ($r, '</b>');
$r = MKDoc::XML::Stripper::_node_to_tag ( { _tag => 'b', _open => 1, _close => 1, extra => "foo" } );
is ($r, '<b extra="foo" />');
$r = MKDoc::XML::Stripper::_node_to_tag ( { _tag => 'b', _open => 1, extra => "'foo'" } );
is ($r, '<b extra="\'foo\'">');
$r = MKDoc::XML::Stripper::_node_to_tag ( { _tag => 'b', _close => 1, extra => "'foo'" } );
is ($r, '</b>');
$r = MKDoc::XML::Stripper::_node_to_tag ( { _tag => 'b', _open => 1, _close => 1, extra => "'foo'" } );
is ($r, '<b extra="\'foo\'" />');
$r = MKDoc::XML::Stripper::_node_to_tag ( { _tag => 'b', _open => 1, extra => "\"foo\"" } );
is ($r, '<b extra=\'"foo"\'>');
$r = MKDoc::XML::Stripper::_node_to_tag ( { _tag => 'b', _close => 1, extra => "\"foo\"" } );
is ($r, '</b>');
$r = MKDoc::XML::Stripper::_node_to_tag ( { _tag => 'b', _open => 1, _close => 1, extra => "\"foo\"" } );
is ($r, '<b extra=\'"foo"\' />');
}
# now let's perform some tests on MKDoc::XML::Stripper objects
{
my $s = new MKDoc::XML::Stripper;
ok ($s->isa ('MKDoc::XML::Stripper'));
# allow p along with 'class' and 'id' attributes
$s->allow (qw /p class id/);
ok ($s->{p});
is (ref $s->{p}, 'HASH');
ok ($s->{p}->{class});
ok ($s->{p}->{id});
ok (!$s->{p}->{p});
# let's see if the 'strip' method works...
my $token = undef;
$token = new MKDoc::XML::Token ('hello');
ok ($s->strip ($token));
is ($s->strip ($token)->as_string, 'hello');
$token = new MKDoc::XML::Token ('<hello>');
ok (!$s->strip ($token));
$token = new MKDoc::XML::Token ('</hello>');
ok (!$s->strip ($token));
$token = new MKDoc::XML::Token ('<hello />');
ok (!$s->strip ($token));
$token = new MKDoc::XML::Token ('<hello name="foo" />');
ok (!$s->strip ($token));
$token = new MKDoc::XML::Token ('<hello name=\'foo\' />');
ok (!$s->strip ($token));
$token = new MKDoc::XML::Token ('<hello name="foo">');
ok (!$s->strip ($token));
$token = new MKDoc::XML::Token ('<hello name=\'foo\'>');
ok (!$s->strip ($token));
$token = new MKDoc::XML::Token ('<p>');
ok ($s->strip ($token));
$token = new MKDoc::XML::Token ('<p class="para" id="someid" foo="bar">');
my $r = $s->strip ($token)->as_string();
like ($r, qr /<p/);
like ($r, qr /class="para"/);
like ($r, qr /id="someid"/);
unlike ($r, qr /foo="bar"/);
}
1;
__END__
|