]>
Commit | Line | Data |
---|---|---|
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: whitespace.js | |
24 | Description: 'Tests regular expressions containing \f\n\r\t\v\s\S\ ' | |
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: \\f\\n\\r\\t\\v\\s\\S '; | |
34 | ||
35 | writeHeaderToLog('Executing script: whitespace.js'); | |
36 | writeHeaderToLog( SECTION + " "+ TITLE); | |
37 | ||
38 | var count = 0; | |
39 | var testcases = new Array(); | |
40 | ||
41 | var non_whitespace = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()-+={[}]|\\:;'<,>./?1234567890" + '"'; | |
42 | var whitespace = "\f\n\r\t\v "; | |
43 | ||
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+')))); | |
48 | ||
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+')))); | |
53 | ||
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'))); | |
58 | ||
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'))); | |
63 | ||
64 | var s = non_whitespace + whitespace; | |
65 | ||
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+')))); | |
70 | ||
71 | s = whitespace + non_whitespace; | |
72 | ||
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+')))); | |
77 | ||
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]+')))); | |
81 | ||
82 | var i; | |
83 | ||
84 | // be sure all whitespace characters match individually | |
85 | for (i = 0; i < whitespace.length; ++i) | |
86 | { | |
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/))); | |
94 | } | |
95 | // be sure all non_whitespace characters match individually | |
96 | for (i = 0; i < non_whitespace.length; ++i) | |
97 | { | |
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/))); | |
105 | } | |
106 | ||
107 | ||
108 | function test() | |
109 | { | |
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 "; | |
117 | } | |
118 | stopTest(); | |
119 | return ( testcases ); | |
120 | } | |
121 | ||
122 | test(); |