]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_2/regexp/parentheses.js
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
23 Filename: parentheses.js
24 Description: 'Tests regular expressions containing ()'
30 var SECTION
= 'As described in Netscape doc "Whats new in JavaScript 1.2"';
31 var VERSION
= 'no version';
33 var TITLE
= 'RegExp: ()';
35 writeHeaderToLog('Executing script: parentheses.js');
36 writeHeaderToLog( SECTION
+ " "+ TITLE
);
39 var testcases
= new Array();
41 // 'abc'.match(new RegExp('(abc)'))
42 testcases
[count
++] = new TestCase ( SECTION
, "'abc'.match(new RegExp('(abc)'))",
43 String(["abc","abc"]), String('abc'.match(new RegExp('(abc)'))));
45 // 'abcdefg'.match(new RegExp('a(bc)d(ef)g'))
46 testcases
[count
++] = new TestCase ( SECTION
, "'abcdefg'.match(new RegExp('a(bc)d(ef)g'))",
47 String(["abcdefg","bc","ef"]), String('abcdefg'.match(new RegExp('a(bc)d(ef)g'))));
49 // 'abcdefg'.match(new RegExp('(.{3})(.{4})'))
50 testcases
[count
++] = new TestCase ( SECTION
, "'abcdefg'.match(new RegExp('(.{3})(.{4})'))",
51 String(["abcdefg","abc","defg"]), String('abcdefg'.match(new RegExp('(.{3})(.{4})'))));
53 // 'aabcdaabcd'.match(new RegExp('(aa)bcd\1'))
54 testcases
[count
++] = new TestCase ( SECTION
, "'aabcdaabcd'.match(new RegExp('(aa)bcd\\1'))",
55 String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(aa)bcd\\1'))));
57 // 'aabcdaabcd'.match(new RegExp('(aa).+\1'))
58 testcases
[count
++] = new TestCase ( SECTION
, "'aabcdaabcd'.match(new RegExp('(aa).+\\1'))",
59 String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(aa).+\\1'))));
61 // 'aabcdaabcd'.match(new RegExp('(.{2}).+\1'))
62 testcases
[count
++] = new TestCase ( SECTION
, "'aabcdaabcd'.match(new RegExp('(.{2}).+\\1'))",
63 String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(.{2}).+\\1'))));
65 // '123456123456'.match(new RegExp('(\d{3})(\d{3})\1\2'))
66 testcases
[count
++] = new TestCase ( SECTION
, "'123456123456'.match(new RegExp('(\\d{3})(\\d{3})\\1\\2'))",
67 String(["123456123456","123","456"]), String('123456123456'.match(new RegExp('(\\d{3})(\\d{3})\\1\\2'))));
69 // 'abcdefg'.match(new RegExp('a(..(..)..)'))
70 testcases
[count
++] = new TestCase ( SECTION
, "'abcdefg'.match(new RegExp('a(..(..)..)'))",
71 String(["abcdefg","bcdefg","de"]), String('abcdefg'.match(new RegExp('a(..(..)..)'))));
73 // 'abcdefg'.match(/a(..(..)..)/)
74 testcases
[count
++] = new TestCase ( SECTION
, "'abcdefg'.match(/a(..(..)..)/)",
75 String(["abcdefg","bcdefg","de"]), String('abcdefg'.match(/a(..(..)..)/)));
77 // 'xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))'))
78 testcases
[count
++] = new TestCase ( SECTION
, "'xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))'))",
79 String(["abcdef","abc","bc","c","def","ef","f"]), String('xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))'))));
81 // 'xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\2\5'))
82 testcases
[count
++] = new TestCase ( SECTION
, "'xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\\2\\5'))",
83 String(["abcdefbcef","abc","bc","c","def","ef","f"]), String('xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\\2\\5'))));
85 // 'abcd'.match(new RegExp('a(.?)b\1c\1d\1'))
86 testcases
[count
++] = new TestCase ( SECTION
, "'abcd'.match(new RegExp('a(.?)b\\1c\\1d\\1'))",
87 String(["abcd",""]), String('abcd'.match(new RegExp('a(.?)b\\1c\\1d\\1'))));
89 // 'abcd'.match(/a(.?)b\1c\1d\1/)
90 testcases
[count
++] = new TestCase ( SECTION
, "'abcd'.match(/a(.?)b\\1c\\1d\\1/)",
91 String(["abcd",""]), String('abcd'.match(/a(.?)b\1c\1d\1/)));
95 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
96 testcases
[tc
].passed
= writeTestCaseResult(
99 testcases
[tc
].description
+" = "+
100 testcases
[tc
].actual
);
101 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
104 return ( testcases
);