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): desale@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: 13 Sep 2002 38* SUMMARY: Testing F.toString() 39* See http://bugzilla.mozilla.org/show_bug.cgi?id=168347 40* 41*/ 42//----------------------------------------------------------------------------- 43var UBound = 0; 44var bug = 168347; 45var summary = "Testing F.toString()"; 46var status = ''; 47var statusitems = []; 48var actual = ''; 49var actualvalues = []; 50var expect= ''; 51var expectedvalues = []; 52var FtoString = ''; 53var sFunc = ''; 54 55sFunc += 'function F()'; 56sFunc += '{'; 57sFunc += ' var f = arguments.callee;'; 58sFunc += ' f.i = 0;'; 59sFunc += ''; 60sFunc += ' try'; 61sFunc += ' {'; 62sFunc += ' f.i = f.i + 1;'; 63sFunc += ' print("i = i+1 succeeded \ti = " + f.i);'; 64sFunc += ' }'; 65sFunc += ' catch(e)'; 66sFunc += ' {'; 67sFunc += ' print("i = i+1 failed with " + e + "\ti = " + f.i);'; 68sFunc += ' }'; 69sFunc += ''; 70sFunc += ' try'; 71sFunc += ' {'; 72sFunc += ' ++f.i;'; 73sFunc += ' print("++i succeeded \t\ti = " + f.i);'; 74sFunc += ' }'; 75sFunc += ' catch(e)'; 76sFunc += ' {'; 77sFunc += ' print("++i failed with " + e + "\ti = " + f.i);'; 78sFunc += ' }'; 79sFunc += ''; 80sFunc += ' try'; 81sFunc += ' {'; 82sFunc += ' f.i++;'; 83sFunc += ' print("i++ succeeded \t\ti = " + f.i);'; 84sFunc += ' }'; 85sFunc += ' catch(e)'; 86sFunc += ' {'; 87sFunc += ' print("i++ failed with " + e + "\ti = " + f.i);'; 88sFunc += ' }'; 89sFunc += ''; 90sFunc += ' try'; 91sFunc += ' {'; 92sFunc += ' --f.i;'; 93sFunc += ' print("--i succeeded \t\ti = " + f.i);'; 94sFunc += ' }'; 95sFunc += ' catch(e)'; 96sFunc += ' {'; 97sFunc += ' print("--i failed with " + e + "\ti = " + f.i);'; 98sFunc += ' }'; 99sFunc += ''; 100sFunc += ' try'; 101sFunc += ' {'; 102sFunc += ' f.i--;'; 103sFunc += ' print("i-- succeeded \t\ti = " + f.i);'; 104sFunc += ' }'; 105sFunc += ' catch(e)'; 106sFunc += ' {'; 107sFunc += ' print("i-- failed with " + e + "\ti = " + f.i);'; 108sFunc += ' }'; 109sFunc += '}'; 110 111 112/* 113 * Use sFunc to define the function F. The test 114 * then rests on comparing F.toString() to sFunc. 115 */ 116eval(sFunc); 117 118 119/* 120 * There are trivial whitespace differences between F.toString() 121 * and sFunc. So strip out whitespace before comparing them - 122 */ 123sFunc = stripWhite(sFunc); 124FtoString = stripWhite(F.toString()); 125 126 127/* 128 * Break comparison into sections to make any failures 129 * easier for the developer to track down - 130 */ 131status = inSection(1); 132actual = FtoString.substring(0,100); 133expect = sFunc.substring(0,100); 134addThis(); 135 136status = inSection(2); 137actual = FtoString.substring(100,200); 138expect = sFunc.substring(100,200); 139addThis(); 140 141status = inSection(3); 142actual = FtoString.substring(200,300); 143expect = sFunc.substring(200,300); 144addThis(); 145 146status = inSection(4); 147actual = FtoString.substring(300,400); 148expect = sFunc.substring(300,400); 149addThis(); 150 151status = inSection(5); 152actual = FtoString.substring(400,500); 153expect = sFunc.substring(400,500); 154addThis(); 155 156status = inSection(6); 157actual = FtoString.substring(500,600); 158expect = sFunc.substring(500,600); 159addThis(); 160 161status = inSection(7); 162actual = FtoString.substring(600,700); 163expect = sFunc.substring(600,700); 164addThis(); 165 166status = inSection(8); 167actual = FtoString.substring(700,800); 168expect = sFunc.substring(700,800); 169addThis(); 170 171status = inSection(9); 172actual = FtoString.substring(800,900); 173expect = sFunc.substring(800,900); 174addThis(); 175 176 177 178//----------------------------------------------------------------------------- 179test(); 180//----------------------------------------------------------------------------- 181 182 183 184function addThis() 185{ 186 statusitems[UBound] = status; 187 actualvalues[UBound] = actual; 188 expectedvalues[UBound] = expect; 189 UBound++; 190} 191 192/* 193 * Remove any whitespace characters; also 194 * any escaped tabs or escaped newlines. 195 */ 196function stripWhite(str) 197{ 198 var re = /\s|\\t|\\n/g; 199 return str.replace(re, ''); 200} 201 202 203function test() 204{ 205 enterFunc('test'); 206 printBugNumber(bug); 207 printStatus(summary); 208 209 for (var i=0; i<UBound; i++) 210 { 211 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 212 } 213 214 exitFunc ('test'); 215} 216