OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 var keys = [0, Math.floor(2) * 0.5]; | 200 var keys = [0, Math.floor(2) * 0.5]; |
201 var str = 'ab', arr = ['a', 'b']; | 201 var str = 'ab', arr = ['a', 'b']; |
202 for (var i = 0; i < 100; ++i) { | 202 for (var i = 0; i < 100; ++i) { |
203 var index = Math.floor(i / 50); | 203 var index = Math.floor(i / 50); |
204 var key = keys[index]; | 204 var key = keys[index]; |
205 var expected = arr[index]; | 205 var expected = arr[index]; |
206 var actual = str[key]; | 206 var actual = str[key]; |
207 assertEquals(expected, actual); | 207 assertEquals(expected, actual); |
208 } | 208 } |
209 | 209 |
| 210 // Test negative zero case. |
| 211 var keys = [0, -0.0]; |
| 212 var str = 'ab', arr = ['a', 'a']; |
| 213 for (var i = 0; i < 100; ++i) { |
| 214 var index = Math.floor(i / 50); |
| 215 var key = keys[index]; |
| 216 var expected = arr[index]; |
| 217 var actual = str[key]; |
| 218 assertEquals(expected, actual); |
| 219 } |
| 220 |
| 221 // Test "not-an-array-index" case. |
| 222 var keys = [0, 0.5]; |
| 223 var str = 'ab', arr = ['a', undefined]; |
| 224 for (var i = 0; i < 100; ++i) { |
| 225 var index = Math.floor(i / 50); |
| 226 var key = keys[index]; |
| 227 var expected = arr[index]; |
| 228 var actual = str[key]; |
| 229 assertEquals(expected, actual); |
| 230 } |
| 231 |
210 // Test out of range case. | 232 // Test out of range case. |
211 var keys = [0, -1]; | 233 var keys = [0, -1]; |
212 var str = 'ab', arr = ['a', undefined]; | 234 var str = 'ab', arr = ['a', undefined]; |
213 for (var i = 0; i < 100; ++i) { | 235 for (var i = 0; i < 100; ++i) { |
214 var index = Math.floor(i / 50); | 236 var index = Math.floor(i / 50); |
215 var key = keys[index]; | 237 var key = keys[index]; |
216 var expected = arr[index]; | 238 var expected = arr[index]; |
217 var actual = str[key]; | 239 var actual = str[key]; |
218 assertEquals(expected, actual); | 240 assertEquals(expected, actual); |
219 } | 241 } |
220 | 242 |
221 var keys = [0, 10]; | 243 var keys = [0, 10]; |
222 var str = 'ab', arr = ['a', undefined]; | 244 var str = 'ab', arr = ['a', undefined]; |
223 for (var i = 0; i < 100; ++i) { | 245 for (var i = 0; i < 100; ++i) { |
224 var index = Math.floor(i / 50); | 246 var index = Math.floor(i / 50); |
225 var key = keys[index]; | 247 var key = keys[index]; |
226 var expected = arr[index]; | 248 var expected = arr[index]; |
227 var actual = str[key]; | 249 var actual = str[key]; |
228 assertEquals(expected, actual); | 250 assertEquals(expected, actual); |
229 } | 251 } |
230 | 252 |
231 // Test two byte string. | 253 // Test two byte string. |
232 var str = '\u0427', arr = ['\u0427']; | 254 var str = '\u0427', arr = ['\u0427']; |
233 for (var i = 0; i < 50; ++i) { | 255 for (var i = 0; i < 50; ++i) { |
234 var expected = arr[0]; | 256 var expected = arr[0]; |
235 var actual = str[0]; | 257 var actual = str[0]; |
236 assertEquals(expected, actual); | 258 assertEquals(expected, actual); |
237 } | 259 } |
OLD | NEW |