Mercurial > pub > Impl
comparison _test/Test/DOM/Navigator.pm @ 24:7f00786f8210
Первая рабочая реазизация схемы и навигаторов
author | Sergey |
---|---|
date | Mon, 05 Oct 2009 00:48:49 +0400 |
parents | 75980091813b |
children | 1828103371d0 |
comparison
equal
deleted
inserted
replaced
23:716b287d4795 | 24:7f00786f8210 |
---|---|
3 | 3 |
4 __PACKAGE__->PassThroughArgs; | 4 __PACKAGE__->PassThroughArgs; |
5 | 5 |
6 use IMPL::Test qw(test failed); | 6 use IMPL::Test qw(test failed); |
7 use IMPL::DOM::Navigator; | 7 use IMPL::DOM::Navigator; |
8 use IMPL::DOM::Navigator::SchemaNavigator; | |
8 use IMPL::DOM::Node; | 9 use IMPL::DOM::Node; |
10 use IMPL::DOM::Schema; | |
11 use IMPL::Class::Property; | |
12 | |
13 BEGIN { | |
14 public property doc => prop_all; | |
15 } | |
16 | |
17 sub CTOR { | |
18 my ($this) = @_; | |
19 | |
20 $this->doc( | |
21 IMPL::DOM::Node->new(nodeName => 'root')->appendRange( | |
22 IMPL::DOM::Node->new(nodeName=> 'age', nodeValue => 21), | |
23 IMPL::DOM::Node->new(nodeName=> 'address')->appendRange( | |
24 IMPL::DOM::Node->new(nodeName=>'city', nodeValue=>'moscow'), | |
25 IMPL::DOM::Node->new(nodeName=>'street', nodeValue=>'main'), | |
26 IMPL::DOM::Node->new(nodeName=>'phone',nodeValue=>'123-456'), | |
27 ), | |
28 IMPL::DOM::Node->new(nodeName=> 'address')->appendRange( | |
29 IMPL::DOM::Node->new(nodeName=>'city', nodeValue=>'San Francisco'), | |
30 IMPL::DOM::Node->new(nodeName=>'street', nodeValue=>'Libertador'), | |
31 ), | |
32 IMPL::DOM::Node->new(nodeName=> 'contacts')->appendRange( | |
33 IMPL::DOM::Node->new(nodeName=>'phone',nodeValue=>'123-123'), | |
34 IMPL::DOM::Node->new(nodeName=>'phone',nodeValue=>'1-233-434-34-54'), | |
35 IMPL::DOM::Node->new(nodeName=>'email',nodeValue=>'some@mail.none') | |
36 ) | |
37 | |
38 ) | |
39 ); | |
40 } | |
9 | 41 |
10 test Creation => sub { | 42 test Creation => sub { |
11 my ($this) = @_; | 43 my ($this) = @_; |
12 | 44 |
13 my $doc = new IMPL::DOM::Node(nodeName => 'root'); | 45 my $doc = new IMPL::DOM::Node(nodeName => 'root'); |
62 failed ("Back() retuned unexpected result", "Recieved: $navresult", "Expected: $doc") if $doc != $navresult; | 94 failed ("Back() retuned unexpected result", "Recieved: $navresult", "Expected: $doc") if $doc != $navresult; |
63 my $curr = $navi->Current; | 95 my $curr = $navi->Current; |
64 failed ("Current node has a wrong value","Current: $curr","Expected: $doc") if $doc != $curr; | 96 failed ("Current node has a wrong value","Current: $curr","Expected: $doc") if $doc != $curr; |
65 }; | 97 }; |
66 | 98 |
99 test selectNodes1 => sub { | |
100 my ($this) = @_; | |
101 | |
102 my $navi = new IMPL::DOM::Navigator($this->doc); | |
103 my @result = $navi->selectNodes('contacts','phone'); | |
104 failed "Expected to get two entries, but got:",map($_->nodeName,@result) unless @result == 2; | |
105 }; | |
67 | 106 |
107 test selectNodes2 => sub { | |
108 my ($this) = @_; | |
109 | |
110 my $navi = new IMPL::DOM::Navigator($this->doc); | |
111 my @result = $navi->selectNodes(undef,'phone'); | |
112 failed "Expected to get three entries, but got:",map($_->nodeName,@result) unless @result == 3; | |
113 }; | |
68 | 114 |
115 test FetchDoeachState => sub { | |
116 my ($this) = @_; | |
117 | |
118 my $navi = new IMPL::DOM::Navigator($this->doc); | |
119 | |
120 $navi->Navigate(undef,'phone'); | |
121 | |
122 $navi->saveState(); | |
123 | |
124 my @result; | |
125 doeach $navi sub { | |
126 push @result,$_; | |
127 }; | |
128 | |
129 failed "Expected to get three nodes, but got: ", map($_->nodeName,@result) unless @result == 3; | |
130 | |
131 $navi->restoreState(); | |
132 @result = (); | |
133 | |
134 push @result, $_ while fetch $navi; | |
135 | |
136 failed "Expected to get three nodes, but got: ", map($_->nodeName,@result) unless @result == 3; | |
137 }; | |
138 | |
139 test NavigateSchema => sub { | |
140 my $navi = new IMPL::DOM::Navigator::SchemaNavigator(IMPL::DOM::Schema->MetaSchema); | |
141 | |
142 my $root = $navi->NavigateName('schema') or failed "Failed to navigate to the root element"; | |
143 | |
144 $navi->saveState; | |
145 $navi->NavigateName('Node') or failed "Failed to navigate to a simple node"; | |
146 $navi->restoreState; | |
147 | |
148 failed "Can't navigate from simple node" if $navi->NavigateName('Property'); | |
149 | |
150 $navi->NavigateName('ComplexType') or failed "Failed to navigate to a complex node"; | |
151 $navi->NavigateName('NodeSet') or failed "Failed to navigate to NodeSet"; | |
152 $navi->SchemaBack(); | |
153 $navi->NavigateName('NodeList') or failed "Failed to navigate to NodeList"; | |
154 $navi->NavigateName('SimpleNode') or failed "Failed to navigate to SimpleNode"; | |
155 $navi->NavigateName('Enum') or failed "Failed to navigate to Enum"; | |
156 $navi->NavigateName('Item') or failed "Failed to navigate to Item"; | |
157 | |
158 }; | |
69 | 159 |
70 | 160 |
71 1; | 161 1; |