@@ -96,6 +96,21 @@ new Test.Unit.Runner({
96
96
this . assertEqual ( 0 , [ 1 , 2 , 1 ] . indexOf ( 1 ) ) ;
97
97
this . assertEqual ( 2 , [ 1 , 2 , 1 ] . indexOf ( 1 , - 1 ) ) ;
98
98
this . assertEqual ( 1 , [ undefined , null ] . indexOf ( null ) ) ;
99
+
100
+ // ES5 compatibility tests.
101
+ var undef ;
102
+ var array = [ 1 , 2 , 3 , 4 , 5 , undef , 6 , 7 , 1 , 2 , 3 ] ;
103
+
104
+ this . assertEqual ( 2 , array . indexOf ( 3 , - 47 ) ,
105
+ "large negative value for fromIndex" ) ;
106
+ this . assertEqual ( 10 , array . indexOf ( 3 , 4 ) ) ;
107
+ this . assertEqual ( 10 , array . indexOf ( 3 , - 5 ) )
108
+ this . assertEqual ( 2 , array . indexOf ( 3 , { } ) ,
109
+ "nonsensical value for fromIndex" ) ;
110
+ this . assertEqual ( 2 , array . indexOf ( 3 , "" ) ,
111
+ "nonsensical value for fromIndex" ) ;
112
+ this . assertEqual ( - 1 , array . indexOf ( 3 , 41 ) ,
113
+ "fromIndex value larger than the length of the array" ) ;
99
114
} ,
100
115
101
116
testLastIndexOf : function ( ) {
@@ -188,18 +203,37 @@ new Test.Unit.Runner({
188
203
189
204
this . assertIdentical ( 1 , Array . prototype . concat . length ) ;
190
205
191
- this . assertEnumEqual ( [ 0 , 1 ] , [ 0 , 1 ] . concat ( ) ) ;
192
- this . assertIdentical ( 2 , [ 0 , 1 ] . concat ( ) . length ) ;
206
+ this . assertEnumEqual (
207
+ [ 0 , 1 ] ,
208
+ [ 0 , 1 ] . concat ( ) ,
209
+ "test 2"
210
+ ) ;
211
+ this . assertIdentical ( 2 , [ 0 , 1 ] . concat ( ) . length , "test 3" ) ;
193
212
194
- this . assertEnumEqual ( [ 0 , 1 , 2 , 3 , 4 ] , [ ] . concat ( [ 0 , 1 ] , [ 2 , 3 , 4 ] ) ) ;
195
- this . assertIdentical ( 5 , [ ] . concat ( [ 0 , 1 ] , [ 2 , 3 , 4 ] ) . length ) ;
213
+ this . assertEnumEqual (
214
+ [ 0 , 1 , 2 , 3 , 4 ] ,
215
+ [ ] . concat ( [ 0 , 1 ] , [ 2 , 3 , 4 ] ) ,
216
+ "test 4"
217
+ ) ;
218
+ this . assertIdentical ( 5 , [ ] . concat ( [ 0 , 1 ] , [ 2 , 3 , 4 ] ) . length , "test 5" ) ;
196
219
197
- this . assertEnumEqual ( [ 0 , x , 1 , 2 , true , "NaN" ] , [ 0 ] . concat ( x , [ 1 , 2 ] , true , "NaN" ) ) ;
198
- this . assertIdentical ( 6 , [ 0 ] . concat ( x , [ 1 , 2 ] , true , "NaN" ) . length ) ;
220
+ this . assertEnumEqual ( [ 0 , x , 1 , 2 , true , "NaN" ] , [ 0 ] . concat ( x , [ 1 , 2 ] , true , "NaN" ) , "test 6" ) ;
221
+ this . assertIdentical ( 6 , [ 0 ] . concat ( x , [ 1 , 2 ] , true , "NaN" ) . length , "test 7" ) ;
222
+
223
+ // These tests will fail in older IE because of the trailing comma.
224
+ // Nothing we can do about that, so just skip them and let the user know.
225
+ if ( [ , ] . length === 2 ) {
226
+ this . info ( "NOTE: Old versions of IE don't like trailing commas in " +
227
+ "arrays. Skipping some tests." ) ;
228
+ } else {
229
+ this . assertEnumEqual ( [ undefined , 1 , undefined ] , [ , 1 ] . concat ( [ ] , [ , ] ) ,
230
+ "concatenation behavior with a trailing comma (1)" ) ;
231
+ this . assertIdentical ( 3 , [ , 1 ] . concat ( [ ] , [ , ] ) . length ,
232
+ "concatenation behavior with a trailing comma (2)" ) ;
233
+ }
234
+
199
235
200
- this . assertEnumEqual ( [ undefined , 1 , undefined ] , [ , 1 ] . concat ( [ ] , [ , ] ) ) ;
201
- this . assertIdentical ( 3 , [ , 1 ] . concat ( [ ] , [ , ] ) . length ) ;
202
- this . assertEnumEqual ( [ 1 ] , Object . keys ( [ , 1 ] . concat ( [ ] , [ , ] ) ) ) ;
236
+ this . assertEnumEqual ( [ 1 ] , Object . keys ( [ , 1 ] . concat ( [ ] , [ , ] ) ) , "test 10" ) ;
203
237
204
238
// Check that Array.prototype.concat can be used in a generic way
205
239
x . concat = Array . prototype . concat ;
0 commit comments