1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_2/regexp/string_replace.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,92 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + Filename: string_replace.js 1.12 + Description: 'Tests the replace method on Strings using regular expressions' 1.13 + 1.14 + Author: Nick Lerissa 1.15 + Date: March 11, 1998 1.16 +*/ 1.17 + 1.18 +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; 1.19 +var VERSION = 'no version'; 1.20 +startTest(); 1.21 +var TITLE = 'String: replace'; 1.22 + 1.23 +writeHeaderToLog('Executing script: string_replace.js'); 1.24 +writeHeaderToLog( SECTION + " "+ TITLE); 1.25 + 1.26 + 1.27 +// 'adddb'.replace(/ddd/,"XX") 1.28 +new TestCase ( SECTION, "'adddb'.replace(/ddd/,'XX')", 1.29 + "aXXb", 'adddb'.replace(/ddd/,'XX')); 1.30 + 1.31 +// 'adddb'.replace(/eee/,"XX") 1.32 +new TestCase ( SECTION, "'adddb'.replace(/eee/,'XX')", 1.33 + 'adddb', 'adddb'.replace(/eee/,'XX')); 1.34 + 1.35 +// '34 56 78b 12'.replace(new RegExp('[0-9]+b'),'**') 1.36 +new TestCase ( SECTION, "'34 56 78b 12'.replace(new RegExp('[0-9]+b'),'**')", 1.37 + "34 56 ** 12", '34 56 78b 12'.replace(new RegExp('[0-9]+b'),'**')); 1.38 + 1.39 +// '34 56 78b 12'.replace(new RegExp('[0-9]+c'),'XX') 1.40 +new TestCase ( SECTION, "'34 56 78b 12'.replace(new RegExp('[0-9]+c'),'XX')", 1.41 + "34 56 78b 12", '34 56 78b 12'.replace(new RegExp('[0-9]+c'),'XX')); 1.42 + 1.43 +// 'original'.replace(new RegExp(),'XX') 1.44 +new TestCase ( SECTION, "'original'.replace(new RegExp(),'XX')", 1.45 + "XXoriginal", 'original'.replace(new RegExp(),'XX')); 1.46 + 1.47 +// 'qwe ert x\t\n 345654AB'.replace(new RegExp('x\s*\d+(..)$'),'****') 1.48 +new TestCase ( SECTION, "'qwe ert x\t\n 345654AB'.replace(new RegExp('x\\s*\\d+(..)$'),'****')", 1.49 + "qwe ert ****", 'qwe ert x\t\n 345654AB'.replace(new RegExp('x\\s*\\d+(..)$'),'****')); 1.50 + 1.51 + 1.52 +/* 1.53 + * Test replacement over ropes. The char to rope node ratio must be sufficiently 1.54 + * high for the special-case code to be tested. 1.55 + */ 1.56 +var stringA = "abcdef"; 1.57 +var stringB = "ghijk"; 1.58 +var stringC = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"; 1.59 +stringC += stringC; 1.60 +stringC += stringC; 1.61 +stringC[0]; /* flatten stringC */ 1.62 +var stringD = "lmn"; 1.63 + 1.64 +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('aa', '')", 1.65 + stringA + stringB + stringC, (stringA + stringB + stringC).replace('aa', '')); 1.66 + 1.67 +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('abc', 'AA')", 1.68 + "AAdefghijk" + stringC, (stringA + stringB + stringC).replace('abc', 'AA')); 1.69 + 1.70 +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('def', 'AA')", 1.71 + "abcAAghijk" + stringC, (stringA + stringB + stringC).replace('def', 'AA')); 1.72 + 1.73 +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('efg', 'AA')", 1.74 + "abcdAAhijk" + stringC, (stringA + stringB + stringC).replace('efg', 'AA')); 1.75 + 1.76 +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('fgh', 'AA')", 1.77 + "abcdeAAijk" + stringC, (stringA + stringB + stringC).replace('fgh', 'AA')); 1.78 + 1.79 +new TestCase ( SECTION, "(stringA + stringB + stringC).replace('ghi', 'AA')", 1.80 + "abcdefAAjk" + stringC, (stringA + stringB + stringC).replace('ghi', 'AA')); 1.81 + 1.82 +new TestCase ( SECTION, "(stringC + stringD).replace('lmn', 'AA')", 1.83 + stringC + "AA", (stringC + stringD).replace('lmn', 'AA')); 1.84 + 1.85 +new TestCase ( SECTION, "(stringC + stringD).replace('lmno', 'AA')", 1.86 + stringC + stringD, (stringC + stringD).replace('lmno', 'AA')); 1.87 + 1.88 +new TestCase ( SECTION, "(stringC + stringD).replace('mn', 'AA')", 1.89 + stringC + "lAA", (stringC + stringD).replace('mn', 'AA')); 1.90 + 1.91 +new TestCase ( SECTION, "(stringC + stringD).replace('n', 'AA')", 1.92 + stringC + "lmAA", (stringC + stringD).replace('n', 'AA')); 1.93 + 1.94 + 1.95 +test();