Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / js / tests / js1_2 / Array / splice2.js
blob1a445709d68566fada4ced1f025d07b7b39d53fe
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 gTestfile = 'splice2.js';
41 /**
42 Filename: splice2.js
43 Description: 'Tests Array.splice(x,y) w/4 var args'
45 Author: Nick Lerissa
46 Date: Fri Feb 13 09:58:28 PST 1998
49 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
50 var VERSION = 'no version';
51 var TITLE = 'String:splice 2';
52 var BUGNUMBER="123795";
54 startTest();
55 writeHeaderToLog('Executing script: splice2.js');
56 writeHeaderToLog( SECTION + " "+ TITLE);
58 var a = ['a','test string',456,9.34,new String("string object"),[],['h','i','j','k']];
59 var b = [1,2,3,4,5,6,7,8,9,0];
61 exhaustiveSpliceTestWithArgs("exhaustive splice w/2 optional args 1",a);
62 exhaustiveSpliceTestWithArgs("exhaustive splice w/2 optional args 2",b);
64 test();
67 function mySplice(testArray, splicedArray, first, len, elements)
69 var removedArray = [];
70 var adjustedFirst = first;
71 var adjustedLen = len;
73 if (adjustedFirst < 0) adjustedFirst = testArray.length + first;
74 if (adjustedFirst < 0) adjustedFirst = 0;
76 if (adjustedLen < 0) adjustedLen = 0;
78 for (i = 0; (i < adjustedFirst)&&(i < testArray.length); ++i)
79 splicedArray.push(testArray[i]);
81 if (adjustedFirst < testArray.length)
82 for (i = adjustedFirst; (i < adjustedFirst + adjustedLen) && (i < testArray.length); ++i)
83 removedArray.push(testArray[i]);
85 for (i = 0; i < elements.length; i++) splicedArray.push(elements[i]);
87 for (i = adjustedFirst + adjustedLen; i < testArray.length; i++)
88 splicedArray.push(testArray[i]);
90 return removedArray;
93 function exhaustiveSpliceTestWithArgs(testname, testArray)
95 var passed = true;
96 var errorMessage;
97 var reason = "";
98 for (var first = -(testArray.length+2); first <= 2 + testArray.length; first++)
100 var actualSpliced = [];
101 var expectedSpliced = [];
102 var actualRemoved = [];
103 var expectedRemoved = [];
105 for (var len = 0; len < testArray.length + 2; len++)
107 actualSpliced = [];
108 expectedSpliced = [];
110 for (var i = 0; i < testArray.length; ++i)
111 actualSpliced.push(testArray[i]);
113 actualRemoved = actualSpliced.splice(first,len,-97,new String("test arg"),[],9.8);
114 expectedRemoved = mySplice(testArray,expectedSpliced,first,len,[-97,new String("test arg"),[],9.8]);
116 var adjustedFirst = first;
117 if (adjustedFirst < 0) adjustedFirst = testArray.length + first;
118 if (adjustedFirst < 0) adjustedFirst = 0;
121 if ( (String(actualSpliced) != String(expectedSpliced))
122 ||(String(actualRemoved) != String(expectedRemoved)))
124 if ( (String(actualSpliced) == String(expectedSpliced))
125 &&(String(actualRemoved) != String(expectedRemoved)) )
128 if ( (expectedRemoved.length == 1)
129 &&(String(actualRemoved) == String(expectedRemoved[0]))) continue;
130 if ( expectedRemoved.length == 0 && actualRemoved == void 0 ) continue;
133 errorMessage =
134 "ERROR: 'TEST FAILED' ERROR: 'TEST FAILED' ERROR: 'TEST FAILED'\n" +
135 " test: " + "a.splice(" + first + "," + len + ",-97,new String('test arg'),[],9.8)\n" +
136 " a: " + String(testArray) + "\n" +
137 " actual spliced: " + String(actualSpliced) + "\n" +
138 " expected spliced: " + String(expectedSpliced) + "\n" +
139 " actual removed: " + String(actualRemoved) + "\n" +
140 " expected removed: " + String(expectedRemoved);
141 reason = reason + errorMessage;
142 writeHeaderToLog(errorMessage);
143 passed = false;
147 var testcase = new TestCase(SECTION, testname, true, passed);
148 if (!passed) testcase.reason = reason;
149 return testcase;