|
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: asterisk.js |
|
9 Description: 'Tests regular expressions containing *' |
|
10 |
|
11 Author: Nick Lerissa |
|
12 Date: March 10, 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 = 'RegExp: *'; |
|
19 |
|
20 writeHeaderToLog('Executing script: aterisk.js'); |
|
21 writeHeaderToLog( SECTION + " "+ TITLE); |
|
22 |
|
23 // 'abcddddefg'.match(new RegExp('d*')) |
|
24 new TestCase ( SECTION, "'abcddddefg'.match(new RegExp('d*'))", |
|
25 String([""]), String('abcddddefg'.match(new RegExp('d*')))); |
|
26 |
|
27 // 'abcddddefg'.match(new RegExp('cd*')) |
|
28 new TestCase ( SECTION, "'abcddddefg'.match(new RegExp('cd*'))", |
|
29 String(["cdddd"]), String('abcddddefg'.match(new RegExp('cd*')))); |
|
30 |
|
31 // 'abcdefg'.match(new RegExp('cx*d')) |
|
32 new TestCase ( SECTION, "'abcdefg'.match(new RegExp('cx*d'))", |
|
33 String(["cd"]), String('abcdefg'.match(new RegExp('cx*d')))); |
|
34 |
|
35 // 'xxxxxxx'.match(new RegExp('(x*)(x+)')) |
|
36 new TestCase ( SECTION, "'xxxxxxx'.match(new RegExp('(x*)(x+)'))", |
|
37 String(["xxxxxxx","xxxxxx","x"]), String('xxxxxxx'.match(new RegExp('(x*)(x+)')))); |
|
38 |
|
39 // '1234567890'.match(new RegExp('(\\d*)(\\d+)')) |
|
40 new TestCase ( SECTION, "'1234567890'.match(new RegExp('(\\d*)(\\d+)'))", |
|
41 String(["1234567890","123456789","0"]), |
|
42 String('1234567890'.match(new RegExp('(\\d*)(\\d+)')))); |
|
43 |
|
44 // '1234567890'.match(new RegExp('(\\d*)\\d(\\d+)')) |
|
45 new TestCase ( SECTION, "'1234567890'.match(new RegExp('(\\d*)\\d(\\d+)'))", |
|
46 String(["1234567890","12345678","0"]), |
|
47 String('1234567890'.match(new RegExp('(\\d*)\\d(\\d+)')))); |
|
48 |
|
49 // 'xxxxxxx'.match(new RegExp('(x+)(x*)')) |
|
50 new TestCase ( SECTION, "'xxxxxxx'.match(new RegExp('(x+)(x*)'))", |
|
51 String(["xxxxxxx","xxxxxxx",""]), String('xxxxxxx'.match(new RegExp('(x+)(x*)')))); |
|
52 |
|
53 // 'xxxxxxyyyyyy'.match(new RegExp('x*y+$')) |
|
54 new TestCase ( SECTION, "'xxxxxxyyyyyy'.match(new RegExp('x*y+$'))", |
|
55 String(["xxxxxxyyyyyy"]), String('xxxxxxyyyyyy'.match(new RegExp('x*y+$')))); |
|
56 |
|
57 // 'abcdef'.match(/[\d]*[\s]*bc./) |
|
58 new TestCase ( SECTION, "'abcdef'.match(/[\\d]*[\\s]*bc./)", |
|
59 String(["bcd"]), String('abcdef'.match(/[\d]*[\s]*bc./))); |
|
60 |
|
61 // 'abcdef'.match(/bc..[\d]*[\s]*/) |
|
62 new TestCase ( SECTION, "'abcdef'.match(/bc..[\\d]*[\\s]*/)", |
|
63 String(["bcde"]), String('abcdef'.match(/bc..[\d]*[\s]*/))); |
|
64 |
|
65 // 'a1b2c3'.match(/.*/) |
|
66 new TestCase ( SECTION, "'a1b2c3'.match(/.*/)", |
|
67 String(["a1b2c3"]), String('a1b2c3'.match(/.*/))); |
|
68 |
|
69 // 'a0.b2.c3'.match(/[xyz]*1/) |
|
70 new TestCase ( SECTION, "'a0.b2.c3'.match(/[xyz]*1/)", |
|
71 null, 'a0.b2.c3'.match(/[xyz]*1/)); |
|
72 |
|
73 test(); |