Skip to content

Commit

Permalink
Merge pull request #435 from prashn64/indexInArray-2.3.x
Browse files Browse the repository at this point in the history
indexInArray fix.
  • Loading branch information
smfoote committed Mar 6, 2014
2 parents 3d3c8dc + 3cc27ce commit a43c995
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dust.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
}

for (;fromIndex < length; fromIndex++) {
if (this[fromIndex] === item) {
if (arr[fromIndex] === item) {
return fromIndex;
}
}
Expand Down
20 changes: 20 additions & 0 deletions test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,26 @@ exports.coreSetup = function(suite, auto) {
unit.fail(err);
});
});

suite.test("indexInArray", function() {
var unit = this,
arr = ["hello", "world"],
nativeIndexOf = Array.prototype.indexOf,
indexOf;
indexOf = dust.indexInArray(arr, "world");
unit.equals(indexOf, 1);
indexOf = dust.indexInArray(arr, "foo");
unit.equals(indexOf, -1);
Array.prototype.indexOf = undefined;
// test indexOf when the array indexOf function is undefined (IE lte 8)
indexOf = dust.indexInArray(arr, "world");
unit.equals(indexOf, 1);
indexOf = dust.indexInArray(arr, "foo");
unit.equals(indexOf, -1);
Array.prototype.indexOf = nativeIndexOf;
unit.notEquals(Array.prototype.indexOf, undefined);
unit.pass();
});
}

function testRender(unit, source, context, expected, options, baseContext, error, logMessage) {
Expand Down
8 changes: 8 additions & 0 deletions test/uutest.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ Test.prototype.equals = function(actual, expected, message) {
}
}

Test.prototype.notEquals = function(actual, expected, message) {
if (actual === expected) {
var err = new Error();
if (message) err.message = message;
throw wrapAssertionError(err, actual, expected, "===");
}
}

Test.prototype.ifError = function(err) {
if (err) throw err;
}
Expand Down

0 comments on commit a43c995

Please sign in to comment.