Added a shorthand for specifying depth as the second argument

This commit is contained in:
dpashkevich 2013-09-16 15:57:39 +04:00
parent cef9f42521
commit f833a5c3b0
2 changed files with 26 additions and 0 deletions

View File

@ -147,6 +147,10 @@ end
-------------------------------------------------------------------
function inspect.inspect(rootObject, options)
if type(options) == 'number' then
options = {depth = options}
end
options = options or {}
local depth = options.depth or math.huge
local filter = parse_filter(options.filter or {})

View File

@ -153,6 +153,28 @@ describe( 'inspect', function()
end)
it('can be passed directly as second argument', function()
assert.equals(inspect(level5, 2), [[{ 1, 2, 3,
a = {
b = {...}
}
}]])
assert.equals(inspect(level5, 1), [[{ 1, 2, 3,
a = {...}
}]])
assert.equals(inspect(level5, 0), "{...}")
assert.equals(inspect(level5, 4), [[{ 1, 2, 3,
a = {
b = {
c = {
d = {...}
}
}
}
}]])
end)
it('respects depth on keys', function()
assert.equals(inspect(keys, {depth = 4}), [[{
[{ 1, 2, 3,