Debian Codegraph @

rhino/testsrc/tests/js1_2/regexp/string_replace.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = 'string_replace.js';
7
8 /**
9 Filename: string_replace.js
10 Description: 'Tests the replace method on Strings using regular expressions'
11
12 Author: Nick Lerissa
13 Date: March 11, 1998
14 */
15
16 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
17 var VERSION = 'no version';
18 startTest();
19 var TITLE = 'String: replace';
20
21 writeHeaderToLog('Executing script: string_replace.js');
22 writeHeaderToLog( SECTION + " "+ TITLE);
23
24
25 // 'adddb'.replace(/ddd/,"XX")
26 new TestCase ( SECTION, "'adddb'.replace(/ddd/,'XX')",
27 "aXXb", 'adddb'.replace(/ddd/,'XX'));
28
29 // 'adddb'.replace(/eee/,"XX")
30 new TestCase ( SECTION, "'adddb'.replace(/eee/,'XX')",
31 'adddb', 'adddb'.replace(/eee/,'XX'));
32
33 // '34 56 78b 12'.replace(new RegExp('[0-9]+b'),'**')
34 new TestCase ( SECTION, "'34 56 78b 12'.replace(new RegExp('[0-9]+b'),'**')",
35 "34 56 ** 12", '34 56 78b 12'.replace(new RegExp('[0-9]+b'),'**'));
36
37 // '34 56 78b 12'.replace(new RegExp('[0-9]+c'),'XX')
38 new TestCase ( SECTION, "'34 56 78b 12'.replace(new RegExp('[0-9]+c'),'XX')",
39 "34 56 78b 12", '34 56 78b 12'.replace(new RegExp('[0-9]+c'),'XX'));
40
41 // 'original'.replace(new RegExp(),'XX')
42 new TestCase ( SECTION, "'original'.replace(new RegExp(),'XX')",
43 "XXoriginal", 'original'.replace(new RegExp(),'XX'));
44
45 // 'qwe ert x\t\n 345654AB'.replace(new RegExp('x\s*\d+(..)$'),'****')
46 new TestCase ( SECTION, "'qwe ert x\t\n 345654AB'.replace(new RegExp('x\\s*\\d+(..)$'),'****')",
47 "qwe ert ****", 'qwe ert x\t\n 345654AB'.replace(new RegExp('x\\s*\\d+(..)$'),'****'));
48
49
50 test();