michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = "364104"; michael@0: var summary = "Array.prototype.indexOf, Array.prototype.lastIndexOf issues " + michael@0: "with the optional second fromIndex argument"; michael@0: var actual, expect; michael@0: michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus(summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: var failed = false; michael@0: michael@0: try michael@0: { michael@0: // indexOf michael@0: if ([2].indexOf(2) != 0) michael@0: throw "indexOf: not finding 2!?"; michael@0: if ([2].indexOf(2, 0) != 0) michael@0: throw "indexOf: not interpreting explicit second argument 0!"; michael@0: if ([2].indexOf(2, 1) != -1) michael@0: throw "indexOf: ignoring second argument with value equal to array length!"; michael@0: if ([2].indexOf(2, 2) != -1) michael@0: throw "indexOf: ignoring second argument greater than array length!"; michael@0: if ([2].indexOf(2, 17) != -1) michael@0: throw "indexOf: ignoring large second argument!"; michael@0: if ([2].indexOf(2, -5) != 0) michael@0: throw "indexOf: calculated fromIndex < 0, should search entire array!"; michael@0: if ([2, 3].indexOf(2, -1) != -1) michael@0: throw "indexOf: not handling index == (-1 + 2), element 2 correctly!"; michael@0: if ([2, 3].indexOf(3, -1) != 1) michael@0: throw "indexOf: not handling index == (-1 + 2), element 3 correctly!"; michael@0: michael@0: // lastIndexOf michael@0: if ([2].lastIndexOf(2) != 0) michael@0: throw "lastIndexOf: not finding 2!?"; michael@0: if ([2].lastIndexOf(2, 1) != 0) michael@0: throw "lastIndexOf: not interpreting explicit second argument 1!?"; michael@0: if ([2].lastIndexOf(2, 17) != 0) michael@0: throw "lastIndexOf: should have searched entire array!"; michael@0: if ([2].lastIndexOf(2, -5) != -1) michael@0: throw "lastIndexOf: -5 + 1 < 0, so array shouldn't be searched!"; michael@0: if ([2].lastIndexOf(2, -2) != -1) michael@0: throw "lastIndexOf: -2 + 1 < 0, so array shouldn't be searched!"; michael@0: if ([2, 3].lastIndexOf(2, -1) != 0) michael@0: throw "lastIndexOf: not handling index == (-1 + 2), element 2 correctly!"; michael@0: if ([2, 3].lastIndexOf(3, -1) != 1) michael@0: throw "lastIndexOf: not handling index == (-1 + 2), element 3 correctly!"; michael@0: if ([2, 3].lastIndexOf(2, -2) != 0) michael@0: throw "lastIndexOf: not handling index == (-2 + 2), element 2 correctly!"; michael@0: if ([2, 3].lastIndexOf(3, -2) != -1) michael@0: throw "lastIndexOf: not handling index == (-2 + 2), element 3 correctly!"; michael@0: if ([2, 3].lastIndexOf(2, -3) != -1) michael@0: throw "lastIndexOf: calculated fromIndex < 0, shouldn't search array for 2!"; michael@0: if ([2, 3].lastIndexOf(3, -3) != -1) michael@0: throw "lastIndexOf: calculated fromIndex < 0, shouldn't search array for 3!"; michael@0: } michael@0: catch (e) michael@0: { michael@0: failed = e; michael@0: } michael@0: michael@0: michael@0: expect = false; michael@0: actual = failed; michael@0: michael@0: reportCompare(expect, actual, summary);