]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_2/regexp/RegExp_object.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: RegExp_object.js
24 Description: 'Tests regular expressions creating RexExp Objects'
30 var SECTION
= 'As described in Netscape doc "Whats new in JavaScript 1.2"';
31 var VERSION
= 'no version';
33 var TITLE
= 'RegExp: object';
35 writeHeaderToLog('Executing script: RegExp_object.js');
36 writeHeaderToLog( SECTION
+ " "+ TITLE
);
39 var testcases
= new Array();
41 var SSN_pattern
= new RegExp("\\d{3}-\\d{2}-\\d{4}");
43 // testing SSN pattern
44 testcases
[count
++] = new TestCase ( SECTION
, "'Test SSN is 123-34-4567'.match(SSN_pattern))",
45 String(["123-34-4567"]), String('Test SSN is 123-34-4567'.match(SSN_pattern
)));
47 // testing SSN pattern
48 testcases
[count
++] = new TestCase ( SECTION
, "'Test SSN is 123-34-4567'.match(SSN_pattern))",
49 String(["123-34-4567"]), String('Test SSN is 123-34-4567'.match(SSN_pattern
)));
51 var PHONE_pattern
= new RegExp("\\(?(\\d{3})\\)?-?(\\d{3})-(\\d{4})");
52 // testing PHONE pattern
53 testcases
[count
++] = new TestCase ( SECTION
, "'Our phone number is (408)345-2345.'.match(PHONE_pattern))",
54 String(["(408)345-2345","408","345","2345"]), String('Our phone number is (408)345-2345.'.match(PHONE_pattern
)));
56 // testing PHONE pattern
57 testcases
[count
++] = new TestCase ( SECTION
, "'The phone number is 408-345-2345!'.match(PHONE_pattern))",
58 String(["408-345-2345","408","345","2345"]), String('The phone number is 408-345-2345!'.match(PHONE_pattern
)));
60 // testing PHONE pattern
61 testcases
[count
++] = new TestCase ( SECTION
, "String(PHONE_pattern.toString())",
62 "/\\(?(\\d{3})\\)?-?(\\d{3})-(\\d{4})/", String(PHONE_pattern
.toString()));
64 // testing conversion to String
65 testcases
[count
++] = new TestCase ( SECTION
, "PHONE_pattern + ' is the string'",
66 "/\\(?(\\d{3})\\)?-?(\\d{3})-(\\d{4})/ is the string",PHONE_pattern
+ ' is the string');
68 // testing conversion to int
69 testcases
[count
++] = new TestCase ( SECTION
, "SSN_pattern - 8",
72 var testPattern
= new RegExp("(\\d+)45(\\d+)90");
76 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
77 testcases
[tc
].passed
= writeTestCaseResult(
80 testcases
[tc
].description
+" = "+
81 testcases
[tc
].actual
);
82 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";