]>
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: RegExp_object.js | |
24 | Description: 'Tests regular expressions creating RexExp Objects' | |
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: object'; | |
34 | ||
35 | writeHeaderToLog('Executing script: RegExp_object.js'); | |
36 | writeHeaderToLog( SECTION + " "+ TITLE); | |
37 | ||
38 | var count = 0; | |
39 | var testcases = new Array(); | |
40 | ||
41 | var SSN_pattern = new RegExp("\\d{3}-\\d{2}-\\d{4}"); | |
42 | ||
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))); | |
46 | ||
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))); | |
50 | ||
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))); | |
55 | ||
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))); | |
59 | ||
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())); | |
63 | ||
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'); | |
67 | ||
68 | // testing conversion to int | |
69 | testcases[count++] = new TestCase ( SECTION, "SSN_pattern - 8", | |
70 | NaN,SSN_pattern - 8); | |
71 | ||
72 | var testPattern = new RegExp("(\\d+)45(\\d+)90"); | |
73 | ||
74 | function test() | |
75 | { | |
76 | for ( tc=0; tc < testcases.length; tc++ ) { | |
77 | testcases[tc].passed = writeTestCaseResult( | |
78 | testcases[tc].expect, | |
79 | testcases[tc].actual, | |
80 | testcases[tc].description +" = "+ | |
81 | testcases[tc].actual ); | |
82 | testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; | |
83 | } | |
84 | stopTest(); | |
85 | return ( testcases ); | |
86 | } | |
87 | ||
88 | test(); |