1 /* -*- Mode: java; tab-width:8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is JavaScript Engine testing utilities.
18 * The Initial Developer of the Original Code is
20 * Portions created by the Initial Developer are Copyright (C) 2007
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s): Igor Bukanov
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
40 var BUGNUMBER = 376773;
41 var summary = 'xmlsimple.stringmethod === xmlsimple.function::stringmethod';
47 printBugNumber(BUGNUMBER);
51 var xml = <a>TEXT</a>;
53 // --------------------------------------------------------------
55 String.prototype.orig_toString = String.prototype.toString;
56 String.prototype.toString = function() {
57 actualcall = 'String.prototype.toString called';
58 return this.orig_toString();
62 expectcall = 'String.prototype.toString not called';
64 actualcall = expectcall;
65 actual = xml.toString();
66 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
68 actualcall = expectcall;
69 actual = xml.function::toString();
70 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
72 actualcall = expectcall;
73 actual = xml.function::toString.call(xml);
74 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
76 String.prototype.toString = String.prototype.orig_toString;
77 delete String.prototype.orig_toString;
79 // --------------------------------------------------------------
81 String.prototype.orig_toSource = String.prototype.toSource;
82 String.prototype.toSource = function() {
83 actualcall = 'String.prototype.toSource called';
84 return this.orig_toSource();
87 expect = '<a>TEXT</a>';
88 expectcall = 'String.prototype.toSource not called';
90 actualcall = expectcall;
91 actual = xml.toSource();
92 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
94 actualcall = expectcall;
95 actual = xml.function::toSource();
96 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
98 actualcall = expectcall;
99 actual = xml.function::toSource.call(xml);
100 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
102 String.prototype.toSource = String.prototype.orig_toSource;
103 delete String.prototype.orig_toSource;
105 // --------------------------------------------------------------
107 String.prototype.orig_valueOf = String.prototype.valueOf;
108 String.prototype.valueOf = function() {
109 actualcall = 'String.prototype.valueOf called';
110 return this.orig_valueOf();
114 expectcall = 'String.prototype.valueOf not called';
116 actualcall = expectcall;
117 actual = xml.valueOf();
118 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
120 actualcall = expectcall;
121 actual = xml.function::valueOf();
122 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
124 actualcall = expectcall;
125 actual = xml.function::valueOf.call(xml);
126 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
128 String.prototype.valueOf = String.prototype.orig_valueOf;
129 delete String.prototype.orig_valueOf;
131 // --------------------------------------------------------------
133 String.prototype.orig_charAt = String.prototype.charAt;
134 String.prototype.charAt = function(pos) {
135 actualcall = 'String.prototype.charAt called';
136 return this.orig_charAt(pos);
140 expectcall = 'String.prototype.charAt called';
142 actualcall = expectcall.replace(/called/, 'not called');
143 actual = xml.charAt(0);
144 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
146 actualcall = expectcall.replace(/called/, 'not called');
147 actual = xml.function::charAt(0);
148 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
150 actualcall = expectcall.replace(/called/, 'not called');
151 actual = xml.function::charAt.call(xml, 0);
152 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
154 String.prototype.charAt = String.prototype.orig_charAt;
155 delete String.prototype.orig_charAt;
157 // --------------------------------------------------------------
159 String.prototype.orig_charCodeAt = String.prototype.charCodeAt;
160 String.prototype.charCodeAt = function(pos) {
161 actualcall = 'String.prototype.charCodeAt called';
162 return this.orig_charCodeAt(pos);
166 expectcall = 'String.prototype.charCodeAt called';
168 actualcall = expectcall.replace(/called/, 'not called');
169 actual = xml.charCodeAt(0);
170 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
172 actualcall = expectcall.replace(/called/, 'not called');
173 actual = xml.function::charCodeAt(0);
174 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
176 actualcall = expectcall.replace(/called/, 'not called');
177 actual = xml.function::charCodeAt.call(xml, 0);
178 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
180 String.prototype.charCodeAt = String.prototype.orig_charCodeAt;
181 delete String.prototype.orig_charCodeAt;
183 // --------------------------------------------------------------
185 String.prototype.orig_concat = String.prototype.concat;
186 String.prototype.concat = function(string1) {
187 actualcall = 'String.prototype.concat called';
188 return this.orig_concat(string1);
192 expectcall = 'String.prototype.concat called';
194 actualcall = expectcall.replace(/called/, 'not called');
195 actual = xml.concat(<b>text</b>);
196 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
198 actualcall = expectcall.replace(/called/, 'not called');
199 actual = xml.function::concat(<b>text</b>);
200 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
202 actualcall = expectcall.replace(/called/, 'not called');
203 actual = xml.function::concat.call(xml, <b>text</b>);
204 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
206 String.prototype.concat = String.prototype.orig_concat;
207 delete String.prototype.orig_concat;
209 // --------------------------------------------------------------
211 String.prototype.orig_indexOf = String.prototype.indexOf;
212 String.prototype.indexOf = function(searchString, position) {
213 actualcall = 'String.prototype.indexOf called';
214 return this.orig_indexOf(searchString, position);
218 expectcall = 'String.prototype.indexOf called';
220 actualcall = expectcall.replace(/called/, 'not called');
221 actual = xml.indexOf('T');
222 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
224 actualcall = expectcall.replace(/called/, 'not called');
225 actual = xml.function::indexOf('T');
226 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
228 actualcall = expectcall.replace(/called/, 'not called');
229 actual = xml.function::indexOf.call(xml, 'T');
230 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
232 String.prototype.indexOf = String.prototype.orig_indexOf;
233 delete String.prototype.orig_indexOf;
235 // --------------------------------------------------------------
237 String.prototype.orig_lastIndexOf = String.prototype.lastIndexOf;
238 String.prototype.lastIndexOf = function(searchString, position) {
239 actualcall = 'String.prototype.lastIndexOf called';
240 return this.orig_lastIndexOf(searchString, position);
244 expectcall = 'String.prototype.lastIndexOf called';
246 actualcall = expectcall.replace(/called/, 'not called');
247 actual = xml.lastIndexOf('T');
248 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
250 actualcall = expectcall.replace(/called/, 'not called');
251 actual = xml.function::lastIndexOf('T');
252 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
254 actualcall = expectcall.replace(/called/, 'not called');
255 actual = xml.function::lastIndexOf.call(xml, 'T');
256 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
258 String.prototype.lastIndexOf = String.prototype.orig_lastIndexOf;
259 delete String.prototype.orig_lastIndexOf;
261 // --------------------------------------------------------------
263 String.prototype.orig_localeCompare = String.prototype.localeCompare;
264 String.prototype.localeCompare = function(that) {
265 actualcall = 'String.prototype.localeCompare called';
266 return this.orig_localeCompare(that);
270 expectcall = 'String.prototype.localeCompare called';
272 actualcall = expectcall.replace(/called/, 'not called');
273 actual = xml.localeCompare(xml);
274 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
276 actualcall = expectcall.replace(/called/, 'not called');
277 actual = xml.function::localeCompare(xml);
278 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
280 actualcall = expectcall.replace(/called/, 'not called');
281 actual = xml.function::localeCompare.call(xml, xml);
282 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
284 String.prototype.localeCompare = String.prototype.orig_localeCompare;
285 delete String.prototype.orig_localeCompare;
287 // --------------------------------------------------------------
289 String.prototype.orig_match = String.prototype.match;
290 String.prototype.match = function(regexp) {
291 actualcall = 'String.prototype.match called';
292 return this.orig_match(regexp);
296 expectcall = 'String.prototype.match called';
298 actualcall = expectcall.replace(/called/, 'not called');
299 actual = xml.match(/TEXT/);
300 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
302 actualcall = expectcall.replace(/called/, 'not called');
303 actual = xml.function::match(/TEXT/);
304 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
306 actualcall = expectcall.replace(/called/, 'not called');
307 actual = xml.function::match.call(xml, /TEXT/);
308 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
310 String.prototype.match = String.prototype.orig_match;
311 delete String.prototype.orig_match;
313 // --------------------------------------------------------------
315 String.prototype.orig_replace = String.prototype.replace;
316 String.prototype.replace = function(searchValue, replaceValue) {
317 actualcall = 'String.prototype.replace called';
318 return this.orig_replace(searchValue, replaceValue);
322 expectcall = 'String.prototype.replace not called';
324 actualcall = expectcall;
325 actual = xml.replace(/EXT/, 'ext');
326 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
328 actualcall = expectcall;
329 actual = xml.function::replace(/EXT/, 'ext');
330 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
332 actualcall = expectcall;
333 actual = xml.function::replace.call(xml, /EXT/, 'ext');
334 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
336 String.prototype.replace = String.prototype.orig_replace;
337 delete String.prototype.orig_replace;
339 // --------------------------------------------------------------
341 String.prototype.orig_search = String.prototype.search;
342 String.prototype.search = function(regexp) {
343 actualcall = 'String.prototype.search called';
344 return this.orig_search(regexp);
348 expectcall = 'String.prototype.search called';
350 actualcall = expectcall.replace(/called/, 'not called');
351 actual = xml.search(/TEXT/);
352 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
354 actualcall = expectcall.search(/called/, 'not called');
355 actual = xml.function::search(/TEXT/);
356 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
358 actualcall = expectcall.search(/called/, 'not called');
359 actual = xml.function::search.call(xml, /TEXT/);
360 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
362 String.prototype.search = String.prototype.orig_search;
363 delete String.prototype.orig_search;
365 // --------------------------------------------------------------
367 String.prototype.orig_slice = String.prototype.slice;
368 String.prototype.slice = function(start, end) {
369 actualcall = 'String.prototype.slice called';
370 return this.orig_slice(start, end);
374 expectcall = 'String.prototype.slice called';
376 actualcall = expectcall.replace(/called/, 'not called');
377 actual = xml.slice(1,1);
378 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
380 actualcall = expectcall.slice(/called/, 'not called');
381 actual = xml.function::slice(1,1);
382 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
384 actualcall = expectcall.slice(/called/, 'not called');
385 actual = xml.function::slice.call(xml, 1,1);
386 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
388 String.prototype.slice = String.prototype.orig_slice;
389 delete String.prototype.orig_slice;
391 // --------------------------------------------------------------
393 String.prototype.orig_split = String.prototype.split;
394 String.prototype.split = function(separator, limit) {
395 actualcall = 'String.prototype.split called';
396 return this.orig_split(separator, limit);
399 expect = ['T', 'E', 'X', 'T'];
400 expectcall = 'String.prototype.split called';
402 actualcall = expectcall.replace(/called/, 'not called');
403 actual = xml.split('');
404 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
406 actualcall = expectcall.split(/called/, 'not called');
407 actual = xml.function::split('');
408 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
410 actualcall = expectcall.split(/called/, 'not called');
411 actual = xml.function::split.call(xml, '');
412 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
414 String.prototype.split = String.prototype.orig_split;
415 delete String.prototype.orig_split;
417 // --------------------------------------------------------------
419 String.prototype.orig_substr = String.prototype.substr;
420 String.prototype.substr = function(start, length) {
421 actualcall = 'String.prototype.substr called';
422 return this.orig_substr(start, length);
426 expectcall = 'String.prototype.substr called';
428 actualcall = expectcall.replace(/called/, 'not called');
429 actual = xml.substr(1,1);
430 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
432 actualcall = expectcall.substr(/called/, 'not called');
433 actual = xml.function::substr(1,1);
434 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
436 actualcall = expectcall.substr(/called/, 'not called');
437 actual = xml.function::substr.call(xml, 1,1);
438 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
440 String.prototype.substr = String.prototype.orig_substr;
441 delete String.prototype.orig_substr;
443 // --------------------------------------------------------------
445 String.prototype.orig_substring = String.prototype.substring;
446 String.prototype.substring = function(start, end) {
447 actualcall = 'String.prototype.substring called';
448 return this.orig_substring(start, end);
452 expectcall = 'String.prototype.substring called';
454 actualcall = expectcall.replace(/called/, 'not called');
455 actual = xml.substring(1,1);
456 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
458 actualcall = expectcall.substring(/called/, 'not called');
459 actual = xml.function::substring(1,1);
460 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
462 actualcall = expectcall.substring(/called/, 'not called');
463 actual = xml.function::substring.call(xml, 1,1);
464 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
466 String.prototype.substring = String.prototype.orig_substring;
467 delete String.prototype.orig_substring;
469 // --------------------------------------------------------------
471 String.prototype.orig_toLowerCase = String.prototype.toLowerCase;
472 String.prototype.toLowerCase = function() {
473 actualcall = 'String.prototype.toLowerCase called';
474 return this.orig_toLowerCase();
478 expectcall = 'String.prototype.toLowerCase called';
480 actualcall = expectcall.replace(/called/, 'not called');
481 actual = xml.toLowerCase();
482 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
484 actualcall = expectcall.toLowerCase(/called/, 'not called');
485 actual = xml.function::toLowerCase();
486 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
488 actualcall = expectcall.toLowerCase(/called/, 'not called');
489 actual = xml.function::toLowerCase.call(xml);
490 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
492 String.prototype.toLowerCase = String.prototype.orig_toLowerCase;
493 delete String.prototype.orig_toLowerCase;
495 // --------------------------------------------------------------
497 String.prototype.orig_toLocaleLowerCase = String.prototype.toLocaleLowerCase;
498 String.prototype.toLocaleLowerCase = function() {
499 actualcall = 'String.prototype.toLocaleLowerCase called';
500 return this.orig_toLocaleLowerCase();
504 expectcall = 'String.prototype.toLocaleLowerCase called';
506 actualcall = expectcall.replace(/called/, 'not called');
507 actual = xml.toLocaleLowerCase();
508 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
510 actualcall = expectcall.toLocaleLowerCase(/called/, 'not called');
511 actual = xml.function::toLocaleLowerCase();
512 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
514 actualcall = expectcall.toLocaleLowerCase(/called/, 'not called');
515 actual = xml.function::toLocaleLowerCase.call(xml);
516 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
518 String.prototype.toLocaleLowerCase = String.prototype.orig_toLocaleLowerCase;
519 delete String.prototype.orig_toLocaleLowerCase;
521 // --------------------------------------------------------------
523 String.prototype.orig_toUpperCase = String.prototype.toUpperCase;
524 String.prototype.toUpperCase = function() {
525 actualcall = 'String.prototype.toUpperCase called';
526 return this.orig_toUpperCase();
530 expectcall = 'String.prototype.toUpperCase called';
532 actualcall = expectcall.replace(/called/, 'not called');
533 actual = xml.toUpperCase();
534 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
536 actualcall = expectcall.toUpperCase(/called/, 'not called');
537 actual = xml.function::toUpperCase();
538 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
540 actualcall = expectcall.toUpperCase(/called/, 'not called');
541 actual = xml.function::toUpperCase.call(xml);
542 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
544 String.prototype.toUpperCase = String.prototype.orig_toUpperCase;
545 delete String.prototype.orig_toUpperCase;
547 // --------------------------------------------------------------
549 String.prototype.orig_toLocaleUpperCase = String.prototype.toLocaleUpperCase;
550 String.prototype.toLocaleUpperCase = function() {
551 actualcall = 'String.prototype.toLocaleUpperCase called';
552 return this.orig_toLocaleUpperCase();
556 expectcall = 'String.prototype.toLocaleUpperCase called';
558 actualcall = expectcall.replace(/called/, 'not called');
559 actual = xml.toLocaleUpperCase();
560 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
562 actualcall = expectcall.toLocaleUpperCase(/called/, 'not called');
563 actual = xml.function::toLocaleUpperCase();
564 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
566 actualcall = expectcall.toLocaleUpperCase(/called/, 'not called');
567 actual = xml.function::toLocaleUpperCase.call(xml);
568 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
570 String.prototype.toLocaleUpperCase = String.prototype.orig_toLocaleUpperCase;
571 delete String.prototype.orig_toLocaleUpperCase;
573 var l = <><a>text</a></>;
575 actual = l.function::charAt.call(l, 0);
576 TEST(++nTest, expect, actual);
579 with (l) actual = function::charAt(0);
580 TEST(++nTest, expect, actual);