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

Contents of /messaging/manakai/t/markup-xml-xpath.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download) (as text)
Fri Oct 31 04:51:56 2003 UTC (21 years ago) by wakaba
Branch: MAIN
File MIME type: application/x-troff
New tests

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3     require Test::Simple; sub ok ($;$);
4     use Message::Markup::XML::XPath;
5     use Message::Markup::XML;
6    
7     my $e = Message::Markup::XML->new (type => '#element',
8     namespace_uri => q<http://e.test/>,
9     local_name => 'e');
10    
11     my $XPath = q"Message::Markup::XML::XPath";
12    
13     my @s = (
14     {
15     g => sub {
16     my $x = $XPath->new (type => '#expression');
17     $x->append_new_node (type => '#path')
18     ->append_new_node
19     (type => '#step',
20     axis => 'ancestor',
21     namespace_uri => q<http://xpath.test/>,
22     local_name => '*');
23    
24     ok $x->stringify eq q<ancestor::xpath.test:*>;
25     },
26     },
27     {
28     g => sub {
29     my $p = $XPath->new (type => '#path');
30     $p->append_new_node (type => '#step', axis => '::root');
31     my $s = $p->append_new_node
32     (type => '#step',
33     axis => 'child',
34     namespace_uri => q<http://xpath.test/>,
35     local_name => 'bar');
36     $p->append_new_node
37     (type => '#step',
38     axis => 'child',
39     namespace_uri => q<http://e.test/>,
40     local_name => 'ba');
41     my $predict = $s->append_new_predict (type => '#expression');
42     $predict->option (operator => '=');
43     $predict->append_new_node (type => '#step', axis => 'attribute',
44     local_name => 'attr');
45     $predict->append_new_node (type => '#literal', value => 'foo');
46    
47     my $xpr = q</child::xpath.test:bar[attribute::attr = 'foo']/child::e.test:ba>;
48     my $expr = $p->stringify;
49     ok $expr eq $xpr, $expr;
50    
51     $e->{ns} = {};
52     $e->define_new_namespace ('' => q<http://e.test/>);
53     $e->set_attribute (expr => $p);
54     my $el = $e . '';
55     ok $el eq qq<<e expr="$xpr" xmlns="http://e.test/" xmlns:xpath.test="http://xpath.test/"></e>>, $el;
56     },1,
57     },
58     );
59    
60    
61    
62     =pod
63    
64     $p->append_new_node (type => '#literal', value => q<don't>);
65     $p->append_new_node (type => '#literal', value => q<you said "hello!">);
66    
67    
68     $p->append_new_node (type => '#literal', value => q<you said "don't worry">);
69     $p->append_new_node (type => '#expression')
70     ->append_new_node (type => '#step', namespace_uri => 'ftp://test.example');
71     $p->append_new_node (type => '#number');
72     $p->append_new_node (type => '#number', value => '-0');
73     $p->append_new_node (type => '#number', value => 3.1415);
74     my $f = $p->append_new_node (type => '#function', local_name => 'current',
75     namespace_uri => q<urn:x-suika-fam-cx:markup:xslt:>);
76     $f->append_new_node (type => '#number', value => '.124');
77     $f->append_new_node (type => '#expression')
78     ->append_new_node (type => '#step', local_name => 'foo');
79    
80     $f->option (is_context_function_library => {q<urn:x-suika-fam-cx:markup:xslt:> => 1, q<urn:x-suika-fam-cx:markup:xpath:> => 1});
81    
82     $p->append_new_node (type => '#function', namespace_uri => q<urn:x-suika-fam-cx:markup:xpath:>, local_name => 'node');
83    
84     $f->append_new_node (type => '#function', namespace_uri => q<urn:x-suika-fam-cx:markup:xpath:>, local_name => 'lang');
85    
86     my $exp2 = $x->append_new_node (type => '#expression');
87     $exp2->option (operator => '|');
88     $exp2->append_new_node (type => '#step', local_name => 'n1');
89     $exp2->append_new_node (type => '#step', local_name => 'n2');
90    
91     my $attr = $e->set_attribute (expression => $x);
92    
93     $x->stringify;
94    
95     print $e;
96    
97     =cut
98    
99    
100     Test::Simple->import (tests => scalar @s);
101    
102    
103     for (@s) {
104     &{$_->{g}};
105     }

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24