sys.inspect prints out special chars correctly (\n, \u0001, etc...)

pull/22966/head
Xavier Shay 2009-12-07 15:44:41 +11:00 committed by Ryan Dahl
parent c3e0a4bc7c
commit 756544fd28
2 changed files with 3 additions and 1 deletions

View File

@ -82,7 +82,7 @@ exports.inherits = process.inherits;
*/ */
var formatter = function(value, indent, parents) { var formatter = function(value, indent, parents) {
switch(typeof(value)) { switch(typeof(value)) {
case 'string': return '"' + value + '"'; case 'string': return JSON.stringify(value);
case 'number': return '' + value; case 'number': return '' + value;
case 'function': return '[Function]'; case 'function': return '[Function]';
case 'boolean': return '' + value; case 'boolean': return '' + value;

View File

@ -10,6 +10,8 @@ assert.equal("[Function]", inspect(function() {}));
assert.equal('undefined', inspect(undefined)); assert.equal('undefined', inspect(undefined));
assert.equal('null', inspect(null)); assert.equal('null', inspect(null));
assert.equal("\"\\n\\u0001\"", inspect("\n\u0001"));
assert.equal('[]', inspect([])); assert.equal('[]', inspect([]));
assert.equal('[\n 1,\n 2\n]', inspect([1, 2])); assert.equal('[\n 1,\n 2\n]', inspect([1, 2]));
assert.equal('[\n 1,\n [\n 2,\n 3\n ]\n]', inspect([1, [2, 3]])); assert.equal('[\n 1,\n [\n 2,\n 3\n ]\n]', inspect([1, [2, 3]]));