~ubuntu-branches/ubuntu/vivid/libxml-bare-perl/vivid

« back to all changes in this revision

Viewing changes to t/UTF8_Values.t

  • Committer: Bazaar Package Importer
  • Author(s): Ryan Niebur, Jonathan Yu, Ryan Niebur, Nathan Handler
  • Date: 2009-08-12 09:42:24 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090812094224-bo487a59xgom7d8l
Tags: 0.45-1
[ Jonathan Yu ]
* New upstream release
  + UTF-8 handling fixed
  + Self-closing nodes are now printed by the XML function
* Added myself to Uploaders and Copyright
* Use new debhelper 7 short rules format
* Standards-Version 3.8.2 (no changes)
* Rewrote control description
* New upstream release
  + Prevent XML corruption during XML saving
  + Fix strange compilation problems by removing line number defines

[ Ryan Niebur ]
* add debian/clean
* Add myself to Uploaders

[ Nathan Handler ]
* debian/watch: Update to ignore development releases.

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::Harness;
 
12
$Test::Harness::verbose=1;
 
13
use Test::More qw(no_plan);
 
14
 
 
15
 
 
16
use_ok('XML::Bare');
 
17
 
 
18
my $data = {
 
19
    hash   => "#",
 
20
    oo     => "\x{f6}",
 
21
    iso_a  => "\x{c4}",
 
22
    iso_oo => "\x{d6}",
 
23
    aa     => "\x{e4}",
 
24
    euro   => "\x{20ac}",
 
25
};
 
26
 
 
27
# build XML string with UTF8 values
 
28
my $xmldata = "<data>\n";
 
29
foreach ( keys %{$data} ) {
 
30
    $xmldata .= "  <$_>";
 
31
    $xmldata .= $data->{$_};
 
32
    $xmldata .= "</$_>\n";
 
33
}
 
34
$xmldata .= "</data>\n";
 
35
 
 
36
# parse the provided XML
 
37
my $obj = new XML::Bare( text => $xmldata );
 
38
my $root = $obj->parse;
 
39
 
 
40
# convert back to XML from parse
 
41
use Data::Dumper;
 
42
my $roundtrip = $obj->xml($root);
 
43
 
 
44
## this isn't valid as order/spacing not preserved
 
45
is( $roundtrip, $xmldata, 'Round trip XML identical' );
 
46
 
 
47
while ( my ( $name, $char ) = each %{$data} ) {
 
48
    my $str = $root->{data}{$name}{value};
 
49
    ok( utf8::is_utf8($str), "Character $name is correct encoding" )
 
50
      if ( utf8::is_utf8($char) );
 
51
    ok( utf8::valid($str), "Character $name is Valid" );
 
52
    ok( ( length($str) == 1 ), "String returned for $name is 1 char long" );
 
53
 
 
54
    is( $str, $char, "Character $name OK" );
 
55
}
 
 
b'\\ No newline at end of file'