|
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: parentheses.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: parentheses.js'); |
|
21 writeHeaderToLog( SECTION + " "+ TITLE); |
|
22 |
|
23 // 'abc'.match(new RegExp('(abc)')) |
|
24 new TestCase ( SECTION, "'abc'.match(new RegExp('(abc)'))", |
|
25 String(["abc","abc"]), String('abc'.match(new RegExp('(abc)')))); |
|
26 |
|
27 // 'abcdefg'.match(new RegExp('a(bc)d(ef)g')) |
|
28 new TestCase ( SECTION, "'abcdefg'.match(new RegExp('a(bc)d(ef)g'))", |
|
29 String(["abcdefg","bc","ef"]), String('abcdefg'.match(new RegExp('a(bc)d(ef)g')))); |
|
30 |
|
31 // 'abcdefg'.match(new RegExp('(.{3})(.{4})')) |
|
32 new TestCase ( SECTION, "'abcdefg'.match(new RegExp('(.{3})(.{4})'))", |
|
33 String(["abcdefg","abc","defg"]), String('abcdefg'.match(new RegExp('(.{3})(.{4})')))); |
|
34 |
|
35 // 'aabcdaabcd'.match(new RegExp('(aa)bcd\1')) |
|
36 new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(aa)bcd\\1'))", |
|
37 String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(aa)bcd\\1')))); |
|
38 |
|
39 // 'aabcdaabcd'.match(new RegExp('(aa).+\1')) |
|
40 new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(aa).+\\1'))", |
|
41 String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(aa).+\\1')))); |
|
42 |
|
43 // 'aabcdaabcd'.match(new RegExp('(.{2}).+\1')) |
|
44 new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(.{2}).+\\1'))", |
|
45 String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(.{2}).+\\1')))); |
|
46 |
|
47 // '123456123456'.match(new RegExp('(\d{3})(\d{3})\1\2')) |
|
48 new TestCase ( SECTION, "'123456123456'.match(new RegExp('(\\d{3})(\\d{3})\\1\\2'))", |
|
49 String(["123456123456","123","456"]), String('123456123456'.match(new RegExp('(\\d{3})(\\d{3})\\1\\2')))); |
|
50 |
|
51 // 'abcdefg'.match(new RegExp('a(..(..)..)')) |
|
52 new TestCase ( SECTION, "'abcdefg'.match(new RegExp('a(..(..)..)'))", |
|
53 String(["abcdefg","bcdefg","de"]), String('abcdefg'.match(new RegExp('a(..(..)..)')))); |
|
54 |
|
55 // 'abcdefg'.match(/a(..(..)..)/) |
|
56 new TestCase ( SECTION, "'abcdefg'.match(/a(..(..)..)/)", |
|
57 String(["abcdefg","bcdefg","de"]), String('abcdefg'.match(/a(..(..)..)/))); |
|
58 |
|
59 // 'xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))')) |
|
60 new TestCase ( SECTION, "'xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))'))", |
|
61 String(["abcdef","abc","bc","c","def","ef","f"]), String('xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))')))); |
|
62 |
|
63 // 'xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\2\5')) |
|
64 new TestCase ( SECTION, "'xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\\2\\5'))", |
|
65 String(["abcdefbcef","abc","bc","c","def","ef","f"]), String('xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\\2\\5')))); |
|
66 |
|
67 // 'abcd'.match(new RegExp('a(.?)b\1c\1d\1')) |
|
68 new TestCase ( SECTION, "'abcd'.match(new RegExp('a(.?)b\\1c\\1d\\1'))", |
|
69 String(["abcd",""]), String('abcd'.match(new RegExp('a(.?)b\\1c\\1d\\1')))); |
|
70 |
|
71 // 'abcd'.match(/a(.?)b\1c\1d\1/) |
|
72 new TestCase ( SECTION, "'abcd'.match(/a(.?)b\\1c\\1d\\1/)", |
|
73 String(["abcd",""]), String('abcd'.match(/a(.?)b\1c\1d\1/))); |
|
74 |
|
75 test(); |