File: test_need_use_bytes.t

package info (click to toggle)
libxml-twig-perl 1%3A3.52-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 4,952 kB
  • sloc: perl: 21,221; xml: 423; makefile: 9
file content (59 lines) | stat: -rwxr-xr-x 1,754 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl -w


# tests that require IO::Scalar to run
use strict;
use Carp;

use File::Spec;
use lib File::Spec->catdir(File::Spec->curdir,"t");
use tools;

#$|=1;
my $DEBUG=0;

use XML::Twig;

BEGIN 
  { eval "use bytes";
    if( $@) 
      { print "1..1\nok 1\n"; 
        warn "skipping, need to be able to use bytes\n";
        exit;
      } 
  }

print "1..2\n";

my $text= "été";
my $text_safe= "été";
my $text_safe_hex= "été";
my $doc=qq{<?xml version="1.0" encoding="UTF-8"?>\n<doc>$text</doc>};
my $doc_safe=qq{<?xml version="1.0" encoding="UTF-8"?>\n<doc>$text_safe</doc>};
my $doc_safe_hex=qq{<?xml version="1.0" encoding="UTF-8"?>\n<doc>$text_safe_hex</doc>};

my $t= XML::Twig->new()->parse( $doc);

if( $] == 5.008)
  { skip( 2); }
else
  { $t->set_output_text_filter( sub { my $text= shift;
                                      use bytes;
                                      $text=~ s{([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)}
                                               {XML::Twig::_XmlUtf8Decode($1)}egs;
                                      return $text;
                                    }
                          );
    is( $t->sprint, $doc_safe, 'safe with _XmlUtf8Decode');  # test 338
    $t->set_output_text_filter( sub { my $text= shift;
                                      use bytes;
                                      $text=~ s{([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)}
                                               {XML::Twig::_XmlUtf8Decode($1, 1)}egs;
                                      return $text;
                                    }
                          );
    is( $t->sprint, $doc_safe_hex, 'safe_hex with _XmlUtf8Decode');  # test 339
  }


exit 0;