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: compile.js 24 Description: 'Tests regular expressions method compile' 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: compile'; 34 35 writeHeaderToLog('Executing script: compile.js'); 36 writeHeaderToLog( SECTION + " "+ TITLE); 37 38 var count = 0; 39 var testcases = new Array(); 40 41 var regularExpression = new RegExp(); 42 43 regularExpression.compile("[0-9]{3}x[0-9]{4}","i"); 44 45 testcases[count++] = new TestCase ( SECTION, 46 "(compile '[0-9]{3}x[0-9]{4}','i')", 47 String(["456X7890"]), String('234X456X7890'.match(regularExpression))); 48 49 testcases[count++] = new TestCase ( SECTION, 50 "source of (compile '[0-9]{3}x[0-9]{4}','i')", 51 "[0-9]{3}x[0-9]{4}", regularExpression.source); 52 53 testcases[count++] = new TestCase ( SECTION, 54 "global of (compile '[0-9]{3}x[0-9]{4}','i')", 55 false, regularExpression.global); 56 57 testcases[count++] = new TestCase ( SECTION, 58 "ignoreCase of (compile '[0-9]{3}x[0-9]{4}','i')", 59 true, regularExpression.ignoreCase); 60 61 regularExpression.compile("[0-9]{3}X[0-9]{3}","g"); 62 63 testcases[count++] = new TestCase ( SECTION, 64 "(compile '[0-9]{3}X[0-9]{3}','g')", 65 String(["234X456"]), String('234X456X7890'.match(regularExpression))); 66 67 testcases[count++] = new TestCase ( SECTION, 68 "source of (compile '[0-9]{3}X[0-9]{3}','g')", 69 "[0-9]{3}X[0-9]{3}", regularExpression.source); 70 71 testcases[count++] = new TestCase ( SECTION, 72 "global of (compile '[0-9]{3}X[0-9]{3}','g')", 73 true, regularExpression.global); 74 75 testcases[count++] = new TestCase ( SECTION, 76 "ignoreCase of (compile '[0-9]{3}X[0-9]{3}','g')", 77 false, regularExpression.ignoreCase); 78 79 80 function test() 81 { 82 for ( tc=0; tc < testcases.length; tc++ ) { 83 testcases[tc].passed = writeTestCaseResult( 84 testcases[tc].expect, 85 testcases[tc].actual, 86 testcases[tc].description +" = "+ 87 testcases[tc].actual ); 88 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; 89 } 90 stopTest(); 91 return ( testcases ); 92 } 93 94 test(); 95