]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_2/regexp/digit.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / mozilla / js1_2 / regexp / digit.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/
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: digit.js
24 Description: 'Tests regular expressions containing \d'
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: \\d';
34
35 writeHeaderToLog('Executing script: digit.js');
36 writeHeaderToLog( SECTION + " "+ TITLE);
37
38 var count = 0;
39 var testcases = new Array();
40
41 var non_digits = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\f\n\r\t\v~`!@#$%^&*()-+={[}]|\\:;'<,>./? " + '"';
42
43 var digits = "1234567890";
44
45 // be sure all digits are matched by \d
46 testcases[count++] = new TestCase ( SECTION,
47 "'" + digits + "'.match(new RegExp('\\d+'))",
48 String([digits]), String(digits.match(new RegExp('\\d+'))));
49
50 // be sure all non-digits are matched by \D
51 testcases[count++] = new TestCase ( SECTION,
52 "'" + non_digits + "'.match(new RegExp('\\D+'))",
53 String([non_digits]), String(non_digits.match(new RegExp('\\D+'))));
54
55 // be sure all non-digits are not matched by \d
56 testcases[count++] = new TestCase ( SECTION,
57 "'" + non_digits + "'.match(new RegExp('\\d'))",
58 null, non_digits.match(new RegExp('\\d')));
59
60 // be sure all digits are not matched by \D
61 testcases[count++] = new TestCase ( SECTION,
62 "'" + digits + "'.match(new RegExp('\\D'))",
63 null, digits.match(new RegExp('\\D')));
64
65 var s = non_digits + digits;
66
67 // be sure all digits are matched by \d
68 testcases[count++] = new TestCase ( SECTION,
69 "'" + s + "'.match(new RegExp('\\d+'))",
70 String([digits]), String(s.match(new RegExp('\\d+'))));
71
72 var s = digits + non_digits;
73
74 // be sure all non-digits are matched by \D
75 testcases[count++] = new TestCase ( SECTION,
76 "'" + s + "'.match(new RegExp('\\D+'))",
77 String([non_digits]), String(s.match(new RegExp('\\D+'))));
78
79 var i;
80
81 // be sure all digits match individually
82 for (i = 0; i < digits.length; ++i)
83 {
84 s = 'ab' + digits[i] + 'cd';
85 testcases[count++] = new TestCase ( SECTION,
86 "'" + s + "'.match(new RegExp('\\d'))",
87 String([digits[i]]), String(s.match(new RegExp('\\d'))));
88 testcases[count++] = new TestCase ( SECTION,
89 "'" + s + "'.match(/\\d/)",
90 String([digits[i]]), String(s.match(/\d/)));
91 }
92 // be sure all non_digits match individually
93 for (i = 0; i < non_digits.length; ++i)
94 {
95 s = '12' + non_digits[i] + '34';
96 testcases[count++] = new TestCase ( SECTION,
97 "'" + s + "'.match(new RegExp('\\D'))",
98 String([non_digits[i]]), String(s.match(new RegExp('\\D'))));
99 testcases[count++] = new TestCase ( SECTION,
100 "'" + s + "'.match(/\\D/)",
101 String([non_digits[i]]), String(s.match(/\D/)));
102 }
103
104
105 function test()
106 {
107 for ( tc=0; tc < testcases.length; tc++ ) {
108 testcases[tc].passed = writeTestCaseResult(
109 testcases[tc].expect,
110 testcases[tc].actual,
111 testcases[tc].description +" = "+
112 testcases[tc].actual );
113 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
114 }
115 stopTest();
116 return ( testcases );
117 }
118
119 test();