File: 20bugs.t

package info (click to toggle)
libxml-sax-writer-perl 0.57-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 176 kB
  • sloc: perl: 553; makefile: 2
file content (98 lines) | stat: -rwxr-xr-x 2,629 bytes parent folder | download | duplicates (4)
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

###
# XML::SAX::Writer tests
# Petr Cimprich <petr@gingerall.com>
# 09/11/2006 - v0.01
###

use strict;

use Test::More tests => 3;
use XML::SAX::Writer qw();

my $isoL1 = ($^O eq 'VMS') ? 'iso8859-1' : 'iso-8859-1';
my $out = '';
my $str1 = 'foo'; 
my $str2 = 'žščřďťňáéíóůúý'; # can't be encoded in iso-8859-1


##################################################
# encoding test
my $w = XML::SAX::Writer->new({
                                EncodeFrom  => 'utf-8',
                                EncodeTo    => $isoL1,
                                Output      => \$out,
                               })->{Handler};

$w->start_document;
$w->start_element({Name	=> 'root', 
		   Prefix => '', 
		   LocalName => 'root',
		   NamespaceURI => '',
		   Attributes => {}});
$w->characters({Data => $str1});
$w->end_element({Name	=> 'root', 
		 Prefix => '', 
		 LocalName => 'root',
		 NamespaceURI => ''});
$w->end_document;
#print $out;

ok($out eq "<root>$str1</root>", 'ASCII characters');


##################################################
# encoding error - char does not exist in a codepage
$w = XML::SAX::Writer->new({
                             EncodeFrom  => 'utf-8',
                             EncodeTo    => $isoL1,
                             Output      => \$out,
                            })->{Handler};

# silent warnings since now
$SIG{__WARN__} = sub {};

$w->start_document;
$w->start_element({Name	=> 'root', 
		   Prefix => '', 
		   LocalName => 'root',
		   NamespaceURI => '',
		   Attributes => {}});
$w->characters({Data => $str2});
$w->end_element({Name	=> 'root', 
		 Prefix => '', 
		 LocalName => 'root',
		 NamespaceURI => ''});
$w->end_document;

ok($out eq "<root>_LOST_DATA_</root>", 'Latin2 characters');

##################################################
# Whitespace not properly escaped in attribute values #11
# https://github.com/perigrin/xml-sax-writer/issues/11

$w = XML::SAX::Writer->new({Output => \$out})->{Handler};
$w->start_document;
$w->start_element({
    Name	=> 'root', 
    Prefix => '', 
    LocalName => 'root',
    NamespaceURI => '',
    Attributes => {
        whitespace => {
            Name	=> 'whitespace', 
            Prefix => '', 
            LocalName => 'whitespace',
            NamespaceURI => '',
            Value => "tab=[\t],newline=[\n],carriage_return=[\r]"
        }
    }
});
$w->end_element({Name	=> 'root', 
		 Prefix => '', 
		 LocalName => 'root',
		 NamespaceURI => ''});
$w->end_document;
is($out, 
    "<root whitespace='tab=[&#x9;],newline=[&#xA;],carriage_return=[&#xD;]' />", 
    'attributes with whitespace');