From 7cf899a4ea88e91bd5b1c323449037bdc6d067a7 Mon Sep 17 00:00:00 2001 From: Sheel Choksi Date: Sun, 9 Feb 2014 14:14:33 -0800 Subject: [PATCH] Special case printing -0 Use the 1/x trick to determine if a value is -0 and special case the printing of it. [closes #496] --- lib/jasmine-core/jasmine.js | 2 ++ spec/core/PrettyPrintSpec.js | 1 + src/core/PrettyPrinter.js | 2 ++ 3 files changed, 5 insertions(+) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index ac4b279d..aa3340b7 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1354,6 +1354,8 @@ getJasmineRequireObj().pp = function(j$) { this.emitScalar('undefined'); } else if (value === null) { this.emitScalar('null'); + } else if (value === 0 && 1/value === -Infinity) { + this.emitScalar('-0'); } else if (value === j$.getGlobal()) { this.emitScalar(''); } else if (value.jasmineToString) { diff --git a/spec/core/PrettyPrintSpec.js b/spec/core/PrettyPrintSpec.js index 4e31e39c..7b7c21ab 100644 --- a/spec/core/PrettyPrintSpec.js +++ b/spec/core/PrettyPrintSpec.js @@ -11,6 +11,7 @@ describe("j$.pp", function () { expect(j$.pp(jasmine.undefined)).toEqual("undefined"); expect(j$.pp(3)).toEqual("3"); expect(j$.pp(-3.14)).toEqual("-3.14"); + expect(j$.pp(-0)).toEqual("-0"); }); it("should stringify arrays properly", function() { diff --git a/src/core/PrettyPrinter.js b/src/core/PrettyPrinter.js index b3b6e80d..8a2dea8b 100644 --- a/src/core/PrettyPrinter.js +++ b/src/core/PrettyPrinter.js @@ -11,6 +11,8 @@ getJasmineRequireObj().pp = function(j$) { this.emitScalar('undefined'); } else if (value === null) { this.emitScalar('null'); + } else if (value === 0 && 1/value === -Infinity) { + this.emitScalar('-0'); } else if (value === j$.getGlobal()) { this.emitScalar(''); } else if (value.jasmineToString) {