mirror of
https://github.com/kikito/inspect.lua.git
synced 2024-12-15 14:34:21 +00:00
made depth an options parameter
This commit is contained in:
parent
e898803196
commit
8a65da658a
@ -137,8 +137,9 @@ local function countTableAppearances(t, tableAppearances)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------
|
||||
function inspect.dump(rootObject, depth)
|
||||
depth = depth or math.huge
|
||||
function inspect.inspect(rootObject, options)
|
||||
options = options or {}
|
||||
depth = options.depth or math.huge
|
||||
|
||||
local tableAppearances = countTableAppearances(rootObject)
|
||||
|
||||
@ -269,7 +270,7 @@ function inspect.dump(rootObject, depth)
|
||||
return table.concat(buffer)
|
||||
end
|
||||
|
||||
setmetatable(inspect, { __call = function(_, ...) return inspect.dump(...) end })
|
||||
setmetatable(inspect, { __call = function(_, ...) return inspect.inspect(...) end })
|
||||
|
||||
return inspect
|
||||
|
||||
|
@ -105,7 +105,16 @@ describe( 'inspect', function()
|
||||
}]])
|
||||
end)
|
||||
|
||||
describe('depth', function()
|
||||
it('displays <table x> instead of repeating an already existing table', function()
|
||||
local a = { 1, 2, 3 }
|
||||
local b = { 'a', 'b', 'c', a }
|
||||
a[4] = b
|
||||
a[5] = a
|
||||
a[6] = b
|
||||
assert.equals(inspect(a), '<1>{ 1, 2, 3, <2>{ "a", "b", "c", <table 1> }, <table 1>, <table 2> }')
|
||||
end)
|
||||
|
||||
describe('The depth parameter', function()
|
||||
local level5 = { 1,2,3, a = { b = { c = { d = { e = 5 } } } } }
|
||||
local keys = { [level5] = true }
|
||||
|
||||
@ -123,16 +132,16 @@ describe( 'inspect', function()
|
||||
}]])
|
||||
end)
|
||||
it('is modifiable by the user', function()
|
||||
assert.equals(inspect(level5, 2), [[{ 1, 2, 3,
|
||||
assert.equals(inspect(level5, {depth = 2}), [[{ 1, 2, 3,
|
||||
a = {
|
||||
b = {...}
|
||||
}
|
||||
}]])
|
||||
assert.equals(inspect(level5, 1), [[{ 1, 2, 3,
|
||||
assert.equals(inspect(level5, {depth = 1}), [[{ 1, 2, 3,
|
||||
a = {...}
|
||||
}]])
|
||||
assert.equals(inspect(level5, 0), "{...}")
|
||||
assert.equals(inspect(level5, 4), [[{ 1, 2, 3,
|
||||
assert.equals(inspect(level5, {depth = 0}), "{...}")
|
||||
assert.equals(inspect(level5, {depth = 4}), [[{ 1, 2, 3,
|
||||
a = {
|
||||
b = {
|
||||
c = {
|
||||
@ -145,7 +154,7 @@ describe( 'inspect', function()
|
||||
end)
|
||||
|
||||
it('respects depth on keys', function()
|
||||
assert.equals(inspect(keys, 4), [[{
|
||||
assert.equals(inspect(keys, {depth = 4}), [[{
|
||||
[{ 1, 2, 3,
|
||||
a = {
|
||||
b = {
|
||||
@ -155,16 +164,6 @@ describe( 'inspect', function()
|
||||
}] = true
|
||||
}]])
|
||||
end)
|
||||
|
||||
it('displays <table x> instead of repeating an already existing table', function()
|
||||
local a = { 1, 2, 3 }
|
||||
local b = { 'a', 'b', 'c', a }
|
||||
a[4] = b
|
||||
a[5] = a
|
||||
a[6] = b
|
||||
assert.equals(inspect(a), '<1>{ 1, 2, 3, <2>{ "a", "b", "c", <table 1> }, <table 1>, <table 2> }')
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
describe('metatables', function()
|
||||
|
Loading…
Reference in New Issue
Block a user