tor-browser

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

regress-363040-01.js (2994B)


      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 var BUGNUMBER = 363040;
      8 var summary = 'Array.prototype.reduce, Array.prototype.reduceRight';
      9 var actual = '';
     10 var expect = '';
     11 
     12 
     13 //-----------------------------------------------------------------------------
     14 test();
     15 //-----------------------------------------------------------------------------
     16 
     17 function test()
     18 {
     19  printBugNumber(BUGNUMBER);
     20  printStatus (summary);
     21 
     22  function f(x,y) { return '(' + x + '+' + y + ')';}
     23 
     24  var testdesc;
     25  var arr0elms  = [];
     26  var arr1elms = [1];
     27  var arr2elms  = [1, 2];
     28 
     29  testdesc = 'Test reduce of empty array without initializer.';
     30  try
     31  {
     32    expect = 'TypeError: reduce of empty array with no initial value';
     33    arr0elms.reduce(f);
     34  }
     35  catch(ex)
     36  {
     37    actual = ex + '';
     38  }
     39  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
     40 
     41  testdesc = 'Test reduceRight of empty array without initializer.';
     42  try
     43  {
     44    expect = 'TypeError: reduce of empty array with no initial value';
     45    arr0elms.reduceRight(f);
     46  }
     47  catch(ex)
     48  {
     49    actual = ex + '';
     50  }
     51  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
     52 
     53  testdesc = 'Test reduce of empty array with initial value.';
     54  expect = 'a';
     55  actual = arr0elms.reduce(f, 'a');
     56  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
     57 
     58  testdesc = 'Test reduceRight of empty array with initial value.';
     59  expect = 'a';
     60  actual = arr0elms.reduceRight(f, 'a');
     61  reportCompare(expect + '', actual + '', testdesc +' : ' + expect);
     62 
     63  testdesc = 'Test reduce of 1 element array with no initializer.';
     64  expect = '1';
     65  actual = arr1elms.reduce(f);
     66  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
     67 
     68  testdesc = 'Test reduceRight of 1 element array with no initializer.';
     69  expect = '1';
     70  actual = arr1elms.reduceRight(f);
     71  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
     72 
     73  testdesc = 'Test reduce of 2 element array with no initializer.';
     74  expect = '(1+2)';
     75  actual = arr2elms.reduce(f);
     76  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
     77 
     78  testdesc = 'Test reduce of 2 element array with initializer.';
     79  expect = '((a+1)+2)';
     80  actual = arr2elms.reduce(f,'a');
     81  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
     82 
     83  testdesc = 'Test reduceRight of 2 element array with no initializer.';
     84  expect = '(2+1)';
     85  actual = arr2elms.reduceRight(f);
     86  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
     87 
     88  testdesc = 'Test reduceRight of 2 element array with no initializer.';
     89  expect = '((a+2)+1)';
     90  actual = arr2elms.reduceRight(f,'a');
     91  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
     92 }