From f833a5c3b0863c92e2d18b6fbde7e2af33a348eb Mon Sep 17 00:00:00 2001 From: dpashkevich Date: Mon, 16 Sep 2013 15:57:39 +0400 Subject: [PATCH] Added a shorthand for specifying depth as the second argument --- inspect.lua | 4 ++++ spec/inspect_spec.lua | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/inspect.lua b/inspect.lua index ed6fa52..f2a13a8 100644 --- a/inspect.lua +++ b/inspect.lua @@ -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 {}) diff --git a/spec/inspect_spec.lua b/spec/inspect_spec.lua index 8c55052..511a637 100644 --- a/spec/inspect_spec.lua +++ b/spec/inspect_spec.lua @@ -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,