Fix pretty printing of RegExp objects.
This commit is contained in:
parent
98e86817bf
commit
7be8247b2f
@ -32,6 +32,10 @@ describe("jasmine.pp", 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 stringify RegExp objects properly", function() {
|
||||||
|
expect(jasmine.pp(/x|y|z/)).toEqual("/x|y|z/");
|
||||||
|
});
|
||||||
|
|
||||||
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;
|
||||||
|
@ -9,11 +9,9 @@ jasmine.PrettyPrinter = function() {
|
|||||||
* Formats a value in a nice, human-readable string.
|
* Formats a value in a nice, human-readable string.
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value
|
||||||
* @returns {String}
|
|
||||||
*/
|
*/
|
||||||
jasmine.PrettyPrinter.prototype.format = function(value) {
|
jasmine.PrettyPrinter.prototype.format = function(value) {
|
||||||
if (this.ppNestLevel_ > 40) {
|
if (this.ppNestLevel_ > 40) {
|
||||||
// return '(jasmine.pp nested too deeply!)';
|
|
||||||
throw new Error('jasmine.PrettyPrinter: format() nested too deeply!');
|
throw new Error('jasmine.PrettyPrinter: format() nested too deeply!');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,6 +33,8 @@ jasmine.PrettyPrinter.prototype.format = function(value) {
|
|||||||
this.emitScalar('HTMLNode');
|
this.emitScalar('HTMLNode');
|
||||||
} else if (value instanceof Date) {
|
} else if (value instanceof Date) {
|
||||||
this.emitScalar('Date(' + value + ')');
|
this.emitScalar('Date(' + value + ')');
|
||||||
|
} else if (value instanceof RegExp) {
|
||||||
|
this.emitScalar(value.toString());
|
||||||
} else if (value.__Jasmine_been_here_before__) {
|
} else if (value.__Jasmine_been_here_before__) {
|
||||||
this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>');
|
this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>');
|
||||||
} else if (jasmine.isArray_(value) || typeof value == 'object') {
|
} else if (jasmine.isArray_(value) || typeof value == 'object') {
|
||||||
|
Loading…
Reference in New Issue
Block a user