Home | History | Annotate | Download | only in regexp
      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:     ignoreCase.js
     24 	Description:  'Tests RegExp attribute ignoreCase'
     25 
     26 	Author:       Nick Lerissa
     27 	Date:         March 13, 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: ignoreCase';
     34 
     35 	writeHeaderToLog('Executing script: ignoreCase.js');
     36 	writeHeaderToLog( SECTION + " "+ TITLE);
     37 
     38 	var count = 0;
     39 	var testcases = new Array();
     40 
     41     // /xyz/i.ignoreCase
     42 	testcases[count++] = new TestCase ( SECTION, "/xyz/i.ignoreCase",
     43 	                                    true, /xyz/i.ignoreCase);
     44 
     45     // /xyz/.ignoreCase
     46 	testcases[count++] = new TestCase ( SECTION, "/xyz/.ignoreCase",
     47 	                                    false, /xyz/.ignoreCase);
     48 
     49     // 'ABC def ghi'.match(/[a-z]+/ig)
     50 	testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(/[a-z]+/ig)",
     51 	                                    String(["ABC","def","ghi"]), String('ABC def ghi'.match(/[a-z]+/ig)));
     52 
     53     // 'ABC def ghi'.match(/[a-z]+/i)
     54 	testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(/[a-z]+/i)",
     55 	                                    String(["ABC"]), String('ABC def ghi'.match(/[a-z]+/i)));
     56 
     57     // 'ABC def ghi'.match(/([a-z]+)/ig)
     58 	testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(/([a-z]+)/ig)",
     59 	                                    String(["ABC","def","ghi"]), String('ABC def ghi'.match(/([a-z]+)/ig)));
     60 
     61     // 'ABC def ghi'.match(/([a-z]+)/i)
     62 	testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(/([a-z]+)/i)",
     63 	                                    String(["ABC","ABC"]), String('ABC def ghi'.match(/([a-z]+)/i)));
     64 
     65     // 'ABC def ghi'.match(/[a-z]+/)
     66 	testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(/[a-z]+/)",
     67 	                                    String(["def"]), String('ABC def ghi'.match(/[a-z]+/)));
     68 
     69     // (new RegExp('xyz','i')).ignoreCase
     70 	testcases[count++] = new TestCase ( SECTION, "(new RegExp('xyz','i')).ignoreCase",
     71 	                                    true, (new RegExp('xyz','i')).ignoreCase);
     72 
     73     // (new RegExp('xyz')).ignoreCase
     74 	testcases[count++] = new TestCase ( SECTION, "(new RegExp('xyz')).ignoreCase",
     75 	                                    false, (new RegExp('xyz')).ignoreCase);
     76 
     77     // 'ABC def ghi'.match(new RegExp('[a-z]+','ig'))
     78 	testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(new RegExp('[a-z]+','ig'))",
     79 	                                    String(["ABC","def","ghi"]), String('ABC def ghi'.match(new RegExp('[a-z]+','ig'))));
     80 
     81     // 'ABC def ghi'.match(new RegExp('[a-z]+','i'))
     82 	testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(new RegExp('[a-z]+','i'))",
     83 	                                    String(["ABC"]), String('ABC def ghi'.match(new RegExp('[a-z]+','i'))));
     84 
     85     // 'ABC def ghi'.match(new RegExp('([a-z]+)','ig'))
     86 	testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(new RegExp('([a-z]+)','ig'))",
     87 	                                    String(["ABC","def","ghi"]), String('ABC def ghi'.match(new RegExp('([a-z]+)','ig'))));
     88 
     89     // 'ABC def ghi'.match(new RegExp('([a-z]+)','i'))
     90 	testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(new RegExp('([a-z]+)','i'))",
     91 	                                    String(["ABC","ABC"]), String('ABC def ghi'.match(new RegExp('([a-z]+)','i'))));
     92 
     93     // 'ABC def ghi'.match(new RegExp('[a-z]+'))
     94 	testcases[count++] = new TestCase ( SECTION, "'ABC def ghi'.match(new RegExp('[a-z]+'))",
     95 	                                    String(["def"]), String('ABC def ghi'.match(new RegExp('[a-z]+'))));
     96 
     97 	function test()
     98 	{
     99 	   for ( tc=0; tc < testcases.length; tc++ ) {
    100 	        testcases[tc].passed = writeTestCaseResult(
    101 	        testcases[tc].expect,
    102 	        testcases[tc].actual,
    103 	        testcases[tc].description +" = "+
    104 	        testcases[tc].actual );
    105 	        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
    106 	   }
    107 	   stopTest();
    108 	   return ( testcases );
    109 	}
    110 
    111 	test();
    112