From 7195bfa42339afd0a50e8549c477f69d754f27b2 Mon Sep 17 00:00:00 2001 From: kikito Date: Sun, 6 Jul 2014 17:24:37 +0200 Subject: [PATCH] remove filter option --- inspect.lua | 32 ++++++------------- spec/inspect_spec.lua | 73 ------------------------------------------- 2 files changed, 9 insertions(+), 96 deletions(-) diff --git a/inspect.lua b/inspect.lua index 638a673..fdaf012 100644 --- a/inspect.lua +++ b/inspect.lua @@ -136,15 +136,6 @@ local function countTableAppearances(t, tableAppearances) return tableAppearances end -local function parse_filter(filter) - if type(filter) == 'function' then return filter end - -- not a function, so it must be a table or table-like - filter = type(filter) == 'table' and filter or {filter} - local dictionary = {} - for _,v in pairs(filter) do dictionary[v] = true end - return function(x) return dictionary[x] end -end - local function makePath(path, key) local newPath, len = {}, #path for i=1, len do newPath[i] = path[i] end @@ -156,7 +147,6 @@ end function inspect.inspect(rootObject, options) options = options or {} local depth = options.depth or math.huge - local filter = parse_filter(options.filter or {}) local tableAppearances = countTableAppearances(rootObject) @@ -269,20 +259,16 @@ function inspect.inspect(rootObject, options) -- putvalue is forward-declared before putTable & putKey putValue = function(v, path) - if filter(v, path) then - puts('') - else - local tv = type(v) + local tv = type(v) - if tv == 'string' then - puts(smartQuote(escape(v))) - elseif tv == 'number' or tv == 'boolean' or tv == 'nil' then - puts(tostring(v)) - elseif tv == 'table' then - putTable(v, path) - else - puts('<',tv,' ',getId(v),'>') - end + if tv == 'string' then + puts(smartQuote(escape(v))) + elseif tv == 'number' or tv == 'boolean' or tv == 'nil' then + puts(tostring(v)) + elseif tv == 'table' then + putTable(v, path) + else + puts('<',tv,' ',getId(v),'>') end end diff --git a/spec/inspect_spec.lua b/spec/inspect_spec.lua index 36daac8..229e4c7 100644 --- a/spec/inspect_spec.lua +++ b/spec/inspect_spec.lua @@ -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 = , - 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, - [] = "a is used as a key here" -}]]) - end) - - it('filtereds array values', function() - assert.equals(inspect({10,20,30}, {filter = {20}}), "{ 10, , 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, - = -}]]) - - 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 = - }, - 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}}), "{ , <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", , "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, , 3, , 5 }') - end) - - end) - describe('metatables', function() it('includes the metatable as an extra hash attribute', function()