Fix OrderedMap.

Tim caught a bug. Squashing it so he can rebase on top of it.
This commit is contained in:
Jordan Walke
2013-07-24 17:39:37 -07:00
committed by Paul O’Shannessy
parent ddb0ef98f7
commit 492407bcc9
2 changed files with 17 additions and 2 deletions
+9
View File
@@ -18,6 +18,7 @@
"use strict";
var invariant = require('invariant');
var mixInto = require('mixInto');
var throwIf = require('throwIf');
@@ -349,6 +350,10 @@ var OrderedMapMethods = {
mapKeyRange: function(cb, startKey, endKey, context) {
var startIndex = this.indexOfKey(startKey);
var endIndex = this.indexOfKey(endKey);
invariant(
startIndex !== undefined && endIndex !== undefined,
'mapKeyRange must be given keys that are present.'
);
if (endIndex < startIndex) {
throw new Error(RANGE_ARGS);
}
@@ -358,6 +363,10 @@ var OrderedMapMethods = {
forEachKeyRange: function(cb, startKey, endKey, context) {
var startIndex = this.indexOfKey(startKey);
var endIndex = this.indexOfKey(endKey);
invariant(
startIndex !== undefined && endIndex !== undefined,
'forEachKeyRange must be given keys that are present.'
);
if (endIndex < startIndex) {
throw new Error(RANGE_ARGS);
}
+8 -2
View File
@@ -739,10 +739,16 @@ describe('OrderedMap', function() {
}).not.toThrow();
expect(function() {
om.mapKeyRange(duplicate, 'x' , 3, scope);
}).not.toThrow();
}).toThrow(
'Invariant Violation: mapKeyRange must be given keys ' +
'that are present.'
);
expect(function() {
om.forEachKeyRange(duplicate, 'x', 3, scope);
}).not.toThrow();
}).toThrow(
'Invariant Violation: forEachKeyRange must be given keys ' +
'that are present.'
);
expect(function() {
om.mapRange(duplicate, 0, 4, scope);