made depth default to infinite

This commit is contained in:
kikito 2012-10-29 23:32:44 +01:00
parent b744b7f3f8
commit 78c4643ba0
2 changed files with 8 additions and 9 deletions

View File

@ -148,7 +148,7 @@ end
function Inspector:putTable(t) function Inspector:putTable(t)
if self:alreadyVisited(t) then if self:alreadyVisited(t) then
self:puts('<table ', self:getId(t), '>') self:puts('<table ', self:getId(t), '>')
elseif self.level >= self.depth then elseif self.depth and self.level >= self.depth then
self:puts('{...}') self:puts('{...}')
else else
if self.tableAppearances[t] > 1 then if self.tableAppearances[t] > 1 then
@ -232,7 +232,6 @@ function Inspector:putKey(k)
end end
local function inspect(t, depth) local function inspect(t, depth)
depth = depth or 4
return tostring(Inspector:new(t, depth)) return tostring(Inspector:new(t, depth))
end end

View File

@ -96,12 +96,14 @@ context( 'inspect', function()
local level5 = { 1,2,3, a = { b = { c = { d = { e = 5 } } } } } local level5 = { 1,2,3, a = { b = { c = { d = { e = 5 } } } } }
local keys = { [level5] = true } local keys = { [level5] = true }
it('has a default depth of 4', function() it('has infinite depth by default', function()
assert_equal(inspect(level5), [[{ 1, 2, 3, assert_equal(inspect(level5), [[{ 1, 2, 3,
a = { a = {
b = { b = {
c = { c = {
d = {...} d = {
e = 5
}
} }
} }
} }
@ -117,13 +119,11 @@ context( 'inspect', function()
a = {...} a = {...}
}]]) }]])
assert_equal(inspect(level5, 0), "{...}") assert_equal(inspect(level5, 0), "{...}")
assert_equal(inspect(level5, 6), [[{ 1, 2, 3, assert_equal(inspect(level5, 4), [[{ 1, 2, 3,
a = { a = {
b = { b = {
c = { c = {
d = { d = {...}
e = 5
}
} }
} }
} }
@ -132,7 +132,7 @@ context( 'inspect', function()
end) end)
it('respects depth on keys', function() it('respects depth on keys', function()
assert_equal(inspect(keys), [[{ assert_equal(inspect(keys, 4), [[{
[{ 1, 2, 3, [{ 1, 2, 3,
a = { a = {
b = { b = {