]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_2/regexp/character_class.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: character_class.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: character_class.js');
36 writeHeaderToLog( SECTION
+ " "+ TITLE
);
39 var testcases
= new Array();
41 // 'abcde'.match(new RegExp('ab[ercst]de'))
42 testcases
[count
++] = new TestCase ( SECTION
, "'abcde'.match(new RegExp('ab[ercst]de'))",
43 String(["abcde"]), String('abcde'.match(new RegExp('ab[ercst]de'))));
45 // 'abcde'.match(new RegExp('ab[erst]de'))
46 testcases
[count
++] = new TestCase ( SECTION
, "'abcde'.match(new RegExp('ab[erst]de'))",
47 null, 'abcde'.match(new RegExp('ab[erst]de')));
49 // 'abcdefghijkl'.match(new RegExp('[d-h]+'))
50 testcases
[count
++] = new TestCase ( SECTION
, "'abcdefghijkl'.match(new RegExp('[d-h]+'))",
51 String(["defgh"]), String('abcdefghijkl'.match(new RegExp('[d-h]+'))));
53 // 'abc6defghijkl'.match(new RegExp('[1234567].{2}'))
54 testcases
[count
++] = new TestCase ( SECTION
, "'abc6defghijkl'.match(new RegExp('[1234567].{2}'))",
55 String(["6de"]), String('abc6defghijkl'.match(new RegExp('[1234567].{2}'))));
57 // '\n\n\abc324234\n'.match(new RegExp('[a-c\d]+'))
58 testcases
[count
++] = new TestCase ( SECTION
, "'\n\n\abc324234\n'.match(new RegExp('[a-c\\d]+'))",
59 String(["abc324234"]), String('\n\n\abc324234\n'.match(new RegExp('[a-c\\d]+'))));
61 // 'abc'.match(new RegExp('ab[.]?c'))
62 testcases
[count
++] = new TestCase ( SECTION
, "'abc'.match(new RegExp('ab[.]?c'))",
63 String(["abc"]), String('abc'.match(new RegExp('ab[.]?c'))));
65 // 'abc'.match(new RegExp('a[b]c'))
66 testcases
[count
++] = new TestCase ( SECTION
, "'abc'.match(new RegExp('a[b]c'))",
67 String(["abc"]), String('abc'.match(new RegExp('a[b]c'))));
69 // 'a1b b2c c3d def f4g'.match(new RegExp('[a-z][^1-9][a-z]'))
70 testcases
[count
++] = new TestCase ( SECTION
, "'a1b b2c c3d def f4g'.match(new RegExp('[a-z][^1-9][a-z]'))",
71 String(["def"]), String('a1b b2c c3d def f4g'.match(new RegExp('[a-z][^1-9][a-z]'))));
73 // '123*&$abc'.match(new RegExp('[*&$]{3}'))
74 testcases
[count
++] = new TestCase ( SECTION
, "'123*&$abc'.match(new RegExp('[*&$]{3}'))",
75 String(["*&$"]), String('123*&$abc'.match(new RegExp('[*&$]{3}'))));
77 // 'abc'.match(new RegExp('a[^1-9]c'))
78 testcases
[count
++] = new TestCase ( SECTION
, "'abc'.match(new RegExp('a[^1-9]c'))",
79 String(["abc"]), String('abc'.match(new RegExp('a[^1-9]c'))));
81 // 'abc'.match(new RegExp('a[^b]c'))
82 testcases
[count
++] = new TestCase ( SECTION
, "'abc'.match(new RegExp('a[^b]c'))",
83 null, 'abc'.match(new RegExp('a[^b]c')));
85 // 'abc#$%def%&*@ghi)(*&'.match(new RegExp('[^a-z]{4}'))
86 testcases
[count
++] = new TestCase ( SECTION
, "'abc#$%def%&*@ghi)(*&'.match(new RegExp('[^a-z]{4}'))",
87 String(["%&*@"]), String('abc#$%def%&*@ghi)(*&'.match(new RegExp('[^a-z]{4}'))));
89 // 'abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/)
90 testcases
[count
++] = new TestCase ( SECTION
, "'abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/)",
91 String(["%&*@"]), String('abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/)));
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
);