File: 48_rt55000.t

package info (click to toggle)
libxml-libxml-perl 2.0207%2Bdfsg%2Breally%2B2.0134-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,572 kB
  • sloc: perl: 6,310; ansic: 3,851; xml: 182; sh: 21; makefile: 16
file content (60 lines) | stat: -rw-r--r-- 1,385 bytes parent folder | download | duplicates (7)
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

use strict;
use warnings;

=head1 DESCRIPTION

If an element contains both a default namespace declaration and a second
namespace declaration, adding an attribute using the default namespace
declaration will cause that attribute to have the other prefix.

OS Version: FreeBSD 6.3-RELEASE
Perl Version: v5.8.8
LibXML Version: 1.70

See L<https://rt.cpan.org/Ticket/Display.html?id=55000> .

=cut

use Test::More tests => 6;

use XML::LibXML;

my $xml_string = <<'XML';
<?xml version="1.0" encoding="UTF-8"?>
<element xmlns="uri"
xmlns:wrong="other">
</element>
XML

my $parser = XML::LibXML->new;
my $doc = $parser->parse_string($xml_string);
my $root = $doc->documentElement();
$root->setAttributeNS("uri", "prefix:attribute", "text");
$root->setAttributeNS("uri", "second", "text");

my $string = $doc->toString(1);

# TEST
unlike ($string, qr/[^\w:]attribute="text"/,
    "Not placed as an unprefixed attribute");
# TEST
unlike ($string, qr/\bwrong:attribute="text"/,
    "Not placed in the wrong namespace");

# TEST
like ($string, qr/\bprefix:attribute="text"/,
    "Placed in the right namespace");

# TEST
unlike ($string, qr/[^\w:]second="text"/,
    "Not placed as an unprefixed attribute");

# TEST
unlike ($string, qr/\bwrong:second="text"/,
    "Not placed in the wrong namespace");

# TEST
like ($string, qr/\bprefix:second="text"/,
    "Placed in the right namespace");