Refactor prettyPrinter to work with immutable objects
[#50766813][#266]
This commit is contained in:
@@ -63,6 +63,13 @@ describe("j$.pp", function () {
|
||||
}
|
||||
});
|
||||
|
||||
it("should stringify immutable circular objects", function(){
|
||||
var frozenObject = {foo: {bar: 'baz'}};
|
||||
frozenObject.circular = frozenObject;
|
||||
frozenObject = Object.freeze(frozenObject);
|
||||
expect(j$.pp(frozenObject)).toEqual("{ foo : { bar : 'baz' }, circular : <circular reference: Object> }");
|
||||
});
|
||||
|
||||
it("should stringify RegExp objects properly", function() {
|
||||
expect(j$.pp(/x|y|z/)).toEqual("/x|y|z/");
|
||||
});
|
||||
|
||||
36
spec/performance/large_object_test.js
Normal file
36
spec/performance/large_object_test.js
Normal file
@@ -0,0 +1,36 @@
|
||||
describe('Printing a big object', function(){
|
||||
var bigObject;
|
||||
function rand(upper) {
|
||||
return Math.round(upper * Math.random());
|
||||
}
|
||||
|
||||
function generateObject(level) {
|
||||
var object = {};
|
||||
|
||||
for (var i = 0; i < 50; i++) {
|
||||
var decide = rand(2);
|
||||
switch (decide) {
|
||||
case 0:
|
||||
object["cycle" + i] = object;
|
||||
break;
|
||||
case 1:
|
||||
object["number" + i] = rand(100);
|
||||
break;
|
||||
case 2:
|
||||
if (level < 3) {
|
||||
object["nesting" + i] = generateObject(level + 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
it('takes a resonable amount of time', function(){
|
||||
bigObject = generateObject(0);
|
||||
expect(j$.pp(bigObject)).toMatch(/cycle/);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user