summaryrefslogtreecommitdiffstats
path: root/js/src/tests/js1_5/Array/regress-364104.js
blob: 05d8953b6e24ae70919511b514b1e76d12c31cb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

//-----------------------------------------------------------------------------
var BUGNUMBER     = "364104";
var summary = "Array.prototype.indexOf, Array.prototype.lastIndexOf issues " +
  "with the optional second fromIndex argument";
var actual, expect;

printBugNumber(BUGNUMBER);
printStatus(summary);

/**************
 * BEGIN TEST *
 **************/

var failed = false;

try
{
  // indexOf
  if ([2].indexOf(2) != 0)
    throw "indexOf: not finding 2!?";
  if ([2].indexOf(2, 0) != 0)
    throw "indexOf: not interpreting explicit second argument 0!";
  if ([2].indexOf(2, 1) != -1)
    throw "indexOf: ignoring second argument with value equal to array length!";
  if ([2].indexOf(2, 2) != -1)
    throw "indexOf: ignoring second argument greater than array length!";
  if ([2].indexOf(2, 17) != -1)
    throw "indexOf: ignoring large second argument!";
  if ([2].indexOf(2, -5) != 0)
    throw "indexOf: calculated fromIndex < 0, should search entire array!";
  if ([2, 3].indexOf(2, -1) != -1)
    throw "indexOf: not handling index == (-1 + 2), element 2 correctly!";
  if ([2, 3].indexOf(3, -1) != 1)
    throw "indexOf: not handling index == (-1 + 2), element 3 correctly!";

  // lastIndexOf
  if ([2].lastIndexOf(2) != 0)
    throw "lastIndexOf: not finding 2!?";
  if ([2].lastIndexOf(2, 1) != 0)
    throw "lastIndexOf: not interpreting explicit second argument 1!?";
  if ([2].lastIndexOf(2, 17) != 0)
    throw "lastIndexOf: should have searched entire array!";
  if ([2].lastIndexOf(2, -5) != -1)
    throw "lastIndexOf: -5 + 1 < 0, so array shouldn't be searched!";
  if ([2].lastIndexOf(2, -2) != -1)
    throw "lastIndexOf: -2 + 1 < 0, so array shouldn't be searched!";
  if ([2, 3].lastIndexOf(2, -1) != 0)
    throw "lastIndexOf: not handling index == (-1 + 2), element 2 correctly!";
  if ([2, 3].lastIndexOf(3, -1) != 1)
    throw "lastIndexOf: not handling index == (-1 + 2), element 3 correctly!";
  if ([2, 3].lastIndexOf(2, -2) != 0)
    throw "lastIndexOf: not handling index == (-2 + 2), element 2 correctly!";
  if ([2, 3].lastIndexOf(3, -2) != -1)
    throw "lastIndexOf: not handling index == (-2 + 2), element 3 correctly!";
  if ([2, 3].lastIndexOf(2, -3) != -1)
    throw "lastIndexOf: calculated fromIndex < 0, shouldn't search array for 2!";
  if ([2, 3].lastIndexOf(3, -3) != -1)
    throw "lastIndexOf: calculated fromIndex < 0, shouldn't search array for 3!";
}
catch (e)
{
  failed = e;
}


expect = false;
actual = failed;

reportCompare(expect, actual, summary);