]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_2/Array/splice2.js
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
24 Description: 'Tests Array.splice(x,y) w/4 var args'
27 Date: Fri Feb 13 09:58:28 PST 1998
30 var SECTION
= 'As described in Netscape doc "Whats new in JavaScript 1.2"';
31 var VERSION
= 'no version';
33 var TITLE
= 'String:splice 2';
34 var BUGNUMBER
="123795";
36 writeHeaderToLog('Executing script: splice2.js');
37 writeHeaderToLog( SECTION
+ " "+ TITLE
);
40 var testcases
= new Array();
43 function mySplice(testArray
, splicedArray
, first
, len
, elements
)
45 var removedArray
= [];
46 var adjustedFirst
= first
;
47 var adjustedLen
= len
;
49 if (adjustedFirst
< 0) adjustedFirst
= testArray
.length
+ first
;
50 if (adjustedFirst
< 0) adjustedFirst
= 0;
52 if (adjustedLen
< 0) adjustedLen
= 0;
54 for (i
= 0; (i
< adjustedFirst
)&&(i
< testArray
.length
); ++i
)
55 splicedArray
.push(testArray
[i
]);
57 if (adjustedFirst
< testArray
.length
)
58 for (i
= adjustedFirst
; (i
< adjustedFirst
+ adjustedLen
) && (i
< testArray
.length
); ++i
)
59 removedArray
.push(testArray
[i
]);
61 for (i
= 0; i
< elements
.length
; i
++) splicedArray
.push(elements
[i
]);
63 for (i
= adjustedFirst
+ adjustedLen
; i
< testArray
.length
; i
++)
64 splicedArray
.push(testArray
[i
]);
69 function exhaustiveSpliceTestWithArgs(testname
, testArray
)
74 for (var first
= -(testArray
.length
+2); first
<= 2 + testArray
.length
; first
++)
76 var actualSpliced
= [];
77 var expectedSpliced
= [];
78 var actualRemoved
= [];
79 var expectedRemoved
= [];
81 for (var len
= 0; len
< testArray
.length
+ 2; len
++)
86 for (var i
= 0; i
< testArray
.length
; ++i
)
87 actualSpliced
.push(testArray
[i
]);
89 actualRemoved
= actualSpliced
.splice(first
,len
,-97,new String("test arg"),[],9.8);
90 expectedRemoved
= mySplice(testArray
,expectedSpliced
,first
,len
,[-97,new String("test arg"),[],9.8]);
92 var adjustedFirst
= first
;
93 if (adjustedFirst
< 0) adjustedFirst
= testArray
.length
+ first
;
94 if (adjustedFirst
< 0) adjustedFirst
= 0;
97 if ( (String(actualSpliced
) != String(expectedSpliced
))
98 ||(String(actualRemoved
) != String(expectedRemoved
)))
100 if ( (String(actualSpliced
) == String(expectedSpliced
))
101 &&(String(actualRemoved
) != String(expectedRemoved
)) )
104 if ( (expectedRemoved
.length
== 1)
105 &&(String(actualRemoved
) == String(expectedRemoved
[0]))) continue;
106 if ( expectedRemoved
.length
== 0 && actualRemoved
== void 0 ) continue;
110 "ERROR: 'TEST FAILED' ERROR: 'TEST FAILED' ERROR: 'TEST FAILED'\n" +
111 " test: " + "a.splice(" + first
+ "," + len
+ ",-97,new String('test arg'),[],9.8)\n" +
112 " a: " + String(testArray
) + "\n" +
113 " actual spliced: " + String(actualSpliced
) + "\n" +
114 " expected spliced: " + String(expectedSpliced
) + "\n" +
115 " actual removed: " + String(actualRemoved
) + "\n" +
116 " expected removed: " + String(expectedRemoved
);
117 reason
= reason
+ errorMessage
;
118 writeHeaderToLog(errorMessage
);
123 var testcase
= new TestCase(SECTION
, testname
, true, passed
);
124 if (!passed
) testcase
.reason
= reason
;
129 var a
= ['a','test string',456,9.34,new String("string object"),[],['h','i','j','k']];
130 var b
= [1,2,3,4,5,6,7,8,9,0];
132 testcases
[count
++] = exhaustiveSpliceTestWithArgs("exhaustive splice w/2 optional args 1",a
);
133 testcases
[count
++] = exhaustiveSpliceTestWithArgs("exhaustive splice w/2 optional args 2",b
);
137 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
138 testcases
[tc
].passed
= writeTestCaseResult(
139 testcases
[tc
].expect
,
140 testcases
[tc
].actual
,
141 testcases
[tc
].description
+" = "+
142 testcases
[tc
].actual
);
143 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
146 return ( testcases
);