218 |
opt => {check_qname => 1, check_prefix => 1, |
opt => {check_qname => 1, check_prefix => 1, |
219 |
check_local_name => 1, use_local_name_star => 1}, |
check_local_name => 1, use_local_name_star => 1}, |
220 |
}, |
}, |
221 |
|
{ |
222 |
|
qname => q"foo|bar", |
223 |
|
prefix => q:foo:, |
224 |
|
lname => q:bar:, |
225 |
|
result => 1, |
226 |
|
opt => {check_qname => 1, check_prefix => 1, |
227 |
|
check_local_name => 1, qname_separator => '|'}, |
228 |
|
}, |
229 |
|
{ |
230 |
|
qname => q"foo|*", |
231 |
|
prefix => q:foo:, |
232 |
|
lname => q:*:, |
233 |
|
result => 1, |
234 |
|
opt => {check_qname => 1, check_prefix => 1, |
235 |
|
check_local_name => 1, qname_separator => '|', |
236 |
|
use_local_name_star => 1}, |
237 |
|
}, |
238 |
|
); |
239 |
|
|
240 |
|
my @gen_pfx = ( |
241 |
|
{ |
242 |
|
reset => 1, |
243 |
|
name => q<http://www.w3.org/1999/xhtml>, |
244 |
|
prefix => DEFAULT_PFX, |
245 |
|
opt => {use_prefix_default => 1}, |
246 |
|
}, |
247 |
|
{ |
248 |
|
reset => 0, |
249 |
|
name => q<http://www.w3.org/1999/xhtml>, |
250 |
|
prefix => q:h:, |
251 |
|
n2p => DEFAULT_PFX, |
252 |
|
opt => {use_prefix_default => 1}, |
253 |
|
}, |
254 |
|
{ |
255 |
|
reset => 1, |
256 |
|
name => q<http://www.w3.org/1999/xhtml>, |
257 |
|
prefix => q:h:, |
258 |
|
opt => {use_prefix_default => 0}, |
259 |
|
}, |
260 |
|
{ |
261 |
|
name => q<http://www.w3.org/1999/xhtml>, |
262 |
|
prefix => q:h1:, |
263 |
|
n2p => q:h:, |
264 |
|
}, |
265 |
|
{ |
266 |
|
name => q<http://www.w3.org/1999/xhtml>, |
267 |
|
prefix => q:xhtml:, |
268 |
|
n2p => q:h:, |
269 |
|
}, |
270 |
|
{ |
271 |
|
name => q<http://www.w3.org/1999/xhtml>, |
272 |
|
prefix => q:xhtml1:, |
273 |
|
n2p => q:h:, |
274 |
|
}, |
275 |
|
{ |
276 |
|
name => q<http://www.w3.org/1999/xhtml>, |
277 |
|
prefix => q:www.w3.org:, |
278 |
|
n2p => q:h:, |
279 |
|
}, |
280 |
|
{ |
281 |
|
name => q<http://www.w3.org/1999/xhtml>, |
282 |
|
prefix => q:http:, |
283 |
|
n2p => q:h:, |
284 |
|
}, |
285 |
|
{ |
286 |
|
name => q<http://www.w3.org/1999/xhtml>, |
287 |
|
prefix => q:ns0:, |
288 |
|
n2p => q:h:, |
289 |
|
}, |
290 |
|
{ |
291 |
|
name => q<http://www.w3.org/1999/xhtml>, |
292 |
|
prefix => q:ns1:, |
293 |
|
n2p => q:h:, |
294 |
|
}, |
295 |
|
{ |
296 |
|
name => q<test/0name/xmlns>, |
297 |
|
prefix => q:name:, |
298 |
|
}, |
299 |
|
{ |
300 |
|
name => q<test/0name/xmlns>, |
301 |
|
prefix => q:test:, |
302 |
|
n2p => q:name:, |
303 |
|
}, |
304 |
|
{ |
305 |
|
reset => 1, |
306 |
|
name => q<:///:04465612@&>, |
307 |
|
prefix => q:ns0:, |
308 |
|
}, |
309 |
|
{ |
310 |
|
reset => 1, |
311 |
|
name => NULL_URI, |
312 |
|
prefix => DEFAULT_PFX, |
313 |
|
opt => {use_prefix_default => 1}, |
314 |
|
}, |
315 |
|
{ |
316 |
|
reset => 0, |
317 |
|
name => NULL_URI, |
318 |
|
prefix => DEFAULT_PFX, |
319 |
|
opt => {use_prefix_default => 1}, |
320 |
|
}, |
321 |
|
{ |
322 |
|
reset => 1, |
323 |
|
name => NULL_URI, |
324 |
|
prefix => DEFAULT_PFX, |
325 |
|
opt => {use_prefix_default => 0}, |
326 |
|
}, |
327 |
|
); |
328 |
|
|
329 |
|
my @expand = ( |
330 |
|
{ |
331 |
|
reset => 1, |
332 |
|
ns => {foo => q<http://foo.test/>}, |
333 |
|
qname => q"foo:bar", |
334 |
|
xname => [q<http://foo.test/> => q:bar:], |
335 |
|
}, |
336 |
|
{ |
337 |
|
reset => 0, |
338 |
|
qname => q"foo:bar", |
339 |
|
xname => [q<http://foo.test/> => q:bar:], |
340 |
|
}, |
341 |
|
{ |
342 |
|
reset => 0, |
343 |
|
qname => q"bar", |
344 |
|
xname => [NULL_URI, q:bar:], |
345 |
|
opt => {use_prefix_default => 1, use_name_null => 1}, |
346 |
|
}, |
347 |
); |
); |
348 |
|
|
349 |
Test::Simple->import (tests => scalar (@reg_p2n) |
Test::Simple->import (tests => scalar (@reg_p2n) |
350 |
+ scalar (@get_p2n) * 2 |
+ scalar (@get_p2n) * 2 |
351 |
+ scalar (@qname) * 2); |
+ scalar (@qname) * 2 |
352 |
|
+ scalar (@gen_pfx) * 2 |
353 |
|
+ scalar (@expand) * 2); |
354 |
|
|
355 |
for (@reg_p2n) { |
for (@reg_p2n) { |
356 |
my $chk = Message::Markup::XML::QName::register_prefix_to_name |
my $chk = Message::Markup::XML::QName::register_prefix_to_name |
397 |
} |
} |
398 |
} |
} |
399 |
|
|
400 |
|
for (@gen_pfx) { |
401 |
|
$e->{ns} = {} if $_->{reset}; |
402 |
|
my $pfx = Message::Markup::XML::QName::generate_prefix ($e, $_->{name}, |
403 |
|
%{$_->{opt}||{}}); |
404 |
|
if ($pfx eq $_->{prefix}) { |
405 |
|
my $chk = Message::Markup::XML::QName::register_prefix_to_name |
406 |
|
($e, $pfx => $_->{name}); |
407 |
|
ok $chk->{success}, $chk->{reason}; |
408 |
|
} else { |
409 |
|
ok $pfx eq $_->{prefix}, ":$pfx: (expected :$_->{prefix}:"; |
410 |
|
} |
411 |
|
} |
412 |
|
|
413 |
|
for (@gen_pfx) { |
414 |
|
$e->{ns} = {} if $_->{reset}; |
415 |
|
my $chk = Message::Markup::XML::QName::name_to_prefix ($e, $_->{name}, |
416 |
|
%{$_->{opt}||{}}, |
417 |
|
make_new_prefix => 1); |
418 |
|
ok $chk->{success} && ($chk->{prefix} eq ($_->{n2p} || $_->{prefix})), |
419 |
|
"$chk->{prefix} (@{[$_->{n2p} || $_->{prefix}]} is expected; $chk->{reason})"; |
420 |
|
} |
421 |
|
|
422 |
|
for (@expand) { |
423 |
|
$e->{ns} = {} if $_->{reset}; |
424 |
|
for my $pfx (keys %{$_->{ns}||{}}) { |
425 |
|
Message::Markup::XML::QName::register_prefix_to_name |
426 |
|
($e, $pfx => $_->{ns}->{$pfx}, %{$_->{opt}||{}}); |
427 |
|
} |
428 |
|
my $chk = Message::Markup::XML::QName::qname_to_expanded_name |
429 |
|
($e, $_->{qname}, %{$_->{opt}||{}}); |
430 |
|
ok $chk->{success} && ($_->{xname}->[0] eq $chk->{name} |
431 |
|
&& $_->{xname}->[1] eq $chk->{local_name}), |
432 |
|
qq(<$chk->{name}> (should be <$_->{xname}->[0]>), "$chk->{local_name}" (should be "$_->{xname}->[1]") (prefix "$chk->{prefix}"; $chk->{reason})); |
433 |
|
} |
434 |
|
|
435 |
|
for (@expand) { |
436 |
|
$e->{ns} = {} if $_->{reset}; |
437 |
|
for my $pfx (keys %{$_->{ns}||{}}) { |
438 |
|
Message::Markup::XML::QName::register_prefix_to_name |
439 |
|
($e, $pfx => $_->{ns}->{$pfx}, %{$_->{opt}||{}}); |
440 |
|
} |
441 |
|
my $chk = Message::Markup::XML::QName::expanded_name_to_qname |
442 |
|
($e, $_->{xname}->[0], $_->{xname}->[1], %{$_->{opt}||{}}); |
443 |
|
ok $chk->{success} && ($_->{qname} eq $chk->{qname}), $chk->{reason}; |
444 |
|
} |
445 |
|
|
446 |
print $e; |
print $e; |