]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/mozilla/js1_2/regexp/character_class.js
JavaScriptCore-461.tar.gz
[apple/javascriptcore.git] / tests / mozilla / js1_2 / regexp / character_class.js
CommitLineData
b37bf2e1
A
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/
5 *
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.
10 *
11 * The Original Code is Mozilla Communicator client code, released March
12 * 31, 1998.
13 *
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
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22/**
23 Filename: character_class.js
24 Description: 'Tests regular expressions containing []'
25
26 Author: Nick Lerissa
27 Date: March 10, 1998
28*/
29
30 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
31 var VERSION = 'no version';
32 startTest();
33 var TITLE = 'RegExp: []';
34
35 writeHeaderToLog('Executing script: character_class.js');
36 writeHeaderToLog( SECTION + " "+ TITLE);
37
38 var count = 0;
39 var testcases = new Array();
40
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'))));
44
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')));
48
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]+'))));
52
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}'))));
56
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]+'))));
60
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'))));
64
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'))));
68
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]'))));
72
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}'))));
76
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'))));
80
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')));
84
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}'))));
88
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}/)));
92
93 function test()
94 {
95 for ( tc=0; tc < testcases.length; tc++ ) {
96 testcases[tc].passed = writeTestCaseResult(
97 testcases[tc].expect,
98 testcases[tc].actual,
99 testcases[tc].description +" = "+
100 testcases[tc].actual );
101 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
102 }
103 stopTest();
104 return ( testcases );
105 }
106
107 test();