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