|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 |
|
7 /** |
|
8 Filename: RegExp_object.js |
|
9 Description: 'Tests regular expressions creating RexExp Objects' |
|
10 |
|
11 Author: Nick Lerissa |
|
12 Date: March 10, 1998 |
|
13 */ |
|
14 |
|
15 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; |
|
16 var VERSION = 'no version'; |
|
17 startTest(); |
|
18 var TITLE = 'RegExp: object'; |
|
19 |
|
20 writeHeaderToLog('Executing script: RegExp_object.js'); |
|
21 writeHeaderToLog( SECTION + " "+ TITLE); |
|
22 |
|
23 var SSN_pattern = new RegExp("\\d{3}-\\d{2}-\\d{4}"); |
|
24 |
|
25 // testing SSN pattern |
|
26 new TestCase ( SECTION, "'Test SSN is 123-34-4567'.match(SSN_pattern))", |
|
27 String(["123-34-4567"]), String('Test SSN is 123-34-4567'.match(SSN_pattern))); |
|
28 |
|
29 // testing SSN pattern |
|
30 new TestCase ( SECTION, "'Test SSN is 123-34-4567'.match(SSN_pattern))", |
|
31 String(["123-34-4567"]), String('Test SSN is 123-34-4567'.match(SSN_pattern))); |
|
32 |
|
33 var PHONE_pattern = new RegExp("\\(?(\\d{3})\\)?-?(\\d{3})-(\\d{4})"); |
|
34 // testing PHONE pattern |
|
35 new TestCase ( SECTION, "'Our phone number is (408)345-2345.'.match(PHONE_pattern))", |
|
36 String(["(408)345-2345","408","345","2345"]), String('Our phone number is (408)345-2345.'.match(PHONE_pattern))); |
|
37 |
|
38 // testing PHONE pattern |
|
39 new TestCase ( SECTION, "'The phone number is 408-345-2345!'.match(PHONE_pattern))", |
|
40 String(["408-345-2345","408","345","2345"]), String('The phone number is 408-345-2345!'.match(PHONE_pattern))); |
|
41 |
|
42 // testing PHONE pattern |
|
43 new TestCase ( SECTION, "String(PHONE_pattern.toString())", |
|
44 "/\\(?(\\d{3})\\)?-?(\\d{3})-(\\d{4})/", String(PHONE_pattern.toString())); |
|
45 |
|
46 // testing conversion to String |
|
47 new TestCase ( SECTION, "PHONE_pattern + ' is the string'", |
|
48 "/\\(?(\\d{3})\\)?-?(\\d{3})-(\\d{4})/ is the string",PHONE_pattern + ' is the string'); |
|
49 |
|
50 // testing conversion to int |
|
51 new TestCase ( SECTION, "SSN_pattern - 8", |
|
52 NaN,SSN_pattern - 8); |
|
53 |
|
54 var testPattern = new RegExp("(\\d+)45(\\d+)90"); |
|
55 |
|
56 test(); |