]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_2/regexp/alphanumeric.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: alphanumeric.js
24 Description: 'Tests regular expressions with \w and \W special characters'
30 var SECTION
= 'As described in Netscape doc "Whats new in JavaScript 1.2"';
31 var VERSION
= 'no version';
33 var TITLE
= 'RegExp: \\w and \\W';
35 writeHeaderToLog('Executing script: alphanumeric.js');
36 writeHeaderToLog( SECTION
+ " " + TITLE
);
39 var testcases
= new Array();
41 var non_alphanumeric
= "~`!@#$%^&*()-+={[}]|\\:;'<,>./?\f\n\r\t\v " + '"';
42 var alphanumeric
= "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
44 // be sure all alphanumerics are matched by \w
45 testcases
[count
++] = new TestCase ( SECTION
,
46 "'" + alphanumeric
+ "'.match(new RegExp('\\w+'))",
47 String([alphanumeric
]), String(alphanumeric
.match(new RegExp('\\w+'))));
49 // be sure all non-alphanumerics are matched by \W
50 testcases
[count
++] = new TestCase ( SECTION
,
51 "'" + non_alphanumeric
+ "'.match(new RegExp('\\W+'))",
52 String([non_alphanumeric
]), String(non_alphanumeric
.match(new RegExp('\\W+'))));
54 // be sure all non-alphanumerics are not matched by \w
55 testcases
[count
++] = new TestCase ( SECTION
,
56 "'" + non_alphanumeric
+ "'.match(new RegExp('\\w'))",
57 null, non_alphanumeric
.match(new RegExp('\\w')));
59 // be sure all alphanumerics are not matched by \W
60 testcases
[count
++] = new TestCase ( SECTION
,
61 "'" + alphanumeric
+ "'.match(new RegExp('\\W'))",
62 null, alphanumeric
.match(new RegExp('\\W')));
64 var s
= non_alphanumeric
+ alphanumeric
;
66 // be sure all alphanumerics are matched by \w
67 testcases
[count
++] = new TestCase ( SECTION
,
68 "'" + s
+ "'.match(new RegExp('\\w+'))",
69 String([alphanumeric
]), String(s
.match(new RegExp('\\w+'))));
71 s
= alphanumeric
+ non_alphanumeric
;
73 // be sure all non-alphanumerics are matched by \W
74 testcases
[count
++] = new TestCase ( SECTION
,
75 "'" + s
+ "'.match(new RegExp('\\W+'))",
76 String([non_alphanumeric
]), String(s
.match(new RegExp('\\W+'))));
78 // be sure all alphanumerics are matched by \w (using literals)
79 testcases
[count
++] = new TestCase ( SECTION
,
80 "'" + s
+ "'.match(/\w+/)",
81 String([alphanumeric
]), String(s
.match(/\w+/)));
83 s
= alphanumeric
+ non_alphanumeric
;
85 // be sure all non-alphanumerics are matched by \W (using literals)
86 testcases
[count
++] = new TestCase ( SECTION
,
87 "'" + s
+ "'.match(/\W+/)",
88 String([non_alphanumeric
]), String(s
.match(/\W+/)));
91 // be sure the following test behaves consistently
92 testcases
[count
++] = new TestCase ( SECTION
,
93 "'" + s
+ "'.match(/(\w+)...(\W+)/)",
94 String([s
, 'abcd' , '%$$']), String(s
.match(/(\w+)...(\W+)/)));
98 // be sure all alphanumeric characters match individually
99 for (i
= 0; i
< alphanumeric
.length
; ++i
)
101 s
= '#$' + alphanumeric
[i
] + '%^';
102 testcases
[count
++] = new TestCase ( SECTION
,
103 "'" + s
+ "'.match(new RegExp('\\w'))",
104 String([alphanumeric
[i
]]), String(s
.match(new RegExp('\\w'))));
106 // be sure all non_alphanumeric characters match individually
107 for (i
= 0; i
< non_alphanumeric
.length
; ++i
)
109 s
= 'sd' + non_alphanumeric
[i
] + String((i
+10) * (i
+10) - 2 * (i
+10));
110 testcases
[count
++] = new TestCase ( SECTION
,
111 "'" + s
+ "'.match(new RegExp('\\W'))",
112 String([non_alphanumeric
[i
]]), String(s
.match(new RegExp('\\W'))));
117 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
118 testcases
[tc
].passed
= writeTestCaseResult(
119 testcases
[tc
].expect
,
120 testcases
[tc
].actual
,
121 testcases
[tc
].description
+" = "+
122 testcases
[tc
].actual
);
123 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
126 return ( testcases
);