js/src/tests/js1_7/regress/regress-363040-01.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_7/regress/regress-363040-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +//-----------------------------------------------------------------------------
    1.10 +var BUGNUMBER = 363040;
    1.11 +var summary = 'Array.prototype.reduce, Array.prototype.reduceRight';
    1.12 +var actual = '';
    1.13 +var expect = '';
    1.14 +
    1.15 +
    1.16 +//-----------------------------------------------------------------------------
    1.17 +test();
    1.18 +//-----------------------------------------------------------------------------
    1.19 +
    1.20 +function test()
    1.21 +{
    1.22 +  enterFunc ('test');
    1.23 +  printBugNumber(BUGNUMBER);
    1.24 +  printStatus (summary);
    1.25 + 
    1.26 +  function f(x,y) { return '(' + x + '+' + y + ')';}
    1.27 +
    1.28 +  var testdesc;
    1.29 +  var arr0elms  = [];
    1.30 +  var arr1elms = [1];
    1.31 +  var arr2elms  = [1, 2];
    1.32 +
    1.33 +  testdesc = 'Test reduce of empty array without initializer.';
    1.34 +  try
    1.35 +  {
    1.36 +    expect = 'TypeError: reduce of empty array with no initial value';
    1.37 +    arr0elms.reduce(f);
    1.38 +  }
    1.39 +  catch(ex)
    1.40 +  {
    1.41 +    actual = ex + '';
    1.42 +  }
    1.43 +  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
    1.44 +
    1.45 +  testdesc = 'Test reduceRight of empty array without initializer.';
    1.46 +  try
    1.47 +  {
    1.48 +    expect = 'TypeError: reduce of empty array with no initial value';
    1.49 +    arr0elms.reduceRight(f);
    1.50 +  }
    1.51 +  catch(ex)
    1.52 +  {
    1.53 +    actual = ex + '';
    1.54 +  }
    1.55 +  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
    1.56 +
    1.57 +  testdesc = 'Test reduce of empty array with initial value.';
    1.58 +  expect = 'a';
    1.59 +  actual = arr0elms.reduce(f, 'a');
    1.60 +  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
    1.61 +
    1.62 +  testdesc = 'Test reduceRight of empty array with initial value.';
    1.63 +  expect = 'a';
    1.64 +  actual = arr0elms.reduceRight(f, 'a');
    1.65 +  reportCompare(expect + '', actual + '', testdesc +' : ' + expect);
    1.66 +
    1.67 +  testdesc = 'Test reduce of 1 element array with no initializer.';
    1.68 +  expect = '1';
    1.69 +  actual = arr1elms.reduce(f);
    1.70 +  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
    1.71 +
    1.72 +  testdesc = 'Test reduceRight of 1 element array with no initializer.';
    1.73 +  expect = '1';
    1.74 +  actual = arr1elms.reduceRight(f);
    1.75 +  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
    1.76 +
    1.77 +  testdesc = 'Test reduce of 2 element array with no initializer.';
    1.78 +  expect = '(1+2)';
    1.79 +  actual = arr2elms.reduce(f);
    1.80 +  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
    1.81 +
    1.82 +  testdesc = 'Test reduce of 2 element array with initializer.';
    1.83 +  expect = '((a+1)+2)';
    1.84 +  actual = arr2elms.reduce(f,'a');
    1.85 +  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
    1.86 +
    1.87 +  testdesc = 'Test reduceRight of 2 element array with no initializer.';
    1.88 +  expect = '(2+1)';
    1.89 +  actual = arr2elms.reduceRight(f);
    1.90 +  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
    1.91 +
    1.92 +  testdesc = 'Test reduceRight of 2 element array with no initializer.';
    1.93 +  expect = '((a+2)+1)';
    1.94 +  actual = arr2elms.reduceRight(f,'a');
    1.95 +  reportCompare(expect + '', actual + '', testdesc + ' : ' + expect);
    1.96 +
    1.97 +  exitFunc ('test');
    1.98 +}

mercurial