|
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 |
|
7 /** |
|
8 Filename: string_search.js |
|
9 Description: 'Tests the search method on Strings using regular expressions' |
|
10 |
|
11 Author: Nick Lerissa |
|
12 Date: March 12, 1998 |
|
13 */ |
|
14 |
|
15 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; |
|
16 var VERSION = 'no version'; |
|
17 startTest(); |
|
18 var TITLE = 'String: search'; |
|
19 |
|
20 writeHeaderToLog('Executing script: string_search.js'); |
|
21 writeHeaderToLog( SECTION + " "+ TITLE); |
|
22 |
|
23 // 'abcdefg'.search(/d/) |
|
24 new TestCase ( SECTION, "'abcdefg'.search(/d/)", |
|
25 3, 'abcdefg'.search(/d/)); |
|
26 |
|
27 // 'abcdefg'.search(/x/) |
|
28 new TestCase ( SECTION, "'abcdefg'.search(/x/)", |
|
29 -1, 'abcdefg'.search(/x/)); |
|
30 |
|
31 // 'abcdefg123456hijklmn'.search(/\d+/) |
|
32 new TestCase ( SECTION, "'abcdefg123456hijklmn'.search(/\d+/)", |
|
33 7, 'abcdefg123456hijklmn'.search(/\d+/)); |
|
34 |
|
35 // 'abcdefg123456hijklmn'.search(new RegExp()) |
|
36 new TestCase ( SECTION, "'abcdefg123456hijklmn'.search(new RegExp())", |
|
37 0, 'abcdefg123456hijklmn'.search(new RegExp())); |
|
38 |
|
39 // 'abc'.search(new RegExp('$')) |
|
40 new TestCase ( SECTION, "'abc'.search(new RegExp('$'))", |
|
41 3, 'abc'.search(new RegExp('$'))); |
|
42 |
|
43 // 'abc'.search(new RegExp('^')) |
|
44 new TestCase ( SECTION, "'abc'.search(new RegExp('^'))", |
|
45 0, 'abc'.search(new RegExp('^'))); |
|
46 |
|
47 // 'abc1'.search(/.\d/) |
|
48 new TestCase ( SECTION, "'abc1'.search(/.\d/)", |
|
49 2, 'abc1'.search(/.\d/)); |
|
50 |
|
51 // 'abc1'.search(/\d{2}/) |
|
52 new TestCase ( SECTION, "'abc1'.search(/\d{2}/)", |
|
53 -1, 'abc1'.search(/\d{2}/)); |
|
54 |
|
55 test(); |