/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//----------------------------------------------------------------------------- var BUGNUMBER = 103351; // <--- (Outgrowth of original bug 83293) var summ_OLD = 'Testing str.replace(strA, strB) == str.replace(new RegExp(strA),strB)'; var summ_NEW = 'Testing String.prototype.replace(x,y) when x is a string'; var summary = summ_NEW; var status = ''; var actual = ''; var expect= ''; var cnEmptyString = ''; var str = 'abc'; var strA = cnEmptyString; var strB = 'Z';
/******************* THESE WERE INCORRECT; SEE ABOVE ************************ status='SectionAoftest'; strA='a'; actual=str.replace(strA,strB); expect=str.replace(newRegExp(strA),strB); reportCompare(expect,actual,status);
* *Note:'Zabc'istheresultweexpectfor'abc'.replace('','Z'). * *Thestring''issupposedtobeequivalenttonewRegExp('')=//. *Theregexp// means we should match the "empty string" conceived of *atthebeginningboundaryoftheword,beforethefirstcharacter. * status='SectionFoftest'; strA=cnEmptyString; actual=str.replace(strA,strB); expect='Zabc'; reportCompare(expect,actual,status);
************************* END OF INCORRECT CASES ****************************/
////////////////////////// OK, LET'S START OVER //////////////////////////////
status = 'Section 1 of test';
actual = 'abc'.replace('a', 'Z');
expect = 'Zbc';
reportCompare(expect, actual, status);
status = 'Section 2 of test';
actual = 'abc'.replace('b', 'Z');
expect = 'aZc';
reportCompare(expect, actual, status);
status = 'Section 3 of test';
actual = 'abc'.replace(undefined, 'Z');
expect = 'abc'; // String(undefined) == 'undefined'; no replacement possible
reportCompare(expect, actual, status);
status = 'Section 4 of test';
actual = 'abc'.replace(null, 'Z');
expect = 'abc'; // String(null) == 'null'; no replacement possible
reportCompare(expect, actual, status);
status = 'Section 5 of test';
actual = 'abc'.replace(true, 'Z');
expect = 'abc'; // String(true) == 'true'; no replacement possible
reportCompare(expect, actual, status);
status = 'Section 6 of test';
actual = 'abc'.replace(false, 'Z');
expect = 'abc'; // String(false) == 'false'; no replacement possible
reportCompare(expect, actual, status);
status = 'Section 7 of test';
actual = 'aa$aa'.replace('$', 'Z');
expect = 'aaZaa'; // NOT 'aa$aaZ' as in ECMA Final Draft; see above
reportCompare(expect, actual, status);
status = 'Section 8 of test';
actual = 'abc'.replace('.*', 'Z');
expect = 'abc'; // not 'Z' as in EMCA Final Draft
reportCompare(expect, actual, status);
status = 'Section 9 of test';
actual = 'abc'.replace('', 'Z');
expect = 'Zabc'; // Still expect 'Zabc' for this
reportCompare(expect, actual, status);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.