File: test_non_ascii.t

package info (click to toggle)
libxml-dom-xpath-perl 0.14-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 240 kB
  • sloc: perl: 449; makefile: 2; xml: 1
file content (43 lines) | stat: -rw-r--r-- 1,852 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl -w
use strict;

# $Id: test_non_ascii.t,v 1.2 2005/10/18 08:37:22 mrodrigu Exp $


use Test::More tests => 10;
use XML::DOM::XPath;

use utf8;

my $display_warning=0;

{ 
  my $dom = XML::DOM::Parser->new();
  my $doc = $dom->parsefile( "t/non_ascii.xml");
  if( !$doc->toString eq "<doc><ent>aü</ent><char>bü</char></doc>\n") { $display_warning=1; }
  is( $doc->toString, "<doc><ent>aü</ent><char>bü</char></doc>\n",'toString (on file)');
  is( $doc->findvalue( '//char'), "bü", "findvalue( '//char') (on file)");
  is( $doc->findnodes_as_string( '//char'), '<char>bü</char>', "findnodes_as_string( '//char') (on file)");
  is( $doc->findvalue( '//ent'), 'aü', "findvalue( '//ent') (on file)");
  is( $doc->findnodes_as_string( '//ent'), '<ent>aü</ent>', "findnodes_as_string( '//ent') (on file)");
}


{ 
  my $xmlStr = q{<doc><ent>a&#252;</ent><char>bü</char></doc>};
  my $dom = XML::DOM::Parser->new();
  my $doc = $dom->parse($xmlStr);
  is( $doc->toString, qq{<doc><ent>aü</ent><char>bü</char></doc>\n},'toString (on string)');
  is( $doc->findvalue( '//char'), 'bü', "findvalue( '//char') (on string)");
  is( $doc->findnodes_as_string( '//char'), qq{<char>bü</char>}, "findnodes_as_string( '//char') (on string)");
  is( $doc->findvalue( '//ent'), qq{aü}, "findvalue( '//ent') (on string)");
  is( $doc->findnodes_as_string( '//ent'), qq{<ent>aü</ent>}, "findnodes_as_string( '//ent') (on string)");
}

if( $display_warning)
  { warn "One possible reason why this test might fail is if XML::Parser and XML::DOM were\n",
         "installed with a different version of perl, compiled with a different set of options.\n",
         "For example upgrading Ubuntu from Dapper Drake to Edgy Eft will cause this test to fail.\n",
         "Re-installing XML::Parser and XML::DOM will fix the problem.\n"
         ;
  }