File: 71overloads.t

package info (click to toggle)
libxml-libxml-perl 2.0116%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,420 kB
  • sloc: perl: 6,139; ansic: 3,752; xml: 182; sh: 64; makefile: 8
file content (217 lines) | stat: -rw-r--r-- 3,731 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
use strict;
use warnings;
use Test::More tests => 25;
use XML::LibXML;

my $root = XML::LibXML->load_xml( IO => \*DATA )->documentElement;

# TEST
ok(
    tied %$root,
    'elements can be hash dereffed to a tied hash',
    );

# TEST
isa_ok(
    tied %$root,
    'XML::LibXML::AttributeHash',
    'tied %$element',
    );

# TEST
ok(
    exists $root->{'attr1'},
    'EXISTS non-namespaced',
    );

# TEST
is(
    $root->{'attr1'},
    'foo',
    'FETCH non-namespaced',
    );

$root->{attr1} = 'bar';
# TEST
is(
    $root->getAttribute('attr1'),
    'bar',
    'STORE non-namespaced',
    );

$root->{attr11} = 'baz';
# TEST
is(
    $root->getAttribute('attr11'),
    'baz',
    'STORE (and create) non-namespaced',
    );

delete $root->{attr11};
# TEST
ok(
    !$root->hasAttribute('attr11'),
    'DELETE non-namespaced',
    );

my $fail = 1;
while (my ($k, $v) = each %$root)
{
    if ($k eq 'attr1')
    {
        $fail = 0;
        # TEST
        pass('FIRSTKEY/NEXTKEY non-namespaced');
    }
}

if ($fail)
{
    fail('FIRSTKEY/NEXTKEY non-namespaced');
}

# TEST
ok(
    exists $root->{'{http://localhost/}attr2'},
    'EXISTS namespaced',
    );

# TEST
is(
    $root->{'{http://localhost/}attr2'},
    'bar',
    'FETCH namespaced',
    );

$root->{'{http://localhost/}attr2'} = 'quux';
# TEST
is(
    $root->getAttributeNS('http://localhost/', 'attr2'),
    'quux',
    'STORE namespaced',
    );

$root->{'{http://localhost/}attr22'} = 'quuux';
# TEST
is(
    $root->getAttributeNS('http://localhost/', 'attr22'),
    'quuux',
    'STORE (and create) namespaced',
    );

$root->{'{http://localhost/another}attr22'} = 'xyzzy';
# TEST
is(
    $root->getAttributeNS('http://localhost/another', 'attr22'),
    'xyzzy',
    'STORE (and create) namespaced, in new namespace',
    );

delete $root->{'{http://localhost/another}attr22'};
# TEST
ok(
    !$root->hasAttributeNS('http://localhost/another', 'attr22'),
    'DELETE namespaced',
    );

my $fail2 = 1;
while (my ($k, $v) = each %$root)
{
    if ($k eq '{http://localhost/}attr22')
    {
        $fail2 = 0;
        # TEST
        pass('FIRSTKEY/NEXTKEY namespaced');
    }
}

if ($fail2)
{
    fail('FIRSTKEY/NEXTKEY namespaced');
}

# TEST
like(
    $root->toStringEC14N,
    qr{<root xmlns:x="http://localhost/" attr1="bar" x:attr2="quux" x:attr22="quuux"></root>},
    '!!! toStringEC14N',
    );

# These are tests for:
# https://rt.cpan.org/Ticket/Display.html?id=75257
# https://rt.cpan.org/Ticket/Display.html?id=75293
# https://rt.cpan.org/Ticket/Display.html?id=75259
# (Three duplicate reports for the same problem.)

# TEST
is_deeply(
    [($root == $root)],
    [1],
    '== comparison',
);

# TEST
is_deeply(
    [($root eq $root)],
    [1],
    'eq comparison',
);

# TEST
is_deeply(
    [($root == 'not-root')],
    [''],
    '== negative comparison',
);

# TEST
is_deeply(
    [($root == 'not-root')],
    [''],
    '== negative comparison',
);

# TEST
is_deeply(
    [!($root != 'not-root')],
    [''],
    '!== negative comparison',
);

# TEST
is_deeply(
    [($root eq 'not-root')],
    [''],
    'eq negative comparison',
);

# TEST
is_deeply(
    [!($root ne 'not-root')],
    [''],
    'eq negative comparison',
);

{
    my $doc = XML::LibXML->load_xml( string => <<'EOT' )->documentElement;
<foo>
    <bar />
    <baz />
</foo>
EOT

    my ($bar_elem) = $doc->findnodes('//bar');
    my ($baz_elem) = $doc->findnodes('//baz');

    # TEST
    is_deeply([$bar_elem == $baz_elem], [''],
        '== comparison between two differenet nodes'
    );

    # TEST
    is_deeply([$bar_elem eq $baz_elem], [''],
        'eq comparison between two differenet nodes'
    );
}
__DATA__
<root attr1="foo" xmlns:x="http://localhost/" x:attr2="bar" />