|
|
@ -182,39 +182,39 @@ describe( 'inspect', function() |
|
|
|
|
|
|
|
|
|
|
|
describe('the process option', function() |
|
|
|
describe('the process option', function() |
|
|
|
|
|
|
|
|
|
|
|
it('can be used to remove a particular element easily', function() |
|
|
|
it('removes one element', function() |
|
|
|
local names = {'Andrew', 'Peter', 'Ann' } |
|
|
|
local names = {'Andrew', 'Peter', 'Ann' } |
|
|
|
local removeAnn = function(item) if item ~= 'Ann' then return item end end |
|
|
|
local removeAnn = function(item) if item ~= 'Ann' then return item end end |
|
|
|
assert.equals(inspect(names, {process = removeAnn}), '{ "Andrew", "Peter" }') |
|
|
|
assert.equals(inspect(names, {process = removeAnn}), '{ "Andrew", "Peter" }') |
|
|
|
end) |
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
it('can use the path', function() |
|
|
|
it('uses the path', function() |
|
|
|
local names = {'Andrew', 'Peter', 'Ann' } |
|
|
|
local names = {'Andrew', 'Peter', 'Ann' } |
|
|
|
local removeThird = function(item, path) if path[1] ~= 3 then return item end end |
|
|
|
local removeThird = function(item, path) if path[1] ~= 3 then return item end end |
|
|
|
assert.equals(inspect(names, {process = removeThird}), '{ "Andrew", "Peter" }') |
|
|
|
assert.equals(inspect(names, {process = removeThird}), '{ "Andrew", "Peter" }') |
|
|
|
end) |
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
it('can replace values', function() |
|
|
|
it('replaces items', function() |
|
|
|
local names = {'Andrew', 'Peter', 'Ann' } |
|
|
|
local names = {'Andrew', 'Peter', 'Ann' } |
|
|
|
local filterAnn = function(item) return item == 'Ann' and '<filtered>' or item end |
|
|
|
local filterAnn = function(item) return item == 'Ann' and '<filtered>' or item end |
|
|
|
assert.equals(inspect(names, {process = filterAnn}), '{ "Andrew", "Peter", "<filtered>" }') |
|
|
|
assert.equals(inspect(names, {process = filterAnn}), '{ "Andrew", "Peter", "<filtered>" }') |
|
|
|
end) |
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
it('can nullify metatables', function() |
|
|
|
it('nullifies metatables', function() |
|
|
|
local mt = {'world'} |
|
|
|
local mt = {'world'} |
|
|
|
local t = setmetatable({'hello'}, mt) |
|
|
|
local t = setmetatable({'hello'}, mt) |
|
|
|
local removeMt = function(item) if item ~= mt then return item end end |
|
|
|
local removeMt = function(item) if item ~= mt then return item end end |
|
|
|
assert.equals(inspect(t, {process = removeMt}), '{ "hello" }') |
|
|
|
assert.equals(inspect(t, {process = removeMt}), '{ "hello" }') |
|
|
|
end) |
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
it('can nullify metatables via their paths', function() |
|
|
|
it('nullifies metatables using their paths', function() |
|
|
|
local mt = {'world'} |
|
|
|
local mt = {'world'} |
|
|
|
local t = setmetatable({'hello'}, mt) |
|
|
|
local t = setmetatable({'hello'}, mt) |
|
|
|
local removeMt = function(item, path) if path[#path] ~= '<metatable>' then return item end end |
|
|
|
local removeMt = function(item, path) if path[#path] ~= '<metatable>' then return item end end |
|
|
|
assert.equals(inspect(t, {process = removeMt}), '{ "hello" }') |
|
|
|
assert.equals(inspect(t, {process = removeMt}), '{ "hello" }') |
|
|
|
end) |
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
it('can nullify the root object', function() |
|
|
|
it('nullifies the root object', function() |
|
|
|
local names = {'Andrew', 'Peter', 'Ann' } |
|
|
|
local names = {'Andrew', 'Peter', 'Ann' } |
|
|
|
local removeNames = function(item) if item ~= names then return item end end |
|
|
|
local removeNames = function(item) if item ~= names then return item end end |
|
|
|
assert.equals(inspect(names, {process = removeNames}), 'nil') |
|
|
|
assert.equals(inspect(names, {process = removeNames}), 'nil') |
|
|
|