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
|
# ----------------------------------------------------------------
use strict;
use Test::More;
# ----------------------------------------------------------------
{
local $@;
eval { require XML::TreePP; };
plan skip_all => 'XML::TreePP is not loaded.' if $@;
}
{
my $ver = ( $XML::TreePP::VERSION =~ /^(\d+\.\d+)/ )[0];
my $chk = ( $ver >= 0.37 );
plan skip_all => "XML::TreePP $XML::TreePP::VERSION < 0.37" unless $chk;
plan tests => 28;
ok( $chk, 'XML::TreePP '.$ver );
use_ok('XML::FeedPP');
&test_main();
}
# ----------------------------------------------------------------
sub test_main {
my $rss = <<'EOT';
<rss version="2.0">
<channel>
<item>
<title>©</title>
<description>©</description>
</item>
<item>
<title>ë</title>
<description>ë</description>
</item>
<item>
<title>ん</title>
<description>ん</description>
</item>
<item>
<title>漢</title>
<description>漢</description>
</item>
</channel>
</rss>
EOT
my $feedA = XML::FeedPP->new( $rss, xml_deref => 0 );
my $cntA = $feedA->get_item;
is( $cntA, 4, 'item count' );
foreach my $item ( $feedA->get_item ) {
my $title = $item->title;
my $description = $item->description;
ok( $title ne $description, 'no deref unmatch' );
like( $title, qr/&#\w+;/, 'no deref title '.$title );
like( $description, qr/&#\w+;/, 'no deref description '.$description );
}
my $feedB = XML::FeedPP->new( $rss, xml_deref => 1 );
my $cntB = $feedB->get_item;
is( $cntB, 4, 'item count' );
foreach my $item ( $feedB->get_item ) {
my $title = $item->title;
my $description = $item->description;
ok( $title eq $description, 'xml_deref match' );
unlike( $title, qr/&#\w+;/, 'xml_deref title '.$title );
unlike( $description, qr/&#\w+;/, 'xml_deref description '.$description );
}
}
# ----------------------------------------------------------------
|