/[suikacvs]/messaging/manakai/t/DOM-Node.t
Suika

Contents of /messaging/manakai/t/DOM-Node.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download) (as text)
Fri Jun 15 14:32:50 2007 UTC (17 years, 5 months ago) by wakaba
Branch: MAIN
File MIME type: application/x-troff
++ manakai/t/ChangeLog	15 Jun 2007 14:31:27 -0000
2007-06-15  Wakaba  <wakaba@suika.fam.cx>

	* DOM-Node.t: New test.

2007-06-15  Wakaba  <wakaba@suika.fam.cx>

	* DOM-Document.t: New test.

++ manakai/lib/Message/DOM/ChangeLog	15 Jun 2007 14:32:37 -0000
2007-06-15  Wakaba  <wakaba@suika.fam.cx>

	* ProcessingInstruction.pm, EntityReference.pm,
	CDATASection, DocumentFragment.pm, DOMDocument.pm, Entity.pm,
	ElementTypeDefinition.pm, AttributeDefinition.pm,
	DocumentType.pm, DOMElement.pm, Attr.pm,
	CharacterData.pm, Text.pm, Comment.pm (node_name,
	node_value, node_type): Implemented.

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3     use Test;
4     BEGIN { plan tests => 4 }
5    
6     require Message::DOM::DOMImplementation;
7    
8     my $dom = Message::DOM::DOMImplementation->____new;
9     my $doc = $dom->create_document;
10    
11     ## Constants
12     my $constants = [
13     [ELEMENT_NODE => 1],
14     [ATTRIBUTE_NODE => 2],
15     [TEXT_NODE => 3],
16     [CDATA_SECTION_NODE => 4],
17     [ENTITY_REFERENCE_NODE => 5],
18     [ENTITY_NODE => 6],
19     [PROCESSING_INSTRUCTION_NODE => 7],
20     [COMMENT_NODE => 8],
21     [DOCUMENT_NODE => 9],
22     [DOCUMENT_TYPE_NODE => 10],
23     [DOCUMENT_FRAGMENT_NODE => 11],
24     [NOTATION_NODE => 12],
25     [ELEMENT_TYPE_DEFINITION_NODE => 81001],
26     [ATTRIBUTE_DEFINITION_NODE => 81002],
27     ];
28    
29     my $tests = {
30     attr => {
31     node => sub {
32     my $attr = $doc->create_attribute ('a');
33     $attr->value ('b');
34     return $attr;
35     },
36     attr_get => {
37     node_name => 'a',
38     name => 'a',
39     node_value => 'b',
40     value => 'b',
41     attributes => undef,
42     },
43     },
44     attr_ns_default => {
45     node => sub {
46     my $attr = $doc->create_attribute_ns (undef, 'a');
47     $attr->value ('b');
48     return $attr;
49     },
50     attr_get => {
51     node_name => 'a',
52     name => 'a',
53     node_value => 'b',
54     value => 'b',
55     attributes => undef,
56     },
57     },
58     attr_ns_prefixed => {
59     node => sub {
60     my $attr = $doc->create_attribute_ns ('http://test/', 'a:b');
61     $attr->value ('c');
62     return $attr;
63     },
64     attr_get => {
65     node_name => 'a:b',
66     name => 'a:b',
67     node_value => 'c',
68     value => 'c',
69     attributes => undef,
70     },
71     },
72     cdatasection => {
73     node => sub { return $doc->create_cdata_section ('cdatadata') },
74     attr_get => {
75     node_name => '#cdata-section',
76     node_value => 'cdatadata',
77     data => 'cdatadata',
78     attributes => undef,
79     },
80     },
81     cdatasectionmde => {
82     node => sub { return $doc->create_cdata_section ('cdata]]>data') },
83     attr_get => {
84     node_name => '#cdata-section',
85     node_value => 'cdata]]>data',
86     data => 'cdata]]>data',
87     attributes => undef,
88     },
89     },
90     comment => {
91     node => sub { return $doc->create_comment ('commentdata') },
92     attr_get => {
93     node_name => '#comment',
94     node_value => 'commentdata',
95     data => 'commentdata',
96     attributes => undef,
97     },
98     },
99     commentcom1 => {
100     node => sub { return $doc->create_comment ('comment--data') },
101     attr_get => {
102     node_name => '#comment',
103     node_value => 'comment--data',
104     data => 'comment--data',
105     attributes => undef,
106     },
107     },
108     commentcom2 => {
109     node => sub { return $doc->create_comment ('commentdata-') },
110     attr_get => {
111     node_name => '#comment',
112     node_value => 'commentdata-',
113     data => 'commentdata-',
114     attributes => undef,
115     },
116     },
117     document => {
118     node => sub { return $doc },
119     attr_get => {
120     attributes => undef,
121     local_name => undef,
122     namespace_uri => undef,
123     node_name => '#document',
124     node_value => undef,
125     parent_node => undef,
126     prefix => undef,
127     },
128     },
129     document_fragment => {
130     node => sub { return $doc->create_document_fragment },
131     attr_get => {
132     attributes => undef,
133     node_name => '#document-fragment',
134     node_value => undef,
135     },
136     },
137     document_type => {
138     node => sub { return $doc->implementation->create_document_type ('n') },
139     attr_get => {
140     attributes => undef,
141     node_name => 'n',
142     node_value => undef,
143     },
144     },
145     document_type_definition => {
146     node => sub { return $doc->create_document_type_definition ('n') },
147     attr_get => {
148     attributes => undef,
149     node_name => 'n',
150     node_value => undef,
151     },
152     },
153     element => {
154     node => sub { return $doc->create_element ('e') },
155     attr_get => {
156     ## TODO: attributes =>
157     node_name => 'e',
158     node_value => undef,
159     },
160     },
161     element_ns_default => {
162     node => sub { return $doc->create_element_ns ('http://test/', 'f') },
163     attr_get => {
164     ## TODO: attributes =>
165     node_name => 'f',
166     node_value => undef,
167     },
168     },
169     element_ns_prefiexed => {
170     node => sub { return $doc->create_element_ns ('http://test/', 'e:f') },
171     attr_get => {
172     ## TODO: attributes =>
173     node_name => 'e:f',
174     node_value => undef,
175     },
176     },
177     entity => {
178     node => sub { return $doc->create_general_entity ('e') },
179     attr_get => {
180     attributes => undef,
181     node_name => 'e',
182     node_value => undef,
183     },
184     },
185     entity_reference => {
186     node => sub { return $doc->create_entity_reference ('e') },
187     attr_get => {
188     attributes => undef,
189     node_name => 'e',
190     node_value => undef,
191     },
192     },
193     notation => {
194     node => sub { return $doc->create_notation ('e') },
195     attr_get => {
196     attributes => undef,
197     node_name => 'e',
198     node_value => undef,
199     },
200     },
201     processing_instruction => {
202     node => sub { return $doc->create_processing_instruction ('t', 'd') },
203     attr_get => {
204     attributes => undef,
205     node_name => 't',
206     node_value => 'd',
207     },
208     },
209     text => {
210     node => sub { return $doc->create_text_node ('textdata') },
211     attr_get => {
212     attributes => undef,
213     node_name => '#text',
214     node_value => 'textdata',
215     },
216     },
217     element_type_definition => {
218     node => sub { return $doc->create_element_type_definition ('e') },
219     attr_get => {
220     attributes => undef,
221     node_name => 'e',
222     node_value => undef,
223     },
224     },
225     attribute_definition => {
226     node => sub { return $doc->create_attribute_definition ('e') },
227     attr_get => {
228     attributes => undef,
229     node_name => 'e',
230     node_value => undef,
231     },
232     },
233     };
234    
235     for my $test_id (sort {$a cmp $b} keys %$tests) {
236     my $test_def = $tests->{$test_id};
237     my $node = $test_def->{node}->();
238    
239     for (@$constants) {
240     my $const_name = $_->[0];
241     ok $node->can ($const_name) ? 1 : 0, 1, "$test_id->can ($const_name)";
242     ok $node->$const_name, $_->[1], "$test_id.$const_name";
243     }
244    
245     for my $attr_name (sort {$a cmp $b} keys %{$test_def->{attr_get}}) {
246     my $expected = $test_def->{attr_get}->{$attr_name};
247     ok $node->can ($attr_name) ? 1 : 0, 1, "$test_id->can ($attr_name)";
248     my $actual = $node->$attr_name;
249     ok $actual, $expected, "$test_id.$attr_name.get";
250     }
251     }
252    
253     ## License: Public Domain.
254     ## $Date: 2007/06/13 12:04:51 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24