From bf938ffc5047a70f430ae92e2cf37cb159c1a500 Mon Sep 17 00:00:00 2001 From: ragaskar Date: Thu, 18 Mar 2010 20:32:40 -0700 Subject: [PATCH] Correct number matching in equals_ --- lib/jasmine-0.10.1.js | 31 ++++++++++++++++++++++++++++--- spec/suites/MatchersSpec.js | 5 +++++ src/Env.js | 4 ++++ src/base.js | 25 +++++++++++++++++++++++-- 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/lib/jasmine-0.10.1.js b/lib/jasmine-0.10.1.js index f1d7ff9..73abc10 100644 --- a/lib/jasmine-0.10.1.js +++ b/lib/jasmine-0.10.1.js @@ -89,7 +89,7 @@ jasmine.getEnv = function() { * @returns {Boolean} */ 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} */ 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); } + if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) { + return (a == b); + } + if (typeof a === "object" && typeof b === "object") { return this.compareObjects_(a, b, mismatchKeys, mismatchValues); } @@ -2289,5 +2314,5 @@ jasmine.version_= { "major": 0, "minor": 10, "build": 1, - "revision": 1268838574 + "revision": 1268969514 }; diff --git a/spec/suites/MatchersSpec.js b/spec/suites/MatchersSpec.js index faae5e4..2c4b90b 100644 --- a/spec/suites/MatchersSpec.js +++ b/spec/suites/MatchersSpec.js @@ -57,6 +57,11 @@ describe("jasmine.Matchers", function() { expect((match(new String("cat")).toEqual("cat"))).toBe(true); 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() { diff --git a/src/Env.js b/src/Env.js index 38262e5..68304f7 100644 --- a/src/Env.js +++ b/src/Env.js @@ -213,6 +213,10 @@ jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { return (a == b); } + if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) { + return (a == b); + } + if (typeof a === "object" && typeof b === "object") { return this.compareObjects_(a, b, mismatchKeys, mismatchValues); } diff --git a/src/base.js b/src/base.js index 751fc15..133220a 100755 --- a/src/base.js +++ b/src/base.js @@ -89,7 +89,7 @@ jasmine.getEnv = function() { * @returns {Boolean} */ 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} */ 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 + ']'; }; /**