1/* ***** BEGIN LICENSE BLOCK ***** 2* Version: NPL 1.1/GPL 2.0/LGPL 2.1 3* 4* The contents of this file are subject to the Netscape Public License 5* Version 1.1 (the "License"); you may not use this file except in 6* compliance with the License. You may obtain a copy of the License at 7* http://www.mozilla.org/NPL/ 8* 9* Software distributed under the License is distributed on an "AS IS" basis, 10* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 11* for the specific language governing rights and limitations under the 12* License. 13* 14* The Original Code is JavaScript Engine testing utilities. 15* 16* The Initial Developer of the Original Code is Netscape Communications Corp. 17* Portions created by the Initial Developer are Copyright (C) 2002 18* the Initial Developer. All Rights Reserved. 19* 20* Contributor(s): rogerl@netscape.com, pschwartau@netscape.com 21* 22* Alternatively, the contents of this file may be used under the terms of 23* either the GNU General Public License Version 2 or later (the "GPL"), or 24* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 25* in which case the provisions of the GPL or the LGPL are applicable instead 26* of those above. If you wish to allow use of your version of this file only 27* under the terms of either the GPL or the LGPL, and not to allow others to 28* use your version of this file under the terms of the NPL, indicate your 29* decision by deleting the provisions above and replace them with the notice 30* and other provisions required by the GPL or the LGPL. If you do not delete 31* the provisions above, a recipient may use your version of this file under 32* the terms of any one of the NPL, the GPL or the LGPL. 33* 34* ***** END LICENSE BLOCK ***** 35* 36* 37* Date: 09 July 2002 38* SUMMARY: RegExp conformance test 39* 40* These testcases are derived from the examples in the ECMA-262 Ed.3 spec 41* scattered through section 15.10.2. 42* 43*/ 44//----------------------------------------------------------------------------- 45var i = 0; 46var bug = '(none)'; 47var summary = 'RegExp conformance test'; 48var status = ''; 49var statusmessages = new Array(); 50var pattern = ''; 51var patterns = new Array(); 52var string = ''; 53var strings = new Array(); 54var actualmatch = ''; 55var actualmatches = new Array(); 56var expectedmatch = ''; 57var expectedmatches = new Array(); 58 59 60status = inSection(1); 61pattern = /a|ab/; 62string = 'abc'; 63actualmatch = string.match(pattern); 64expectedmatch = Array('a'); 65addThis(); 66 67status = inSection(2); 68pattern = /((a)|(ab))((c)|(bc))/; 69string = 'abc'; 70actualmatch = string.match(pattern); 71expectedmatch = Array('abc', 'a', 'a', undefined, 'bc', undefined, 'bc'); 72addThis(); 73 74status = inSection(3); 75pattern = /a[a-z]{2,4}/; 76string = 'abcdefghi'; 77actualmatch = string.match(pattern); 78expectedmatch = Array('abcde'); 79addThis(); 80 81status = inSection(4); 82pattern = /a[a-z]{2,4}?/; 83string = 'abcdefghi'; 84actualmatch = string.match(pattern); 85expectedmatch = Array('abc'); 86addThis(); 87 88status = inSection(5); 89pattern = /(aa|aabaac|ba|b|c)*/; 90string = 'aabaac'; 91actualmatch = string.match(pattern); 92expectedmatch = Array('aaba', 'ba'); 93addThis(); 94 95status = inSection(6); 96pattern = /^(a+)\1*,\1+$/; 97string = 'aaaaaaaaaa,aaaaaaaaaaaaaaa'; 98actualmatch = string.match(pattern); 99expectedmatch = Array('aaaaaaaaaa,aaaaaaaaaaaaaaa', 'aaaaa'); 100addThis(); 101 102status = inSection(7); 103pattern = /(z)((a+)?(b+)?(c))*/; 104string = 'zaacbbbcac'; 105actualmatch = string.match(pattern); 106expectedmatch = Array('zaacbbbcac', 'z', 'ac', 'a', undefined, 'c'); 107addThis(); 108 109status = inSection(8); 110pattern = /(a*)*/; 111string = 'b'; 112actualmatch = string.match(pattern); 113expectedmatch = Array('', undefined); 114addThis(); 115 116status = inSection(9); 117pattern = /(a*)b\1+/; 118string = 'baaaac'; 119actualmatch = string.match(pattern); 120expectedmatch = Array('b', ''); 121addThis(); 122 123status = inSection(10); 124pattern = /(?=(a+))/; 125string = 'baaabac'; 126actualmatch = string.match(pattern); 127expectedmatch = Array('', 'aaa'); 128addThis(); 129 130status = inSection(11); 131pattern = /(?=(a+))a*b\1/; 132string = 'baaabac'; 133actualmatch = string.match(pattern); 134expectedmatch = Array('aba', 'a'); 135addThis(); 136 137status = inSection(12); 138pattern = /(.*?)a(?!(a+)b\2c)\2(.*)/; 139string = 'baaabaac'; 140actualmatch = string.match(pattern); 141expectedmatch = Array('baaabaac', 'ba', undefined, 'abaac'); 142addThis(); 143 144status = inSection(13); 145pattern = /(?=(a+))/; 146string = 'baaabac'; 147actualmatch = string.match(pattern); 148expectedmatch = Array('', 'aaa'); 149addThis(); 150 151 152 153//------------------------------------------------------------------------------------------------- 154test(); 155//------------------------------------------------------------------------------------------------- 156 157 158function addThis() 159{ 160 statusmessages[i] = status; 161 patterns[i] = pattern; 162 strings[i] = string; 163 actualmatches[i] = actualmatch; 164 expectedmatches[i] = expectedmatch; 165 i++; 166} 167 168 169function test() 170{ 171 enterFunc ('test'); 172 printBugNumber (bug); 173 printStatus (summary); 174 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches); 175 exitFunc ('test'); 176} 177