-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sys.inspect is totally more awesome now
- No longer relies on JSON.stringify, so it can output nulls and functions - Handles circular references better - Has tests
- Loading branch information
1 parent
4d818f1
commit 34c0235
Showing
2 changed files
with
90 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
process.mixin(require("./common")); | ||
process.mixin(require("sys")); | ||
|
||
assert.equal("0", inspect(0)); | ||
assert.equal("1", inspect(1)); | ||
assert.equal("false", inspect(false)); | ||
assert.equal('""', inspect("")); | ||
assert.equal('"hello"', inspect("hello")); | ||
assert.equal("[Function]", inspect(function() {})); | ||
assert.equal('undefined', inspect(undefined)); | ||
assert.equal('null', inspect(null)); | ||
|
||
assert.equal('[]', inspect([])); | ||
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('{}', inspect({})); | ||
assert.equal('{\n "a": 1\n}', inspect({a: 1})); | ||
assert.equal('{\n "a": [Function]\n}', inspect({a: function() {}})); | ||
assert.equal('{\n "a": 1,\n "b": 2\n}', inspect({a: 1, b: 2})); | ||
assert.equal('{\n "a": {}\n}', inspect({'a': {}})); | ||
assert.equal('{\n "a": {\n "b": 2\n }\n}', inspect({'a': {'b': 2}})); | ||
|
||
var value = {} | ||
value['a'] = value; | ||
assert.equal('{\n "a": [Circular]\n}', inspect(value)); |