~ubuntu-branches/ubuntu/utopic/libxml-bare-perl/utopic-proposed

« back to all changes in this revision

Viewing changes to t/UTF8_Attributes.t

  • Committer: Package Import Robot
  • Author(s): Nuno Carvalho, gregor herrmann, Salvatore Bonaccorso, Axel Beckert, Nuno Carvalho
  • Date: 2013-09-17 15:54:28 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130917155428-4d0xb5cissw2323f
Tags: 0.53-1
* Team upload.

[ gregor herrmann ]
* debian/control: update {versioned,alternative} (build) dependencies.

[ Salvatore Bonaccorso ]
* Change Vcs-Git to canonical URI (git://anonscm.debian.org)
* Change search.cpan.org based URIs to metacpan.org based URIs

[ Axel Beckert ]
* debian/copyright: migrate pre-1.0 format to 1.0 using "cme fix dpkg-
  copyright"

[ Nuno Carvalho ]
* New upstream release.
* debian/copyright: update copyright years.
* debian/control: update standards version.
* debian/control: update debhelper required version, in order to pass all
  the hardening flags to EUMM.
* Add lintian override to apparently false-positive warning.
* Add set of patches accepted upstream but still not included in this
  release, visit https://rt.cpan.org/Public/Bug/Display.html?id=88155
  for details.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl -w
2
 
 
3
 
use strict;
4
 
use warnings;
5
 
 
6
 
# NB we have use utf8 here, but the source should be 7bit clean
7
 
# however I need the utf8::is_utf8 and utf8::valid names which
8
 
# are no longer exposed without the use line.
9
 
use utf8;
10
 
 
11
 
use Test::More;
12
 
 
13
 
use_ok('XML::Bare');
14
 
 
15
 
my $data = {
16
 
    hash   => "#",
17
 
    oo     => "\x{f6}",
18
 
    iso_a  => "\x{c4}",
19
 
    iso_oo => "\x{d6}",
20
 
    aa     => "\x{e4}",
21
 
    euro   => "\x{20ac}",
22
 
};
23
 
 
24
 
# build XML string with UTF8 values
25
 
my $xmldata = "<data>\n";
26
 
foreach ( keys %{$data} ) {
27
 
    $xmldata .= "  <$_ char=\"" . $data->{$_} . "\" />\n";
28
 
}
29
 
$xmldata .= "</data>\n";
30
 
 
31
 
# parse the provided XML
32
 
my $obj = new XML::Bare( text => $xmldata );
33
 
my $root = $obj->parse;
34
 
 
35
 
# convert back to XML from parse
36
 
my $roundtrip = $obj->xml($root);
37
 
 
38
 
## this isn't valid as order/spacing not preserved
39
 
is( $roundtrip, $xmldata, 'Round trip XML identical' );
40
 
 
41
 
while ( my ( $name, $char ) = each %{$data} ) {
42
 
    my $str = $root->{data}{$name}{char}{value};
43
 
    ok( $root->{data}{$name}{char}{_att}, "$name has char attribute" );
44
 
    ok( utf8::is_utf8($str), "Character $name is correct encoding" )
45
 
      if ( utf8::is_utf8($char) );
46
 
    ok( utf8::valid($str), "Character $name is Valid" );
47
 
    ok( ( length($str) == 1 ), "String returned for $name is 1 char long" );
48
 
 
49
 
    is( $str, $char, "Character $name OK" );
50
 
}
51
 
 
52
 
 
53
 
done_testing;
 
1
#!/usr/bin/perl -w
 
2
 
 
3
use strict;
 
4
use warnings;
 
5
 
 
6
# NB we have use utf8 here, but the source should be 7bit clean
 
7
# however I need the utf8::is_utf8 and utf8::valid names which
 
8
# are no longer exposed without the use line.
 
9
use utf8;
 
10
 
 
11
use Test::More qw(no_plan);
 
12
 
 
13
use_ok('XML::Bare');
 
14
 
 
15
my $data = {
 
16
    hash   => "#",
 
17
    oo     => "\x{f6}",
 
18
    iso_a  => "\x{c4}",
 
19
    iso_oo => "\x{d6}",
 
20
    aa     => "\x{e4}",
 
21
    euro   => "\x{20ac}",
 
22
};
 
23
 
 
24
# build XML string with UTF8 values
 
25
my $xmldata = "<data>\n";
 
26
foreach ( keys %{$data} ) {
 
27
    $xmldata .= "  <$_ char=\"" . $data->{$_} . "\" />\n";
 
28
}
 
29
$xmldata .= "</data>\n";
 
30
 
 
31
# parse the provided XML
 
32
my $obj = new XML::Bare( text => $xmldata );
 
33
my $root = $obj->parse;
 
34
 
 
35
# convert back to XML from parse
 
36
my $roundtrip = $obj->xml($root);
 
37
 
 
38
## this isn't valid as order/spacing not preserved
 
39
is( $roundtrip, $xmldata, 'Round trip XML identical' );
 
40
 
 
41
while ( my ( $name, $char ) = each %{$data} ) {
 
42
    my $str = $root->{data}{$name}{char}{value};
 
43
    ok( $root->{data}{$name}{char}{_att}, "$name has char attribute" );
 
44
    ok( utf8::is_utf8($str), "Character $name is correct encoding" )
 
45
      if ( utf8::is_utf8($char) );
 
46
    ok( utf8::valid($str), "Character $name is Valid" );
 
47
    ok( ( length($str) == 1 ), "String returned for $name is 1 char long" );
 
48
 
 
49
    is( $str, $char, "Character $name OK" );
 
50
}
 
 
b'\\ No newline at end of file'