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
|
###
# XML::SAX::Writer tests
# Petr Cimprich <petr@gingerall.com>
# 09/11/2006 - v0.01
###
use strict;
use Test::More tests => 2;
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');
|