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.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6
michael@0 7 /**
michael@0 8 Filename: splice2.js
michael@0 9 Description: 'Tests Array.splice(x,y) w/4 var args'
michael@0 10
michael@0 11 Author: Nick Lerissa
michael@0 12 Date: Fri Feb 13 09:58:28 PST 1998
michael@0 13 */
michael@0 14
michael@0 15 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
michael@0 16 var VERSION = 'no version';
michael@0 17 var TITLE = 'String:splice 2';
michael@0 18 var BUGNUMBER="123795";
michael@0 19
michael@0 20 startTest();
michael@0 21 writeHeaderToLog('Executing script: splice2.js');
michael@0 22 writeHeaderToLog( SECTION + " "+ TITLE);
michael@0 23
michael@0 24 var a = ['a','test string',456,9.34,new String("string object"),[],['h','i','j','k']];
michael@0 25 var b = [1,2,3,4,5,6,7,8,9,0];
michael@0 26
michael@0 27 exhaustiveSpliceTestWithArgs("exhaustive splice w/2 optional args 1",a);
michael@0 28 exhaustiveSpliceTestWithArgs("exhaustive splice w/2 optional args 2",b);
michael@0 29
michael@0 30 test();
michael@0 31
michael@0 32
michael@0 33 function mySplice(testArray, splicedArray, first, len, elements)
michael@0 34 {
michael@0 35 var removedArray = [];
michael@0 36 var adjustedFirst = first;
michael@0 37 var adjustedLen = len;
michael@0 38
michael@0 39 if (adjustedFirst < 0) adjustedFirst = testArray.length + first;
michael@0 40 if (adjustedFirst < 0) adjustedFirst = 0;
michael@0 41
michael@0 42 if (adjustedLen < 0) adjustedLen = 0;
michael@0 43
michael@0 44 for (i = 0; (i < adjustedFirst)&&(i < testArray.length); ++i)
michael@0 45 splicedArray.push(testArray[i]);
michael@0 46
michael@0 47 if (adjustedFirst < testArray.length)
michael@0 48 for (i = adjustedFirst; (i < adjustedFirst + adjustedLen) && (i < testArray.length); ++i)
michael@0 49 removedArray.push(testArray[i]);
michael@0 50
michael@0 51 for (i = 0; i < elements.length; i++) splicedArray.push(elements[i]);
michael@0 52
michael@0 53 for (i = adjustedFirst + adjustedLen; i < testArray.length; i++)
michael@0 54 splicedArray.push(testArray[i]);
michael@0 55
michael@0 56 return removedArray;
michael@0 57 }
michael@0 58
michael@0 59 function exhaustiveSpliceTestWithArgs(testname, testArray)
michael@0 60 {
michael@0 61 var passed = true;
michael@0 62 var errorMessage;
michael@0 63 var reason = "";
michael@0 64 for (var first = -(testArray.length+2); first <= 2 + testArray.length; first++)
michael@0 65 {
michael@0 66 var actualSpliced = [];
michael@0 67 var expectedSpliced = [];
michael@0 68 var actualRemoved = [];
michael@0 69 var expectedRemoved = [];
michael@0 70
michael@0 71 for (var len = 0; len < testArray.length + 2; len++)
michael@0 72 {
michael@0 73 actualSpliced = [];
michael@0 74 expectedSpliced = [];
michael@0 75
michael@0 76 for (var i = 0; i < testArray.length; ++i)
michael@0 77 actualSpliced.push(testArray[i]);
michael@0 78
michael@0 79 actualRemoved = actualSpliced.splice(first,len,-97,new String("test arg"),[],9.8);
michael@0 80 expectedRemoved = mySplice(testArray,expectedSpliced,first,len,[-97,new String("test arg"),[],9.8]);
michael@0 81
michael@0 82 var adjustedFirst = first;
michael@0 83 if (adjustedFirst < 0) adjustedFirst = testArray.length + first;
michael@0 84 if (adjustedFirst < 0) adjustedFirst = 0;
michael@0 85
michael@0 86
michael@0 87 if ( (String(actualSpliced) != String(expectedSpliced))
michael@0 88 ||(String(actualRemoved) != String(expectedRemoved)))
michael@0 89 {
michael@0 90 if ( (String(actualSpliced) == String(expectedSpliced))
michael@0 91 &&(String(actualRemoved) != String(expectedRemoved)) )
michael@0 92 {
michael@0 93
michael@0 94 if ( (expectedRemoved.length == 1)
michael@0 95 &&(String(actualRemoved) == String(expectedRemoved[0]))) continue;
michael@0 96 if ( expectedRemoved.length == 0 && actualRemoved == void 0 ) continue;
michael@0 97 }
michael@0 98
michael@0 99 errorMessage =
michael@0 100 "ERROR: 'TEST FAILED' ERROR: 'TEST FAILED' ERROR: 'TEST FAILED'\n" +
michael@0 101 " test: " + "a.splice(" + first + "," + len + ",-97,new String('test arg'),[],9.8)\n" +
michael@0 102 " a: " + String(testArray) + "\n" +
michael@0 103 " actual spliced: " + String(actualSpliced) + "\n" +
michael@0 104 " expected spliced: " + String(expectedSpliced) + "\n" +
michael@0 105 " actual removed: " + String(actualRemoved) + "\n" +
michael@0 106 " expected removed: " + String(expectedRemoved);
michael@0 107 reason = reason + errorMessage;
michael@0 108 writeHeaderToLog(errorMessage);
michael@0 109 passed = false;
michael@0 110 }
michael@0 111 }
michael@0 112 }
michael@0 113 var testcase = new TestCase(SECTION, testname, true, passed);
michael@0 114 if (!passed) testcase.reason = reason;
michael@0 115 return testcase;
michael@0 116 }

mercurial