js/src/tests/js1_2/Array/splice2.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
     7 /**
     8    Filename:     splice2.js
     9    Description:  'Tests Array.splice(x,y) w/4 var args'
    11    Author:       Nick Lerissa
    12    Date:         Fri Feb 13 09:58:28 PST 1998
    13 */
    15 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
    16 var VERSION = 'no version';
    17 var TITLE = 'String:splice 2';
    18 var BUGNUMBER="123795";
    20 startTest();
    21 writeHeaderToLog('Executing script: splice2.js');
    22 writeHeaderToLog( SECTION + " "+ TITLE);
    24 var a = ['a','test string',456,9.34,new String("string object"),[],['h','i','j','k']];
    25 var b = [1,2,3,4,5,6,7,8,9,0];
    27 exhaustiveSpliceTestWithArgs("exhaustive splice w/2 optional args 1",a);
    28 exhaustiveSpliceTestWithArgs("exhaustive splice w/2 optional args 2",b);
    30 test();
    33 function mySplice(testArray, splicedArray, first, len, elements)
    34 {
    35   var removedArray  = [];
    36   var adjustedFirst = first;
    37   var adjustedLen   = len;
    39   if (adjustedFirst < 0) adjustedFirst = testArray.length + first;
    40   if (adjustedFirst < 0) adjustedFirst = 0;
    42   if (adjustedLen < 0) adjustedLen = 0;
    44   for (i = 0; (i < adjustedFirst)&&(i < testArray.length); ++i)
    45     splicedArray.push(testArray[i]);
    47   if (adjustedFirst < testArray.length)
    48     for (i = adjustedFirst; (i < adjustedFirst + adjustedLen) && (i < testArray.length); ++i)
    49       removedArray.push(testArray[i]);
    51   for (i = 0; i < elements.length; i++) splicedArray.push(elements[i]);
    53   for (i = adjustedFirst + adjustedLen; i < testArray.length; i++)
    54     splicedArray.push(testArray[i]);
    56   return removedArray;
    57 }
    59 function exhaustiveSpliceTestWithArgs(testname, testArray)
    60 {
    61   var passed = true;
    62   var errorMessage;
    63   var reason = "";
    64   for (var first = -(testArray.length+2); first <= 2 + testArray.length; first++)
    65   {
    66     var actualSpliced   = [];
    67     var expectedSpliced = [];
    68     var actualRemoved   = [];
    69     var expectedRemoved = [];
    71     for (var len = 0; len < testArray.length + 2; len++)
    72     {
    73       actualSpliced   = [];
    74       expectedSpliced = [];
    76       for (var i = 0; i < testArray.length; ++i)
    77 	actualSpliced.push(testArray[i]);
    79       actualRemoved   = actualSpliced.splice(first,len,-97,new String("test arg"),[],9.8);
    80       expectedRemoved = mySplice(testArray,expectedSpliced,first,len,[-97,new String("test arg"),[],9.8]);
    82       var adjustedFirst = first;
    83       if (adjustedFirst < 0) adjustedFirst = testArray.length + first;
    84       if (adjustedFirst < 0) adjustedFirst = 0;
    87       if (  (String(actualSpliced) != String(expectedSpliced))
    88 	    ||(String(actualRemoved) != String(expectedRemoved)))
    89       {
    90 	if (  (String(actualSpliced) == String(expectedSpliced))
    91 	      &&(String(actualRemoved) != String(expectedRemoved)) )
    92 	{
    94 	  if ( (expectedRemoved.length == 1)
    95 	       &&(String(actualRemoved) == String(expectedRemoved[0]))) continue;
    96 	  if ( expectedRemoved.length == 0  && actualRemoved == void 0 ) continue;
    97 	}
    99 	errorMessage =
   100 	  "ERROR: 'TEST FAILED' ERROR: 'TEST FAILED' ERROR: 'TEST FAILED'\n" +
   101 	  "             test: " + "a.splice(" + first + "," + len + ",-97,new String('test arg'),[],9.8)\n" +
   102 	  "                a: " + String(testArray) + "\n" +
   103 	  "   actual spliced: " + String(actualSpliced) + "\n" +
   104 	  " expected spliced: " + String(expectedSpliced) + "\n" +
   105 	  "   actual removed: " + String(actualRemoved) + "\n" +
   106 	  " expected removed: " + String(expectedRemoved);
   107 	reason = reason + errorMessage;
   108 	writeHeaderToLog(errorMessage);
   109 	passed = false;
   110       }
   111     }
   112   }
   113   var testcase = new TestCase(SECTION, testname, true, passed);
   114   if (!passed) testcase.reason = reason;
   115   return testcase;
   116 }

mercurial