depth works on values. It was too easy

This commit is contained in:
Enrique García Cota 2011-04-24 00:43:55 +02:00
parent 4e3eb102ed
commit 71bf1a87a0

View File

@ -47,11 +47,11 @@ context( 'inspect', function()
context('tables', function() context('tables', function()
test('Should work with simple array-like tables', function() test('Should work with simple array-like tables', function()
assert_equal(inspect({1,2,3}), "{1, 2, 3}" ) assert_equal(inspect({1,2,3}), "{ 1, 2, 3 }" )
end) end)
test('Should work with nested arrays', function() test('Should work with nested arrays', function()
assert_equal(inspect({'a','b','c', {'d','e'}, 'f'}), '{"a", "b", "c", {"d", "e"}, "f"}' ) assert_equal(inspect({'a','b','c', {'d','e'}, 'f'}), '{ "a", "b", "c", { "d", "e" }, "f" }' )
end) end)
test('Should work with simple dictionary tables', function() test('Should work with simple dictionary tables', function()
@ -69,7 +69,7 @@ context( 'inspect', function()
end) end)
test('Should work with hybrid tables', function() test('Should work with hybrid tables', function()
assert_equal(inspect({ 'a', {b = 1}, 2, c = 3, ['ahoy you'] = 4 }), [[{"a", { assert_equal(inspect({ 'a', {b = 1}, 2, c = 3, ['ahoy you'] = 4 }), [[{ "a", {
b = 1 b = 1
}, 2, }, 2,
["ahoy you"] = 4, ["ahoy you"] = 4,
@ -77,6 +77,32 @@ context( 'inspect', function()
}]]) }]])
end) end)
test('Should respect depth', function()
local level4 = { 1,2,3, a = { b = { c = { d = 4 } } } }
assert_equal(inspect(level4, 4), [[{ 1, 2, 3,
a = {
b = {
c = {
d = 4
}
}
}
}]])
assert_equal(inspect(level4, 3), [[{ 1, 2, 3,
a = {
b = {
c = {...}
}
}
}]])
assert_equal(inspect(level4, 2), [[{ 1, 2, 3,
a = {
b = {...}
}
}]])
end) end)
end)
end) end)