mirror of
https://github.com/kikito/inspect.lua.git
synced 2024-12-15 14:34:21 +00:00
Added a shorthand for specifying depth as the second argument
This commit is contained in:
parent
cef9f42521
commit
f833a5c3b0
@ -147,6 +147,10 @@ end
|
|||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
function inspect.inspect(rootObject, options)
|
function inspect.inspect(rootObject, options)
|
||||||
|
if type(options) == 'number' then
|
||||||
|
options = {depth = options}
|
||||||
|
end
|
||||||
|
|
||||||
options = options or {}
|
options = options or {}
|
||||||
local depth = options.depth or math.huge
|
local depth = options.depth or math.huge
|
||||||
local filter = parse_filter(options.filter or {})
|
local filter = parse_filter(options.filter or {})
|
||||||
|
@ -153,6 +153,28 @@ describe( 'inspect', function()
|
|||||||
|
|
||||||
end)
|
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()
|
it('respects depth on keys', function()
|
||||||
assert.equals(inspect(keys, {depth = 4}), [[{
|
assert.equals(inspect(keys, {depth = 4}), [[{
|
||||||
[{ 1, 2, 3,
|
[{ 1, 2, 3,
|
||||||
|
Loading…
Reference in New Issue
Block a user