tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

regress-168347.js (4211B)


      1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 /*
      7 *
      8 * Date:    13 Sep 2002
      9 * SUMMARY: Testing F.toString()
     10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=168347
     11 *
     12 */
     13 //-----------------------------------------------------------------------------
     14 var UBound = 0;
     15 var BUGNUMBER = 168347;
     16 var summary = "Testing F.toString()";
     17 var status = '';
     18 var statusitems = [];
     19 var actual = '';
     20 var actualvalues = [];
     21 var expect= '';
     22 var expectedvalues = [];
     23 var FtoString = '';
     24 var sFunc = '';
     25 
     26 sFunc += 'function F()';
     27 sFunc += '{';
     28 sFunc += '  var f = arguments.callee;';
     29 sFunc += '  f.i = 0;';
     30 sFunc += '';
     31 sFunc += '  try';
     32 sFunc += '  {';
     33 sFunc += '    f.i = f.i + 1;';
     34 sFunc += '    print("i = i+1 succeeded \ti = " + f.i);';
     35 sFunc += '  }';
     36 sFunc += '  catch(e)';
     37 sFunc += '  {';
     38 sFunc += '    print("i = i+1 failed with " + e + "\ti = " + f.i);';
     39 sFunc += '  }';
     40 sFunc += '';
     41 sFunc += '  try';
     42 sFunc += '  {';
     43 sFunc += '    ++f.i;';
     44 sFunc += '    print("++i succeeded \t\ti = " + f.i);';
     45 sFunc += '  }';
     46 sFunc += '  catch(e)';
     47 sFunc += '  {';
     48 sFunc += '    print("++i failed with " + e + "\ti = " + f.i);';
     49 sFunc += '  }';
     50 sFunc += '';
     51 sFunc += '  try';
     52 sFunc += '  {';
     53 sFunc += '    f.i++;';
     54 sFunc += '    print("i++ succeeded \t\ti = " + f.i);';
     55 sFunc += '  }';
     56 sFunc += '  catch(e)';
     57 sFunc += '  {';
     58 sFunc += '    print("i++ failed with " + e + "\ti = " + f.i);';
     59 sFunc += '  }';
     60 sFunc += '';
     61 sFunc += '  try';
     62 sFunc += '  {';
     63 sFunc += '    --f.i;';
     64 sFunc += '    print("--i succeeded \t\ti = " + f.i);';
     65 sFunc += '  }';
     66 sFunc += '  catch(e)';
     67 sFunc += '  {';
     68 sFunc += '    print("--i failed with " + e + "\ti = " + f.i);';
     69 sFunc += '  }';
     70 sFunc += '';
     71 sFunc += '  try';
     72 sFunc += '  {';
     73 sFunc += '    f.i--;';
     74 sFunc += '    print("i-- succeeded \t\ti = " + f.i);';
     75 sFunc += '  }';
     76 sFunc += '  catch(e)';
     77 sFunc += '  {';
     78 sFunc += '    print("i-- failed with " + e + "\ti = " + f.i);';
     79 sFunc += '  }';
     80 sFunc += '}';
     81 
     82 
     83 /*
     84 * Use sFunc to define the function F. The test
     85 * then rests on comparing F.toString() to sFunc.
     86 */
     87 eval(sFunc);
     88 
     89 
     90 /*
     91 * There are trivial whitespace differences between F.toString()
     92 * and sFunc. So strip out whitespace before comparing them -
     93 */
     94 sFunc = stripWhite(sFunc);
     95 FtoString = stripWhite(F.toString());
     96 
     97 
     98 /*
     99 * Break comparison into sections to make any failures
    100 * easier for the developer to track down -
    101 */
    102 status = inSection(1);
    103 actual = FtoString.substring(0,100);
    104 expect = sFunc.substring(0,100);
    105 addThis();
    106 
    107 status = inSection(2);
    108 actual = FtoString.substring(100,200);
    109 expect = sFunc.substring(100,200);
    110 addThis();
    111 
    112 status = inSection(3);
    113 actual = FtoString.substring(200,300);
    114 expect = sFunc.substring(200,300);
    115 addThis();
    116 
    117 status = inSection(4);
    118 actual = FtoString.substring(300,400);
    119 expect = sFunc.substring(300,400);
    120 addThis();
    121 
    122 status = inSection(5);
    123 actual = FtoString.substring(400,500);
    124 expect = sFunc.substring(400,500);
    125 addThis();
    126 
    127 status = inSection(6);
    128 actual = FtoString.substring(500,600);
    129 expect = sFunc.substring(500,600);
    130 addThis();
    131 
    132 status = inSection(7);
    133 actual = FtoString.substring(600,700);
    134 expect = sFunc.substring(600,700);
    135 addThis();
    136 
    137 status = inSection(8);
    138 actual = FtoString.substring(700,800);
    139 expect = sFunc.substring(700,800);
    140 addThis();
    141 
    142 status = inSection(9);
    143 actual = FtoString.substring(800,900);
    144 expect = sFunc.substring(800,900);
    145 addThis();
    146 
    147 
    148 
    149 //-----------------------------------------------------------------------------
    150 test();
    151 //-----------------------------------------------------------------------------
    152 
    153 
    154 
    155 function addThis()
    156 {
    157  statusitems[UBound] = status;
    158  actualvalues[UBound] = actual;
    159  expectedvalues[UBound] = expect;
    160  UBound++;
    161 }
    162 
    163 /*
    164 * Remove any whitespace characters; also
    165 * any escaped tabs or escaped newlines.
    166 */
    167 function stripWhite(str)
    168 {
    169  var re = /\s|\\t|\\n/g;
    170  return str.replace(re, '');
    171 }
    172 
    173 
    174 function test()
    175 {
    176  printBugNumber(BUGNUMBER);
    177  printStatus(summary);
    178 
    179  for (var i=0; i<UBound; i++)
    180  {
    181    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    182  }
    183 }