Debian Codegraph @

rhino/testsrc/tests/js1_2/regexp/string_search.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_search.js';
7
8 /**
9 Filename: string_search.js
10 Description: 'Tests the search method on Strings using regular expressions'
11
12 Author: Nick Lerissa
13 Date: March 12, 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: search';
20
21 writeHeaderToLog('Executing script: string_search.js');
22 writeHeaderToLog( SECTION + " "+ TITLE);
23
24 // 'abcdefg'.search(/d/)
25 new TestCase ( SECTION, "'abcdefg'.search(/d/)",
26 3, 'abcdefg'.search(/d/));
27
28 // 'abcdefg'.search(/x/)
29 new TestCase ( SECTION, "'abcdefg'.search(/x/)",
30 -1, 'abcdefg'.search(/x/));
31
32 // 'abcdefg123456hijklmn'.search(/\d+/)
33 new TestCase ( SECTION, "'abcdefg123456hijklmn'.search(/\d+/)",
34 7, 'abcdefg123456hijklmn'.search(/\d+/));
35
36 // 'abcdefg123456hijklmn'.search(new RegExp())
37 new TestCase ( SECTION, "'abcdefg123456hijklmn'.search(new RegExp())",
38 0, 'abcdefg123456hijklmn'.search(new RegExp()));
39
40 // 'abc'.search(new RegExp('$'))
41 new TestCase ( SECTION, "'abc'.search(new RegExp('$'))",
42 3, 'abc'.search(new RegExp('$')));
43
44 // 'abc'.search(new RegExp('^'))
45 new TestCase ( SECTION, "'abc'.search(new RegExp('^'))",
46 0, 'abc'.search(new RegExp('^')));
47
48 // 'abc1'.search(/.\d/)
49 new TestCase ( SECTION, "'abc1'.search(/.\d/)",
50 2, 'abc1'.search(/.\d/));
51
52 // 'abc1'.search(/\d{2}/)
53 new TestCase ( SECTION, "'abc1'.search(/\d{2}/)",
54 -1, 'abc1'.search(/\d{2}/));
55
56 test();