Remove space between key and colon when pretty printing objects

[#4005255]
This commit is contained in:
Greg Cobb and Luan Santos
2014-03-12 11:47:47 -07:00
parent c9e37a2a1c
commit 21de44a204
3 changed files with 14 additions and 14 deletions

View File

@@ -27,10 +27,10 @@ describe("j$.pp", function () {
}); });
it("should stringify objects properly", function() { it("should stringify objects properly", function() {
expect(j$.pp({foo: 'bar'})).toEqual("{ foo : 'bar' }"); expect(j$.pp({foo: 'bar'})).toEqual("{ foo: 'bar' }");
expect(j$.pp({foo:'bar', baz:3, nullValue: null, undefinedValue: jasmine.undefined})).toEqual("{ foo : 'bar', baz : 3, nullValue : null, undefinedValue : undefined }"); expect(j$.pp({foo:'bar', baz:3, nullValue: null, undefinedValue: jasmine.undefined})).toEqual("{ foo: 'bar', baz: 3, nullValue: null, undefinedValue: undefined }");
expect(j$.pp({foo: function () { expect(j$.pp({foo: function () {
}, bar: [1, 2, 3]})).toEqual("{ foo : Function, bar : [ 1, 2, 3 ] }"); }, bar: [1, 2, 3]})).toEqual("{ foo: Function, bar: [ 1, 2, 3 ] }");
}); });
it("should not include inherited properties when stringifying an object", function() { it("should not include inherited properties when stringifying an object", function() {
@@ -38,7 +38,7 @@ describe("j$.pp", function () {
SomeClass.prototype.foo = "inherited foo"; SomeClass.prototype.foo = "inherited foo";
var instance = new SomeClass(); var instance = new SomeClass();
instance.bar = "my own bar"; instance.bar = "my own bar";
expect(j$.pp(instance)).toEqual("{ bar : 'my own bar' }"); expect(j$.pp(instance)).toEqual("{ bar: 'my own bar' }");
}); });
it("should not recurse objects and arrays more deeply than j$.MAX_PRETTY_PRINT_DEPTH", function() { it("should not recurse objects and arrays more deeply than j$.MAX_PRETTY_PRINT_DEPTH", function() {
@@ -48,15 +48,15 @@ describe("j$.pp", function () {
try { try {
j$.MAX_PRETTY_PRINT_DEPTH = 2; j$.MAX_PRETTY_PRINT_DEPTH = 2;
expect(j$.pp(nestedObject)).toEqual("{ level1 : { level2 : Object } }"); expect(j$.pp(nestedObject)).toEqual("{ level1: { level2: Object } }");
expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, Array ] ]"); expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, Array ] ]");
j$.MAX_PRETTY_PRINT_DEPTH = 3; j$.MAX_PRETTY_PRINT_DEPTH = 3;
expect(j$.pp(nestedObject)).toEqual("{ level1 : { level2 : { level3 : Object } } }"); expect(j$.pp(nestedObject)).toEqual("{ level1: { level2: { level3: Object } } }");
expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, Array ] ] ]"); expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, Array ] ] ]");
j$.MAX_PRETTY_PRINT_DEPTH = 4; j$.MAX_PRETTY_PRINT_DEPTH = 4;
expect(j$.pp(nestedObject)).toEqual("{ level1 : { level2 : { level3 : { level4 : 'leaf' } } } }"); expect(j$.pp(nestedObject)).toEqual("{ level1: { level2: { level3: { level4: 'leaf' } } } }");
expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, [ 4, 'leaf' ] ] ] ]"); expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, [ 4, 'leaf' ] ] ] ]");
} finally { } finally {
j$.MAX_PRETTY_PRINT_DEPTH = originalMaxDepth; j$.MAX_PRETTY_PRINT_DEPTH = originalMaxDepth;
@@ -67,7 +67,7 @@ describe("j$.pp", function () {
var frozenObject = {foo: {bar: 'baz'}}; var frozenObject = {foo: {bar: 'baz'}};
frozenObject.circular = frozenObject; frozenObject.circular = frozenObject;
frozenObject = Object.freeze(frozenObject); frozenObject = Object.freeze(frozenObject);
expect(j$.pp(frozenObject)).toEqual("{ foo : { bar : 'baz' }, circular : <circular reference: Object> }"); expect(j$.pp(frozenObject)).toEqual("{ foo: { bar: 'baz' }, circular: <circular reference: Object> }");
}); });
it("should stringify RegExp objects properly", function() { it("should stringify RegExp objects properly", function() {
@@ -77,7 +77,7 @@ describe("j$.pp", function () {
it("should indicate circular object references", function() { it("should indicate circular object references", function() {
var sampleValue = {foo: 'hello'}; var sampleValue = {foo: 'hello'};
sampleValue.nested = sampleValue; sampleValue.nested = sampleValue;
expect(j$.pp(sampleValue)).toEqual("{ foo : 'hello', nested : <circular reference: Object> }"); expect(j$.pp(sampleValue)).toEqual("{ foo: 'hello', nested: <circular reference: Object> }");
}); });
it("should indicate getters on objects as such", function() { it("should indicate getters on objects as such", function() {
@@ -89,10 +89,10 @@ describe("j$.pp", function () {
}); });
} }
if (sampleValue.__defineGetter__) { if (sampleValue.__defineGetter__) {
expect(j$.pp(sampleValue)).toEqual("{ id : 1, calculatedValue : <getter> }"); expect(j$.pp(sampleValue)).toEqual("{ id: 1, calculatedValue: <getter> }");
} }
else { else {
expect(j$.pp(sampleValue)).toEqual("{ id : 1 }"); expect(j$.pp(sampleValue)).toEqual("{ id: 1 }");
} }
}); });
@@ -136,7 +136,7 @@ describe("j$.pp", function () {
var obj = Object.create(null); var obj = Object.create(null);
obj.foo = 'bar'; obj.foo = 'bar';
expect(j$.pp(obj)).toEqual("{ foo : 'bar' }"); expect(j$.pp(obj)).toEqual("{ foo: 'bar' }");
}); });
}); });

View File

@@ -3,7 +3,7 @@ describe("j$.pp (HTML Dependent)", function () {
var sampleNode = document.createElement('div'); var sampleNode = document.createElement('div');
sampleNode.innerHTML = 'foo<b>bar</b>'; sampleNode.innerHTML = 'foo<b>bar</b>';
expect(j$.pp(sampleNode)).toEqual("HTMLNode"); expect(j$.pp(sampleNode)).toEqual("HTMLNode");
expect(j$.pp({foo: sampleNode})).toEqual("{ foo : HTMLNode }"); expect(j$.pp({foo: sampleNode})).toEqual("{ foo: HTMLNode }");
}); });
it("should print Firefox's wrapped native objects correctly", function() { it("should print Firefox's wrapped native objects correctly", function() {

View File

@@ -111,7 +111,7 @@ getJasmineRequireObj().pp = function(j$) {
} }
self.append(property); self.append(property);
self.append(' : '); self.append(': ');
if (isGetter) { if (isGetter) {
self.append('<getter>'); self.append('<getter>');
} else { } else {