Correct number matching in equals_

This commit is contained in:
ragaskar 2010-03-18 20:32:40 -07:00
parent c85079e9d0
commit bf938ffc50
4 changed files with 60 additions and 5 deletions

View File

@ -89,7 +89,7 @@ jasmine.getEnv = function() {
* @returns {Boolean} * @returns {Boolean}
*/ */
jasmine.isArray_ = function(value) { jasmine.isArray_ = function(value) {
return Object.prototype.toString.apply(value) === '[object Array]'; return jasmine.isA_("Array", value);
}; };
/** /**
@ -99,7 +99,28 @@ jasmine.isArray_ = function(value) {
* @returns {Boolean} * @returns {Boolean}
*/ */
jasmine.isString_ = function(value) { jasmine.isString_ = function(value) {
return Object.prototype.toString.apply(value) === '[object String]'; return jasmine.isA_("String", value);
};
/**
* @ignore
* @private
* @param value
* @returns {Boolean}
*/
jasmine.isNumber_ = function(value) {
return jasmine.isA_("Number", value);
};
/**
* @ignore
* @private
* @param {String} typeName
* @param value
* @returns {Boolean}
*/
jasmine.isA_ = function(typeName, value) {
return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
}; };
/** /**
@ -836,6 +857,10 @@ jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
return (a == b); return (a == b);
} }
if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) {
return (a == b);
}
if (typeof a === "object" && typeof b === "object") { if (typeof a === "object" && typeof b === "object") {
return this.compareObjects_(a, b, mismatchKeys, mismatchValues); return this.compareObjects_(a, b, mismatchKeys, mismatchValues);
} }
@ -2289,5 +2314,5 @@ jasmine.version_= {
"major": 0, "major": 0,
"minor": 10, "minor": 10,
"build": 1, "build": 1,
"revision": 1268838574 "revision": 1268969514
}; };

View File

@ -57,6 +57,11 @@ describe("jasmine.Matchers", function() {
expect((match(new String("cat")).toEqual("cat"))).toBe(true); expect((match(new String("cat")).toEqual("cat"))).toBe(true);
expect((match(new String("cat")).toNotEqual("cat"))).toBe(false); expect((match(new String("cat")).toNotEqual("cat"))).toBe(false);
expect((match(new Number(5)).toEqual(5))).toBe(true);
expect((match(new Number('5')).toEqual(5))).toBe(true);
expect((match(new Number(5)).toNotEqual(5))).toBe(false);
expect((match(new Number('5')).toNotEqual(5))).toBe(false);
}); });
it("toEqual to build an Expectation Result", function() { it("toEqual to build an Expectation Result", function() {

View File

@ -213,6 +213,10 @@ jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
return (a == b); return (a == b);
} }
if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) {
return (a == b);
}
if (typeof a === "object" && typeof b === "object") { if (typeof a === "object" && typeof b === "object") {
return this.compareObjects_(a, b, mismatchKeys, mismatchValues); return this.compareObjects_(a, b, mismatchKeys, mismatchValues);
} }

View File

@ -89,7 +89,7 @@ jasmine.getEnv = function() {
* @returns {Boolean} * @returns {Boolean}
*/ */
jasmine.isArray_ = function(value) { jasmine.isArray_ = function(value) {
return Object.prototype.toString.apply(value) === '[object Array]'; return jasmine.isA_("Array", value);
}; };
/** /**
@ -99,7 +99,28 @@ jasmine.isArray_ = function(value) {
* @returns {Boolean} * @returns {Boolean}
*/ */
jasmine.isString_ = function(value) { jasmine.isString_ = function(value) {
return Object.prototype.toString.apply(value) === '[object String]'; return jasmine.isA_("String", value);
};
/**
* @ignore
* @private
* @param value
* @returns {Boolean}
*/
jasmine.isNumber_ = function(value) {
return jasmine.isA_("Number", value);
};
/**
* @ignore
* @private
* @param {String} typeName
* @param value
* @returns {Boolean}
*/
jasmine.isA_ = function(typeName, value) {
return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
}; };
/** /**