/[suikacvs]/messaging/manakai/t/markup-xml-qname.t
Suika

Diff of /messaging/manakai/t/markup-xml-qname.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by wakaba, Sun Sep 28 01:05:04 2003 UTC revision 1.3 by wakaba, Fri Oct 31 08:39:27 2003 UTC
# Line 6  use Message::Markup::XML::QName qw/UNDEF Line 6  use Message::Markup::XML::QName qw/UNDEF
6  sub ok ($;$);  sub ok ($;$);
7  my $e = new Message::Markup::XML (type => '#element', local_name => 'test',  my $e = new Message::Markup::XML (type => '#element', local_name => 'test',
8                                    namespace_uri => 'http://something.test/');                                    namespace_uri => 'http://something.test/');
9    use Carp q(verbose);
10  my @reg_p2n = (  my @reg_p2n = (
11                 {                 {
12                  prefix => q(test1),                  prefix => q(test1),
# Line 196  my @qname = ( Line 196  my @qname = (
196               },               },
197               {               {
198                qname  => q":bar",                qname  => q":bar",
199                  join_qname => q"bar",
200                prefix => q"",                prefix => q"",
201                lname  => q"bar",                lname  => q"bar",
202                result => 0,                result => 0,
203                  join_result => 1,
204                opt    => {check_qname => 1, check_prefix => 1,                opt    => {check_qname => 1, check_prefix => 1,
205                           check_local_name => 1},                           check_local_name => 1},
206               },               },
# Line 351  Test::Simple->import (tests => scalar (@ Line 353  Test::Simple->import (tests => scalar (@
353                               + scalar (@qname) * 2                               + scalar (@qname) * 2
354                               + scalar (@gen_pfx) * 2                               + scalar (@gen_pfx) * 2
355                               + scalar (@expand) * 2);                               + scalar (@expand) * 2);
356    eval q{
357    sub ok ($;$) {
358      my ($cond, $desc) = @_;
359      if ($cond) {
360        Test::Simple::ok (1);
361      } else {
362        Test::Simple::ok (0, $desc);
363      }
364    }};
365    
366  for (@reg_p2n) {  for (@reg_p2n) {
367    my $chk = Message::Markup::XML::QName::register_prefix_to_name    my $chk = Message::Markup::XML::QName::register_prefix_to_name
368      ($e, $_->{prefix} => $_->{name}, %{$_->{opt}||{}});      ($e, $_->{prefix} => $_->{name}, %{$_->{opt}||{}});
369    ok ($chk->{success} == $_->{result}, $chk->{reason});    ok ($chk->{success} == $_->{result}, 'Register pfx->URI: '.$chk->{reason});
370  }  }
371                                
372  for (@get_p2n) {  for (@get_p2n) {
# Line 382  for (@qname) { Line 393  for (@qname) {
393    if ($_->{result}) {    if ($_->{result}) {
394      ok $chk->{prefix}.':'.($chk->{local_name_star} ? '*' : $chk->{local_name})      ok $chk->{prefix}.':'.($chk->{local_name_star} ? '*' : $chk->{local_name})
395      eq $_->{prefix} . ':' . $_->{lname},      eq $_->{prefix} . ':' . $_->{lname},
396        "$chk->{prefix}:$chk->{local_name}($chk->{local_name_star})";        "Split 1: $_->{qname} => $chk->{prefix}:$chk->{local_name}($chk->{local_name_star})";
397    } else {    } else {
398      ok $chk->{success} == $_->{result},      ok $chk->{success} == $_->{result},
399        "$chk->{prefix}:$chk->{local_name}($chk->{local_name_star})";        "Split 0: $_->{qname} => $chk->{prefix}:$chk->{local_name}($chk->{local_name_star})";
400    }    }
401        
402    $chk = Message::Markup::XML::QName::join_qname    $chk = Message::Markup::XML::QName::join_qname
403      ($_->{prefix}, $_->{lname}, %{$_->{opt}||{}});      ($_->{prefix}, $_->{lname}, %{$_->{opt}||{}});
404    if ($_->{result}) {    if ((defined $_->{join_result} and $_->{join_result}) or $_->{result}) {
405      ok $chk->{qname} eq $_->{qname}, $chk->{qname};      ok $chk->{qname} eq ($_->{join_qname} || $_->{qname}), "Join 1: $_->{prefix}, $_->{lname} => $chk->{qname}";
406    } else {    } else {
407      ok $chk->{success} == $_->{result}, $chk->{qname};      ok $chk->{success} == ((defined $_->{join_result} and $_->{join_result}) or $_->{result}),
408           "Join 0: $chk->{success}; $_->{prefix}, $_->{lname} => $chk->{qname}";
409    }    }
410  }  }
411    
# Line 404  for (@gen_pfx) { Line 416  for (@gen_pfx) {
416    if ($pfx eq $_->{prefix}) {    if ($pfx eq $_->{prefix}) {
417      my $chk = Message::Markup::XML::QName::register_prefix_to_name      my $chk = Message::Markup::XML::QName::register_prefix_to_name
418                  ($e, $pfx => $_->{name});                  ($e, $pfx => $_->{name});
419      ok $chk->{success}, $chk->{reason};      ok $chk->{success}, 'Generate pfx: '.$chk->{reason};
420    } else {    } else {
421      ok $pfx eq $_->{prefix}, ":$pfx: (expected :$_->{prefix}:";      ok $pfx eq $_->{prefix}, "Generate pfx: :$pfx: (expected :$_->{prefix}:";
422    }    }
423  }  }
424    
# Line 416  for (@gen_pfx) { Line 428  for (@gen_pfx) {
428                                                           %{$_->{opt}||{}},                                                           %{$_->{opt}||{}},
429                                                           make_new_prefix => 1);                                                           make_new_prefix => 1);
430    ok $chk->{success} && ($chk->{prefix} eq ($_->{n2p} || $_->{prefix})),    ok $chk->{success} && ($chk->{prefix} eq ($_->{n2p} || $_->{prefix})),
431       "$chk->{prefix} (@{[$_->{n2p} || $_->{prefix}]} is expected; $chk->{reason})";       "URI->Pfx: $chk->{prefix} (@{[$_->{n2p} || $_->{prefix}]} is expected; $chk->{reason})";
432  }  }
433    
434  for (@expand) {  for (@expand) {
# Line 429  for (@expand) { Line 441  for (@expand) {
441                ($e, $_->{qname}, %{$_->{opt}||{}});                ($e, $_->{qname}, %{$_->{opt}||{}});
442    ok $chk->{success} && ($_->{xname}->[0] eq $chk->{name}    ok $chk->{success} && ($_->{xname}->[0] eq $chk->{name}
443                       && $_->{xname}->[1] eq $chk->{local_name}),                       && $_->{xname}->[1] eq $chk->{local_name}),
444       qq(<$chk->{name}> (should be <$_->{xname}->[0]>), "$chk->{local_name}" (should be "$_->{xname}->[1]") (prefix "$chk->{prefix}"; $chk->{reason}));       qq(QName->expand: <$chk->{name}> (should be <$_->{xname}->[0]>), "$chk->{local_name}" (should be "$_->{xname}->[1]") (prefix "$chk->{prefix}"; $chk->{reason}));
445  }  }
446    
447  for (@expand) {  for (@expand) {
# Line 440  for (@expand) { Line 452  for (@expand) {
452    }    }
453    my $chk = Message::Markup::XML::QName::expanded_name_to_qname    my $chk = Message::Markup::XML::QName::expanded_name_to_qname
454                ($e, $_->{xname}->[0], $_->{xname}->[1], %{$_->{opt}||{}});                ($e, $_->{xname}->[0], $_->{xname}->[1], %{$_->{opt}||{}});
455    ok $chk->{success} && ($_->{qname} eq $chk->{qname}), $chk->{reason};    ok $chk->{success} && ($_->{qname} eq $chk->{qname}), 'Expand->QName: '.$chk->{reason};
456  }  }
457    
458  print $e;  print $e;

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24