|
|
|
@ -180,79 +180,6 @@ describe( 'inspect', function() |
|
|
|
|
end) |
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
describe('The filter option', function() |
|
|
|
|
|
|
|
|
|
it('filters hash values', function() |
|
|
|
|
local a = {'this is a'} |
|
|
|
|
local b = {x = 1, a = a} |
|
|
|
|
|
|
|
|
|
assert.equals(inspect(b, {filter = {a}}), [[{ |
|
|
|
|
a = <filtered>, |
|
|
|
|
x = 1 |
|
|
|
|
}]]) |
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
it('filtereds hash keys', function() |
|
|
|
|
local a = {'this is a'} |
|
|
|
|
local b = {x = 1, [a] = 'a is used as a key here'} |
|
|
|
|
|
|
|
|
|
assert.equals(inspect(b, {filter = {a}}), [[{ |
|
|
|
|
x = 1, |
|
|
|
|
[<filtered>] = "a is used as a key here" |
|
|
|
|
}]]) |
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
it('filtereds array values', function() |
|
|
|
|
assert.equals(inspect({10,20,30}, {filter = {20}}), "{ 10, <filtered>, 30 }") |
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
it('filtereds metatables', function() |
|
|
|
|
local a = {'this is a'} |
|
|
|
|
local b = setmetatable({x = 1}, a) |
|
|
|
|
assert.equals(inspect(b, {filter = {a}}), [[{ |
|
|
|
|
x = 1, |
|
|
|
|
<metatable> = <filtered> |
|
|
|
|
}]]) |
|
|
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
it('filters by path', function() |
|
|
|
|
local people = { tony = { age = 21 }, martha = { age = 34} } |
|
|
|
|
local hideMarthaAge = function(_,path) |
|
|
|
|
return table.concat(path, '.') == 'martha.age' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
assert.equals(inspect(people, {filter = hideMarthaAge}), [[{ |
|
|
|
|
martha = { |
|
|
|
|
age = <filtered> |
|
|
|
|
}, |
|
|
|
|
tony = { |
|
|
|
|
age = 21 |
|
|
|
|
} |
|
|
|
|
}]]) |
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
it('does not increase the table ids', function() |
|
|
|
|
local a = {'this is a'} |
|
|
|
|
local b = {} |
|
|
|
|
local c = {a, b, b} |
|
|
|
|
assert.equals(inspect(c, {filter = {a}}), "{ <filtered>, <1>{}, <table 1> }") |
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
it('can be a non table (gets interpreted as a table with one element)', function() |
|
|
|
|
assert.equals(inspect({'foo', 'bar', 'baz'}, {filter = "bar"}), '{ "foo", <filtered>, "baz" }') |
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
it('can be a function which returns true for the elements that needs to be filtered', function() |
|
|
|
|
local msg = inspect({1,2,3,4,5}, { filter = function(x) |
|
|
|
|
return type(x) == 'number' and x % 2 == 0 |
|
|
|
|
end }) |
|
|
|
|
|
|
|
|
|
assert.equals(msg, '{ 1, <filtered>, 3, <filtered>, 5 }') |
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
describe('metatables', function() |
|
|
|
|
|
|
|
|
|
it('includes the metatable as an extra hash attribute', function() |
|
|
|
|