-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
230 additions
and
11 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
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,154 @@ | ||
var test = require('tape'); | ||
|
||
var inspect = require('../'); | ||
|
||
test('simple object with indent', function (t) { | ||
t.plan(1); | ||
|
||
var obj = { a: 1, b: 2 }; | ||
|
||
var expected = [ | ||
'{', | ||
' a: 1,', | ||
' b: 2', | ||
'}' | ||
].join('\n'); | ||
|
||
t.equal(inspect(obj, { indent: 2 }), expected); | ||
}); | ||
|
||
test('two deep object with indent', function (t) { | ||
t.plan(1); | ||
|
||
var obj = { a: 1, b: { c: 3, d: 4 } }; | ||
|
||
var expected = [ | ||
'{', | ||
' a: 1,', | ||
' b: {', | ||
' c: 3,', | ||
' d: 4', | ||
' }', | ||
'}' | ||
].join('\n'); | ||
|
||
t.equal(inspect(obj, { indent: 2 }), expected); | ||
}); | ||
|
||
test('simple array with all single line elements', function (t) { | ||
t.plan(1); | ||
|
||
var obj = [1, 2, 3, 'asdf\nsdf']; | ||
|
||
var expected = '[ 1, 2, 3, \'asdf\\nsdf\' ]'; | ||
|
||
t.equal(inspect(obj, { indent: 2 }), expected); | ||
}); | ||
|
||
test('array with complex elements', function (t) { | ||
t.plan(1); | ||
|
||
var obj = [1, { a: 1, b: { c: 1 } }, 'asdf\nsdf']; | ||
|
||
var expected = [ | ||
'[', | ||
' 1,', | ||
' {', | ||
' a: 1,', | ||
' b: {', | ||
' c: 1', | ||
' }', | ||
' },', | ||
' \'asdf\\nsdf\'', | ||
']' | ||
].join('\n'); | ||
|
||
t.equal(inspect(obj, { indent: 2 }), expected); | ||
}); | ||
|
||
test('values', function (t) { | ||
t.plan(1); | ||
var obj = [{}, [], { 'a-b': 5 }]; | ||
|
||
var expected = [ | ||
'[', | ||
' {},', | ||
' [],', | ||
' {', | ||
' \'a-b\': 5', | ||
' }', | ||
']' | ||
].join('\n'); | ||
|
||
t.equal(inspect(obj, { indent: 2 }), expected); | ||
}); | ||
|
||
test('Map', { skip: typeof Map !== 'function' }, function (t) { | ||
var map = new Map(); | ||
map.set({ a: 1 }, ['b']); | ||
map.set(3, NaN); | ||
|
||
var expectedString = [ | ||
'Map (2) {', | ||
' { a: 1 } => [ \'b\' ],', | ||
' 3 => NaN', | ||
'}' | ||
].join('\n'); | ||
|
||
t.equal( | ||
inspect(map, { indent: 2 }), | ||
expectedString, | ||
'Map keys are not indented' | ||
); | ||
|
||
t.equal(inspect(new Map(), { indent: 2 }), 'Map (0) {}', 'empty Map should show as empty'); | ||
|
||
var nestedMap = new Map(); | ||
nestedMap.set(nestedMap, map); | ||
var expectedNested = [ | ||
'Map (1) {', | ||
' [Circular] => Map (2) {', | ||
' { a: 1 } => [ \'b\' ],', | ||
' 3 => NaN', | ||
' }', | ||
'}' | ||
].join('\n'); | ||
t.equal(inspect(nestedMap, { indent: 2 }), expectedNested, 'Map containing a Map should work'); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('Set', { skip: typeof Set !== 'function' }, function (t) { | ||
var set = new Set(); | ||
set.add({ a: 1 }); | ||
set.add(['b']); | ||
var expectedString = [ | ||
'Set (2) {', | ||
' {', | ||
' a: 1', | ||
' },', | ||
' [ \'b\' ]', | ||
'}' | ||
].join('\n'); | ||
t.equal(inspect(set, { indent: 2 }), expectedString, 'new Set([{ a: 1 }, ["b"]]) should show size and contents'); | ||
|
||
t.equal(inspect(new Set(), { indent: 2 }), 'Set (0) {}', 'empty Set should show as empty'); | ||
|
||
var nestedSet = new Set(); | ||
nestedSet.add(set); | ||
nestedSet.add(nestedSet); | ||
var expectedNested = [ | ||
'Set (2) {', | ||
' Set (2) {', | ||
' {', | ||
' a: 1', | ||
' },', | ||
' [ \'b\' ]', | ||
' },', | ||
' [Circular]', | ||
'}' | ||
].join('\n'); | ||
t.equal(inspect(nestedSet, { indent: 2 }), expectedNested, 'Set containing a Set should work'); | ||
|
||
t.end(); | ||
}); |