File: test_3_47.t

package info (click to toggle)
libxml-twig-perl 1%3A3.50-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 4,404 kB
  • ctags: 2,144
  • sloc: perl: 20,948; xml: 418; makefile: 7
file content (45 lines) | stat: -rwxr-xr-x 1,410 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/perl

use strict;
use warnings;

use XML::Twig;
use Test::More tests => 3;

use utf8;

# test CDATA sections in HTML escaping https://rt.cpan.org/Ticket/Display.html?id=86773

               # module              =>  XML::Twig->new options
my %html_conv= ( 'HTML::TreeBuilder' =>  {},
                 'HTML::Tidy'        =>  { use_tidy => 1 },
               );
foreach my $module ( sort keys  %html_conv)
  { SKIP: 
      { eval "use $module";
        skip "$module not available", 1 if 1 ;

        my $in = q{<h1>Here&amp;there v&amp;r;</h1><p>marco&amp;company; and marco&amp;company &pound; &#163; &#xA3; £</p>};
        my $expected= q{<h1>Here&amp;there v&amp;r;</h1><p>marco&amp;company; and marco&amp;company £ £ £ £</p>};

        my $parser= XML::Twig->new( %{$html_conv{$module}});
        my $t = $parser->safe_parse_html($in);
        print $@ if $@;

        like $t->sprint, qr{\Q$expected\E}, "In and out are the same ($module)";

      }
  }

{ # test RT #94295 https://rt.cpan.org/Public/Bug/Display.html?id=94295
  # in twig_handlers, '=' in regexps on attributes are turned into 'eq'
  my $xml= '<doc><e dn="foo=1 host=0">e1</e><e dn="foo=1 host=2">e2</e></doc>';
  my $r;
  my $t= XML::Twig->new( twig_handlers => { 'e[@dn =~ /host=0/]' => sub { $r.= $_->text } })
                  ->parse( $xml);
  is( $r, 'e1', 'regexp on attribute, including an = sign');
}
exit;