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:     question_mark.js
     24 	Description:  'Tests regular expressions containing ?'
     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: ?';
     34 
     35 	writeHeaderToLog('Executing script: question_mark.js');
     36 	writeHeaderToLog( SECTION + " "+ TITLE);
     37 
     38 	var count = 0;
     39 	var testcases = new Array();
     40 
     41     // 'abcdef'.match(new RegExp('cd?e'))
     42 	testcases[count++] = new TestCase ( SECTION, "'abcdef'.match(new RegExp('cd?e'))",
     43 	                                    String(["cde"]), String('abcdef'.match(new RegExp('cd?e'))));
     44 
     45     // 'abcdef'.match(new RegExp('cdx?e'))
     46 	testcases[count++] = new TestCase ( SECTION, "'abcdef'.match(new RegExp('cdx?e'))",
     47 	                                    String(["cde"]), String('abcdef'.match(new RegExp('cdx?e'))));
     48 
     49     // 'pqrstuvw'.match(new RegExp('o?pqrst'))
     50 	testcases[count++] = new TestCase ( SECTION, "'pqrstuvw'.match(new RegExp('o?pqrst'))",
     51 	                                    String(["pqrst"]), String('pqrstuvw'.match(new RegExp('o?pqrst'))));
     52 
     53     // 'abcd'.match(new RegExp('x?y?z?'))
     54 	testcases[count++] = new TestCase ( SECTION, "'abcd'.match(new RegExp('x?y?z?'))",
     55 	                                    String([""]), String('abcd'.match(new RegExp('x?y?z?'))));
     56 
     57     // 'abcd'.match(new RegExp('x?ay?bz?c'))
     58 	testcases[count++] = new TestCase ( SECTION, "'abcd'.match(new RegExp('x?ay?bz?c'))",
     59 	                                    String(["abc"]), String('abcd'.match(new RegExp('x?ay?bz?c'))));
     60 
     61     // 'abcd'.match(/x?ay?bz?c/)
     62 	testcases[count++] = new TestCase ( SECTION, "'abcd'.match(/x?ay?bz?c/)",
     63 	                                    String(["abc"]), String('abcd'.match(/x?ay?bz?c/)));
     64 
     65     // 'abbbbc'.match(new RegExp('b?b?b?b'))
     66 	testcases[count++] = new TestCase ( SECTION, "'abbbbc'.match(new RegExp('b?b?b?b'))",
     67 	                                    String(["bbbb"]), String('abbbbc'.match(new RegExp('b?b?b?b'))));
     68 
     69     // '123az789'.match(new RegExp('ab?c?d?x?y?z'))
     70 	testcases[count++] = new TestCase ( SECTION, "'123az789'.match(new RegExp('ab?c?d?x?y?z'))",
     71 	                                    String(["az"]), String('123az789'.match(new RegExp('ab?c?d?x?y?z'))));
     72 
     73     // '123az789'.match(/ab?c?d?x?y?z/)
     74 	testcases[count++] = new TestCase ( SECTION, "'123az789'.match(/ab?c?d?x?y?z/)",
     75 	                                    String(["az"]), String('123az789'.match(/ab?c?d?x?y?z/)));
     76 
     77     // '?????'.match(new RegExp('\\??\\??\\??\\??\\??'))
     78 	testcases[count++] = new TestCase ( SECTION, "'?????'.match(new RegExp('\\??\\??\\??\\??\\??'))",
     79 	                                    String(["?????"]), String('?????'.match(new RegExp('\\??\\??\\??\\??\\??'))));
     80 
     81     // 'test'.match(new RegExp('.?.?.?.?.?.?.?'))
     82 	testcases[count++] = new TestCase ( SECTION, "'test'.match(new RegExp('.?.?.?.?.?.?.?'))",
     83 	                                    String(["test"]), String('test'.match(new RegExp('.?.?.?.?.?.?.?'))));
     84 
     85 	function test()
     86 	{
     87 	   for ( tc=0; tc < testcases.length; tc++ ) {
     88 	        testcases[tc].passed = writeTestCaseResult(
     89 	        testcases[tc].expect,
     90 	        testcases[tc].actual,
     91 	        testcases[tc].description +" = "+
     92 	        testcases[tc].actual );
     93 	        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
     94 	   }
     95 	   stopTest();
     96 	   return ( testcases );
     97 	}
     98 
     99 	test();
    100