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: whitespace.js
24 Description: 'Tests regular expressions containing \f\n\r\t\v\s\S\ '
30 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
31 var VERSION = 'no version';
33 var TITLE = 'RegExp: \\f\\n\\r\\t\\v\\s\\S ';
35 writeHeaderToLog('Executing script: whitespace.js');
36 writeHeaderToLog( SECTION + " "+ TITLE);
39 var testcases = new Array();
41 var non_whitespace = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()-+={[}]|\\:;'<,>./?1234567890" + '"';
42 var whitespace = "\f\n\r\t\v ";
44 // be sure all whitespace is matched by \s
45 testcases[count++] = new TestCase ( SECTION,
46 "'" + whitespace + "'.match(new RegExp('\\s+'))",
47 String([whitespace]), String(whitespace.match(new RegExp('\\s+'))));
49 // be sure all non-whitespace is matched by \S
50 testcases[count++] = new TestCase ( SECTION,
51 "'" + non_whitespace + "'.match(new RegExp('\\S+'))",
52 String([non_whitespace]), String(non_whitespace.match(new RegExp('\\S+'))));
54 // be sure all non-whitespace is not matched by \s
55 testcases[count++] = new TestCase ( SECTION,
56 "'" + non_whitespace + "'.match(new RegExp('\\s'))",
57 null, non_whitespace.match(new RegExp('\\s')));
59 // be sure all whitespace is not matched by \S
60 testcases[count++] = new TestCase ( SECTION,
61 "'" + whitespace + "'.match(new RegExp('\\S'))",
62 null, whitespace.match(new RegExp('\\S')));
64 var s = non_whitespace + whitespace;
66 // be sure all digits are matched by \s
67 testcases[count++] = new TestCase ( SECTION,
68 "'" + s + "'.match(new RegExp('\\s+'))",
69 String([whitespace]), String(s.match(new RegExp('\\s+'))));
71 s = whitespace + non_whitespace;
73 // be sure all non-whitespace are matched by \S
74 testcases[count++] = new TestCase ( SECTION,
75 "'" + s + "'.match(new RegExp('\\S+'))",
76 String([non_whitespace]), String(s.match(new RegExp('\\S+'))));
78 // '1233345find me345'.match(new RegExp('[a-z\\s][a-z\\s]+'))
79 testcases[count++] = new TestCase ( SECTION, "'1233345find me345'.match(new RegExp('[a-z\\s][a-z\\s]+'))",
80 String(["find me"]), String('1233345find me345'.match(new RegExp('[a-z\\s][a-z\\s]+'))));
84 // be sure all whitespace characters match individually
85 for (i = 0; i < whitespace.length; ++i)
87 s = 'ab' + whitespace[i] + 'cd';
88 testcases[count++] = new TestCase ( SECTION,
89 "'" + s + "'.match(new RegExp('\\\\s'))",
90 String([whitespace[i]]), String(s.match(new RegExp('\\s'))));
91 testcases[count++] = new TestCase ( SECTION,
92 "'" + s + "'.match(/\s/)",
93 String([whitespace[i]]), String(s.match(/\s/)));
95 // be sure all non_whitespace characters match individually
96 for (i = 0; i < non_whitespace.length; ++i)
98 s = ' ' + non_whitespace[i] + ' ';
99 testcases[count++] = new TestCase ( SECTION,
100 "'" + s + "'.match(new RegExp('\\\\S'))",
101 String([non_whitespace[i]]), String(s.match(new RegExp('\\S'))));
102 testcases[count++] = new TestCase ( SECTION,
103 "'" + s + "'.match(/\S/)",
104 String([non_whitespace[i]]), String(s.match(/\S/)));
110 for ( tc=0; tc < testcases.length; tc++ ) {
111 testcases[tc].passed = writeTestCaseResult(
112 testcases[tc].expect,
113 testcases[tc].actual,
114 testcases[tc].description +" = "+
115 testcases[tc].actual );
116 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
119 return ( testcases );