Imported tests
[mono.git] / mcs / class / Microsoft.JScript / Test / Mozilla / js1_2 / regexp / parentheses.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */\r
2 /* ***** BEGIN LICENSE BLOCK *****\r
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1\r
4  *\r
5  * The contents of this file are subject to the Mozilla Public License Version\r
6  * 1.1 (the "License"); you may not use this file except in compliance with\r
7  * the License. You may obtain a copy of the License at\r
8  * http://www.mozilla.org/MPL/\r
9  *\r
10  * Software distributed under the License is distributed on an "AS IS" basis,\r
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License\r
12  * for the specific language governing rights and limitations under the\r
13  * License.\r
14  *\r
15  * The Original Code is Mozilla Communicator client code, released\r
16  * March 31, 1998.\r
17  *\r
18  * The Initial Developer of the Original Code is\r
19  * Netscape Communications Corporation.\r
20  * Portions created by the Initial Developer are Copyright (C) 1998\r
21  * the Initial Developer. All Rights Reserved.\r
22  *\r
23  * Contributor(s):\r
24  *\r
25  * Alternatively, the contents of this file may be used under the terms of\r
26  * either the GNU General Public License Version 2 or later (the "GPL"), or\r
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),\r
28  * in which case the provisions of the GPL or the LGPL are applicable instead\r
29  * of those above. If you wish to allow use of your version of this file only\r
30  * under the terms of either the GPL or the LGPL, and not to allow others to\r
31  * use your version of this file under the terms of the MPL, indicate your\r
32  * decision by deleting the provisions above and replace them with the notice\r
33  * and other provisions required by the GPL or the LGPL. If you do not delete\r
34  * the provisions above, a recipient may use your version of this file under\r
35  * the terms of any one of the MPL, the GPL or the LGPL.\r
36  *\r
37  * ***** END LICENSE BLOCK ***** */\r
38 \r
39 /**\r
40    Filename:     parentheses.js\r
41    Description:  'Tests regular expressions containing ()'\r
42 \r
43    Author:       Nick Lerissa\r
44    Date:         March 10, 1998\r
45 */\r
46 \r
47 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';\r
48 var VERSION = 'no version';\r
49 startTest();\r
50 var TITLE   = 'RegExp: ()';\r
51 \r
52 writeHeaderToLog('Executing script: parentheses.js');\r
53 writeHeaderToLog( SECTION + " "+ TITLE);\r
54 \r
55 // 'abc'.match(new RegExp('(abc)'))\r
56 new TestCase ( SECTION, "'abc'.match(new RegExp('(abc)'))",\r
57                String(["abc","abc"]), String('abc'.match(new RegExp('(abc)'))));\r
58 \r
59 // 'abcdefg'.match(new RegExp('a(bc)d(ef)g'))\r
60 new TestCase ( SECTION, "'abcdefg'.match(new RegExp('a(bc)d(ef)g'))",\r
61                String(["abcdefg","bc","ef"]), String('abcdefg'.match(new RegExp('a(bc)d(ef)g'))));\r
62 \r
63 // 'abcdefg'.match(new RegExp('(.{3})(.{4})'))\r
64 new TestCase ( SECTION, "'abcdefg'.match(new RegExp('(.{3})(.{4})'))",\r
65                String(["abcdefg","abc","defg"]), String('abcdefg'.match(new RegExp('(.{3})(.{4})'))));\r
66 \r
67 // 'aabcdaabcd'.match(new RegExp('(aa)bcd\1'))\r
68 new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(aa)bcd\\1'))",\r
69                String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(aa)bcd\\1'))));\r
70 \r
71 // 'aabcdaabcd'.match(new RegExp('(aa).+\1'))\r
72 new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(aa).+\\1'))",\r
73                String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(aa).+\\1'))));\r
74 \r
75 // 'aabcdaabcd'.match(new RegExp('(.{2}).+\1'))\r
76 new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(.{2}).+\\1'))",\r
77                String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(.{2}).+\\1'))));\r
78 \r
79 // '123456123456'.match(new RegExp('(\d{3})(\d{3})\1\2'))\r
80 new TestCase ( SECTION, "'123456123456'.match(new RegExp('(\\d{3})(\\d{3})\\1\\2'))",\r
81                String(["123456123456","123","456"]), String('123456123456'.match(new RegExp('(\\d{3})(\\d{3})\\1\\2'))));\r
82 \r
83 // 'abcdefg'.match(new RegExp('a(..(..)..)'))\r
84 new TestCase ( SECTION, "'abcdefg'.match(new RegExp('a(..(..)..)'))",\r
85                String(["abcdefg","bcdefg","de"]), String('abcdefg'.match(new RegExp('a(..(..)..)'))));\r
86 \r
87 // 'abcdefg'.match(/a(..(..)..)/)\r
88 new TestCase ( SECTION, "'abcdefg'.match(/a(..(..)..)/)",\r
89                String(["abcdefg","bcdefg","de"]), String('abcdefg'.match(/a(..(..)..)/)));\r
90 \r
91 // 'xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))'))\r
92 new TestCase ( SECTION, "'xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))'))",\r
93                String(["abcdef","abc","bc","c","def","ef","f"]), String('xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))'))));\r
94 \r
95 // 'xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\2\5'))\r
96 new TestCase ( SECTION, "'xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\\2\\5'))",\r
97                String(["abcdefbcef","abc","bc","c","def","ef","f"]), String('xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\\2\\5'))));\r
98 \r
99 // 'abcd'.match(new RegExp('a(.?)b\1c\1d\1'))\r
100 new TestCase ( SECTION, "'abcd'.match(new RegExp('a(.?)b\\1c\\1d\\1'))",\r
101                String(["abcd",""]), String('abcd'.match(new RegExp('a(.?)b\\1c\\1d\\1'))));\r
102 \r
103 // 'abcd'.match(/a(.?)b\1c\1d\1/)\r
104 new TestCase ( SECTION, "'abcd'.match(/a(.?)b\\1c\\1d\\1/)",\r
105                String(["abcd",""]), String('abcd'.match(/a(.?)b\1c\1d\1/)));\r
106 \r
107 test();\r