michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * michael@0: * Date: 13 Sep 2002 michael@0: * SUMMARY: Testing F.toString() michael@0: * See http://bugzilla.mozilla.org/show_bug.cgi?id=168347 michael@0: * michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var UBound = 0; michael@0: var BUGNUMBER = 168347; michael@0: var summary = "Testing F.toString()"; michael@0: var status = ''; michael@0: var statusitems = []; michael@0: var actual = ''; michael@0: var actualvalues = []; michael@0: var expect= ''; michael@0: var expectedvalues = []; michael@0: var FtoString = ''; michael@0: var sFunc = ''; michael@0: michael@0: sFunc += 'function F()'; michael@0: sFunc += '{'; michael@0: sFunc += ' var f = arguments.callee;'; michael@0: sFunc += ' f.i = 0;'; michael@0: sFunc += ''; michael@0: sFunc += ' try'; michael@0: sFunc += ' {'; michael@0: sFunc += ' f.i = f.i + 1;'; michael@0: sFunc += ' print("i = i+1 succeeded \ti = " + f.i);'; michael@0: sFunc += ' }'; michael@0: sFunc += ' catch(e)'; michael@0: sFunc += ' {'; michael@0: sFunc += ' print("i = i+1 failed with " + e + "\ti = " + f.i);'; michael@0: sFunc += ' }'; michael@0: sFunc += ''; michael@0: sFunc += ' try'; michael@0: sFunc += ' {'; michael@0: sFunc += ' ++f.i;'; michael@0: sFunc += ' print("++i succeeded \t\ti = " + f.i);'; michael@0: sFunc += ' }'; michael@0: sFunc += ' catch(e)'; michael@0: sFunc += ' {'; michael@0: sFunc += ' print("++i failed with " + e + "\ti = " + f.i);'; michael@0: sFunc += ' }'; michael@0: sFunc += ''; michael@0: sFunc += ' try'; michael@0: sFunc += ' {'; michael@0: sFunc += ' f.i++;'; michael@0: sFunc += ' print("i++ succeeded \t\ti = " + f.i);'; michael@0: sFunc += ' }'; michael@0: sFunc += ' catch(e)'; michael@0: sFunc += ' {'; michael@0: sFunc += ' print("i++ failed with " + e + "\ti = " + f.i);'; michael@0: sFunc += ' }'; michael@0: sFunc += ''; michael@0: sFunc += ' try'; michael@0: sFunc += ' {'; michael@0: sFunc += ' --f.i;'; michael@0: sFunc += ' print("--i succeeded \t\ti = " + f.i);'; michael@0: sFunc += ' }'; michael@0: sFunc += ' catch(e)'; michael@0: sFunc += ' {'; michael@0: sFunc += ' print("--i failed with " + e + "\ti = " + f.i);'; michael@0: sFunc += ' }'; michael@0: sFunc += ''; michael@0: sFunc += ' try'; michael@0: sFunc += ' {'; michael@0: sFunc += ' f.i--;'; michael@0: sFunc += ' print("i-- succeeded \t\ti = " + f.i);'; michael@0: sFunc += ' }'; michael@0: sFunc += ' catch(e)'; michael@0: sFunc += ' {'; michael@0: sFunc += ' print("i-- failed with " + e + "\ti = " + f.i);'; michael@0: sFunc += ' }'; michael@0: sFunc += '}'; michael@0: michael@0: michael@0: /* michael@0: * Use sFunc to define the function F. The test michael@0: * then rests on comparing F.toString() to sFunc. michael@0: */ michael@0: eval(sFunc); michael@0: michael@0: michael@0: /* michael@0: * There are trivial whitespace differences between F.toString() michael@0: * and sFunc. So strip out whitespace before comparing them - michael@0: */ michael@0: sFunc = stripWhite(sFunc); michael@0: FtoString = stripWhite(F.toString()); michael@0: michael@0: michael@0: /* michael@0: * Break comparison into sections to make any failures michael@0: * easier for the developer to track down - michael@0: */ michael@0: status = inSection(1); michael@0: actual = FtoString.substring(0,100); michael@0: expect = sFunc.substring(0,100); michael@0: addThis(); michael@0: michael@0: status = inSection(2); michael@0: actual = FtoString.substring(100,200); michael@0: expect = sFunc.substring(100,200); michael@0: addThis(); michael@0: michael@0: status = inSection(3); michael@0: actual = FtoString.substring(200,300); michael@0: expect = sFunc.substring(200,300); michael@0: addThis(); michael@0: michael@0: status = inSection(4); michael@0: actual = FtoString.substring(300,400); michael@0: expect = sFunc.substring(300,400); michael@0: addThis(); michael@0: michael@0: status = inSection(5); michael@0: actual = FtoString.substring(400,500); michael@0: expect = sFunc.substring(400,500); michael@0: addThis(); michael@0: michael@0: status = inSection(6); michael@0: actual = FtoString.substring(500,600); michael@0: expect = sFunc.substring(500,600); michael@0: addThis(); michael@0: michael@0: status = inSection(7); michael@0: actual = FtoString.substring(600,700); michael@0: expect = sFunc.substring(600,700); michael@0: addThis(); michael@0: michael@0: status = inSection(8); michael@0: actual = FtoString.substring(700,800); michael@0: expect = sFunc.substring(700,800); michael@0: addThis(); michael@0: michael@0: status = inSection(9); michael@0: actual = FtoString.substring(800,900); michael@0: expect = sFunc.substring(800,900); michael@0: addThis(); michael@0: michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: michael@0: michael@0: function addThis() michael@0: { michael@0: statusitems[UBound] = status; michael@0: actualvalues[UBound] = actual; michael@0: expectedvalues[UBound] = expect; michael@0: UBound++; michael@0: } michael@0: michael@0: /* michael@0: * Remove any whitespace characters; also michael@0: * any escaped tabs or escaped newlines. michael@0: */ michael@0: function stripWhite(str) michael@0: { michael@0: var re = /\s|\\t|\\n/g; michael@0: return str.replace(re, ''); michael@0: } michael@0: michael@0: michael@0: function test() michael@0: { michael@0: enterFunc('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus(summary); michael@0: michael@0: for (var i=0; i