js/src/tests/js1_2/Array/splice1.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:     splice1.js
     9    Description:  'Tests Array.splice(x,y) w/no 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 1';
    18 var BUGNUMBER="123795";
    20 startTest();
    21 writeHeaderToLog('Executing script: splice1.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 exhaustiveSpliceTest("exhaustive splice w/no optional args 1",a);
    28 exhaustiveSpliceTest("exhaustive splice w/no optional args 1",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) &&
    49 	   (i < testArray.length); ++i)
    50     {
    51       removedArray.push(testArray[i]);
    52     }
    54   for (i = 0; i < elements.length; i++) splicedArray.push(elements[i]);
    56   for (i = adjustedFirst + adjustedLen; i < testArray.length; i++)
    57     splicedArray.push(testArray[i]);
    59   return removedArray;
    60 }
    62 function exhaustiveSpliceTest(testname, testArray)
    63 {
    64   var errorMessage;
    65   var passed = true;
    66   var reason = "";
    68   for (var first = -(testArray.length+2); first <= 2 + testArray.length; first++)
    69   {
    70     var actualSpliced   = [];
    71     var expectedSpliced = [];
    72     var actualRemoved   = [];
    73     var expectedRemoved = [];
    75     for (var len = 0; len < testArray.length + 2; len++)
    76     {
    77       actualSpliced   = [];
    78       expectedSpliced = [];
    80       for (var i = 0; i < testArray.length; ++i)
    81 	actualSpliced.push(testArray[i]);
    83       actualRemoved   = actualSpliced.splice(first,len);
    84       expectedRemoved = mySplice(testArray,expectedSpliced,first,len,[]);
    86       var adjustedFirst = first;
    87       if (adjustedFirst < 0) adjustedFirst = testArray.length + first;
    88       if (adjustedFirst < 0) adjustedFirst = 0;
    90       if (  (String(actualSpliced) != String(expectedSpliced))
    91 	    ||(String(actualRemoved) != String(expectedRemoved)))
    92       {
    93 	if (  (String(actualSpliced) == String(expectedSpliced))
    94 	      &&(String(actualRemoved) != String(expectedRemoved)) )
    95 	{
    96 	  if ( (expectedRemoved.length == 1)
    97 	       &&(String(actualRemoved) == String(expectedRemoved[0]))) continue;
    98 	  if ( expectedRemoved.length == 0 && actualRemoved == void 0) continue;
    99 	}
   101 	errorMessage =
   102 	  "ERROR: 'TEST FAILED'\n" +
   103 	  "             test: " + "a.splice(" + first + "," + len + ",-97,new String('test arg'),[],9.8)\n" +
   104 	  "                a: " + String(testArray) + "\n" +
   105 	  "   actual spliced: " + String(actualSpliced) + "\n" +
   106 	  " expected spliced: " + String(expectedSpliced) + "\n" +
   107 	  "   actual removed: " + String(actualRemoved) + "\n" +
   108 	  " expected removed: " + String(expectedRemoved) + "\n";
   109 	writeHeaderToLog(errorMessage);
   110 	reason = reason + errorMessage;
   111 	passed = false;
   112       }
   113     }
   114   }
   115   var testcase = new TestCase( SECTION, testname, true, passed);
   116   if (!passed)
   117     testcase.reason = reason;
   118   return testcase;
   119 }

mercurial