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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download) (as text)
Sun Jul 8 11:28:45 2007 UTC (17 years, 4 months ago) by wakaba
Branch: MAIN
CVS Tags: manakai-release-0-4-0, HEAD
File MIME type: application/x-troff
++ manakai/t/ChangeLog	8 Jul 2007 11:28:41 -0000
	* DOM-CharacterData.t, DOM-Text.t: New test scripts.

2007-07-08  Wakaba  <wakaba@suika.fam.cx>

++ manakai/lib/Message/DOM/ChangeLog	8 Jul 2007 11:28:19 -0000
	* DOMCharacterData.pm (AUTOLOAD): Removed.
	(data): Reimplemented.
	(delete_data, insert_data, replace_data, substring_data): There were
	a number of bugs.

	* Text.pm (AUTOLOAD): Removed.  Unused.

2007-07-08  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3     use Test;
4     BEGIN { plan tests => 121 }
5    
6     require Message::DOM::DOMImplementation;
7     use Message::Util::Error;
8    
9     my $dom = Message::DOM::DOMImplementation->____new;
10     my $doc = $dom->create_document;
11    
12     for my $node (
13     $doc->create_text_node ('initial value'),
14     $doc->create_comment ('initial value'),
15     $doc->create_cdata_section ('initial value'),
16     ) {
17     ok $node->node_value, 'initial value', $node->node_name . '->node_value get';
18     ok $node->text_content, 'initial value', $node->node_name . '->tc get';
19     ok $node->data, 'initial value', $node->node_name . '->data get';
20    
21     $node->manakai_set_read_only (0);
22    
23     $node->node_value ('value1');
24    
25     ok $node->node_value, 'value1', $node->node_name . '->node_value nv.set';
26     ok $node->text_content, 'value1', $node->node_name . '->text_content nv.set';
27     ok $node->data, 'value1', $node->node_name . '->data nv.set';
28    
29     $node->node_value ('');
30    
31     ok $node->node_value, '', $node->node_name . '->node_value nv.empty';
32     ok $node->text_content, '', $node->node_name . '->text_content nv.empty';
33     ok $node->data, '', $node->node_name . '->data nv.empty';
34    
35     $node->text_content ('value3');
36    
37     ok $node->node_value, 'value3', $node->node_name . '->node_value tc.set';
38     ok $node->text_content, 'value3', $node->node_name . '->text_content tc.set';
39     ok $node->data, 'value3', $node->node_name . '->data tc.set';
40    
41     $node->text_content ('');
42    
43     ok $node->node_value, '', $node->node_name . '->node_value tc.empty';
44     ok $node->text_content, '', $node->node_name . '->text_content tc.empty';
45     ok $node->data, '', $node->node_name . '->data tc.empty';
46    
47     $node->text_content ('value4');
48     $node->text_content (undef);
49    
50     ok $node->node_value, '', $node->node_name . '->node_value tc.undef';
51     ok $node->text_content, '', $node->node_name . '->text_content tc.undef';
52     ok $node->data, '', $node->node_name . '->data tc.undef';
53    
54     $node->data ('value2');
55    
56     ok $node->node_value, 'value2', $node->node_name . '->node_value d.set';
57     ok $node->text_content, 'value2', $node->node_name . '->text_content d.set';
58     ok $node->data, 'value2', $node->node_name . '->data d.set';
59    
60     $node->data ('');
61    
62     ok $node->node_value, '', $node->node_name . '->node_value d.empty';
63     ok $node->text_content, '', $node->node_name . '->text_content d.empty';
64     ok $node->data, '', $node->node_name . '->data d.empty';
65    
66     $node->manakai_set_read_only (1);
67    
68     try {
69     $node->node_value ('value1');
70     } catch Message::DOM::DOMException with {
71     ok shift->type, 'NO_MODIFICATION_ALLOWED_ERR', $node->node_name . '->nv.ro';
72     };
73    
74     try {
75     $node->text_content ('value1');
76     } catch Message::DOM::DOMException with {
77     ok shift->type, 'NO_MODIFICATION_ALLOWED_ERR', $node->node_name . '->tc.ro';
78     };
79    
80     try {
81     $node->data ('value1');
82     } catch Message::DOM::DOMException with {
83     ok shift->type, 'NO_MODIFICATION_ALLOWED_ERR', $node->node_name . '->d.ro';
84     };
85     }
86    
87     ## |length|
88     {
89     my $text = $doc->create_text_node ('');
90     for my $testdata (
91     # id, data, length
92     ['empty', '', 0],
93     ['small.a', 'a', 1],
94     ['han.4e00', "\x{4E00}", 1],
95     ['a-z', 'abcdefghijklmnopqrstuvwxyz', 26],
96     ['U+10000', "\x{10000}", 2],
97     ['aU+10000', "a\x{10000}", 3],
98     ['U+10000U+11111', "\x{10000}\x{11111}", 4],
99     ) {
100     $text->data ($testdata->[1]);
101     ok $text->length, $testdata->[2], $testdata->[0] . '->length';
102     }
103    
104     $text->data ('');
105     ok $text->substring_data (0, 0), '', "substring_data [1]";
106     ok $text->substring_data (0, 1), '', "substring_data [2]";
107    
108     $text->data ('abcdefg');
109     ok $text->substring_data (0, 0), '', "substring_data [1]";
110     ok $text->substring_data (0, 1), 'a', "substring_data [2]";
111     ok $text->substring_data (5, 1), 'f', "substring_data [3]";
112     ok $text->substring_data (5, 2), 'fg', "substring_data [4]";
113    
114     $text->data ('');
115     $text->append_data ('');
116     ok $text->data, '', "append_data [1]";
117    
118     $text->append_data ('a');
119     ok $text->data, 'a', "append_data [2]";
120    
121     $text->append_data ('abc');
122     ok $text->data, 'aabc', "append_data [3]";
123    
124     $text->data ('');
125    
126     try {
127     $text->insert_data (1, 'abc');
128     } catch Message::DOM::DOMException with {
129     ok shift->type, 'INDEX_SIZE_ERR', 'insert_data [1]';
130     };
131    
132     try {
133     $text->insert_data (-1, 'abc');
134     } catch Message::DOM::DOMException with {
135     ok shift->type, 'INDEX_SIZE_ERR', 'insert_data [2]';
136     };
137    
138     $text->insert_data (0, 'abc');
139     ok $text->data, 'abc', 'insert_data [3]';
140    
141     $text->insert_data (3, 'abc');
142     ok $text->data, 'abcabc', 'insert_data [4]';
143    
144     $text->insert_data (1, 'abc');
145     ok $text->data, 'aabcbcabc', 'insert_data [5]';
146    
147     $text->data ('');
148    
149     $text->insert_data (0, "\x{10000}");
150     ok $text->data, "\x{10000}", "insert_data [6]";
151    
152     $text->insert_data (2, "\x{10001}");
153     ok $text->data, "\x{10000}\x{10001}", "insert_data [7]";
154    
155     $text->insert_data (2, 'a');
156     ok $text->data, "\x{10000}a\x{10001}", "insert_data [8]";
157    
158     $text->data ('');
159    
160     $text->delete_data (0, 0);
161     ok $text->data, '', 'delete_data [1]';
162    
163     $text->delete_data (0, 10);
164     ok $text->data, '', 'delete_data [2]';
165    
166     try {
167     $text->delete_data (-1, 0);
168     } catch Message::DOM::DOMException with {
169     ok shift->type, 'INDEX_SIZE_ERR', 'delete_data [3]';
170     };
171    
172     try {
173     $text->delete_data (1, 0);
174     } catch Message::DOM::DOMException with {
175     ok shift->type, 'INDEX_SIZE_ERR', 'delete_data [4]';
176     };
177    
178     try {
179     $text->delete_data (0, -10);
180     } catch Message::DOM::DOMException with {
181     ok shift->type, 'INDEX_SIZE_ERR', 'delete_data [5]';
182     };
183    
184     $text->append_data ('abcdefg');
185    
186     $text->delete_data (0, 0);
187     ok $text->data, 'abcdefg', 'delete_data [6]';
188    
189     $text->delete_data (0, 2);
190     ok $text->data, 'cdefg', 'delete_data [7]';
191    
192     try {
193     $text->delete_data (-1, 0);
194     } catch Message::DOM::DOMException with {
195     ok shift->type, 'INDEX_SIZE_ERR', 'delete_data [8]';
196     };
197    
198     try {
199     $text->delete_data (20, 0);
200     } catch Message::DOM::DOMException with {
201     ok shift->type, 'INDEX_SIZE_ERR', 'delete_data [9]';
202     };
203    
204     try {
205     $text->delete_data (0, -10);
206     } catch Message::DOM::DOMException with {
207     ok shift->type, 'INDEX_SIZE_ERR', 'delete_data [10]';
208     };
209    
210     $text->delete_data (2, 12);
211     ok $text->data, 'cd', 'delete_data [11]';
212    
213     $text->delete_data (0, 2);
214     ok $text->data, '', 'delete_data [12]';
215    
216     $text->data ("ab\x{10000}cdefg");
217    
218     $text->delete_data (0, 4);
219     ok $text->data, 'cdefg', 'delete_data [13]';
220    
221     $text->data ("ab\x{10000}cdefg");
222    
223     $text->delete_data (4, 2);
224     ok $text->data, "ab\x{10000}efg", 'delete_data [14]';
225    
226     $text->data ('abcdefg');
227     $text->replace_data (0, 2, 'ABCD');
228     ok $text->data, 'ABCDcdefg', 'replace_data [1]';
229    
230     $text->replace_data (3, 32, "\x{3000}\x{4E00}");
231     ok $text->data, "ABC\x{3000}\x{4E00}", 'replace_data [2]';
232     }
233    
234     =head1 LICENSE
235    
236     Copyright 2007 Wakaba <w@suika.fam.cx>
237    
238     This program is free software; you can redistribute it and/or
239     modify it under the same terms as Perl itself.
240    
241     =cut
242    
243     ## $Date: 2007/06/17 13:37:42 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24