PageRenderTime 39ms CodeModel.GetById 13ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 1ms

/XML-TreePP/t/49_invalid_encoding.t

http://xml-treepp.googlecode.com/
Unknown | 61 lines | 57 code | 4 blank | 0 comment | 0 complexity | 20834fd5cb397fd34e661a7ff8609096 MD5 | raw file
 1# ----------------------------------------------------------------
 2    use strict;
 3    use Test::More;
 4# ----------------------------------------------------------------
 5{
 6    local $@;
 7    eval { require 5.008001; };
 8    plan skip_all => 'Perl 5.8.1 is required.' if $@;
 9}
10# ----------------------------------------------------------------
11    my $ENC = 'UNKNOWN_ENCODING';
12# ----------------------------------------------------------------
13{
14    plan tests => 4;
15    use_ok('XML::TreePP');
16    &test1();
17    &test2();
18    &test3();
19}
20# ----------------------------------------------------------------
21sub test1 {
22    my $xml = <<"EOT";
23<?xml version="1.0" encoding="$ENC"?>
24<root>
25    <elem>value</elem>
26</root>
27EOT
28
29    my $tpp = XML::TreePP->new();
30
31    local $@;
32    eval {
33        my $tree = $tpp->parse( $xml );
34    };
35    like( $@, qr#^Unknown encoding#, 'parse: '.$@ );
36}
37# ----------------------------------------------------------------
38sub test2 {
39    my $tree = { root => { elem => 'value' }};
40    my $tpp = XML::TreePP->new();
41
42    local $@;
43    eval {
44        my $xml = $tpp->write( $tree, $ENC );
45    };
46    like( $@, qr#^Unknown encoding#, 'write: '.$@ );
47}
48# ----------------------------------------------------------------
49sub test3 {
50    my $tree = { root => { elem => 'value' }};
51    my $tpp = XML::TreePP->new( output_encoding => $ENC );
52
53    local $@;
54    eval {
55        my $xml = $tpp->write( $tree );
56    };
57    like( $@, qr#^Unknown encoding#, 'output_encoding: '.$@ );
58}
59# ----------------------------------------------------------------
60;1;
61# ----------------------------------------------------------------