From 9050d539622ab99a66b91d7e54ba94cb8f63390e Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Fri, 14 Apr 2017 13:09:05 +0200 Subject: [PATCH] Removed unused functionallity, and associated tests. --- analyze_structure.lua | 45 --------------------------------- test/test_analyze_structure.lua | 42 ------------------------------ 2 files changed, 87 deletions(-) diff --git a/analyze_structure.lua b/analyze_structure.lua index b891941..ea074ac 100644 --- a/analyze_structure.lua +++ b/analyze_structure.lua @@ -119,20 +119,6 @@ local function contains_only_nice_string_keys (t) return true end -local function contains_only_nice_number_indexes (t) - -- Predicate: Does t contain only number keys, all of which are integer, - -- larger than/equal 1 and less than the maximum index. - - local max_index = largest_number_index(t) - for k, v in pairs(t) do - if type(k) ~= 'number' or k < 1 or max_index < k or k ~= math.floor(k) then - return false - end - end - - return #t > 0 -end - local function is_set (t) -- Predicate: Does t contain only boolean values. local value_types = get_value_types(t) @@ -167,36 +153,6 @@ local function is_tabular (t) return true end -local is_short_table, is_simple_value - -function is_short_table (value) - -- Predicate: value is either an empty table, or one with a single simple - -- non-function element. - - if type(value) ~= 'table' then - error(('[pretty/internal]: Only tables allowed in function analyze_structure.is_short_table, but was given %s (%s)'):format(value, type(value)), 2) - end - - local first_key = next(value, nil) - if not first_key then - return true - elseif not next(value, first_key) == nil then - return false - end - - return type(value[first_key]) ~= 'table' - and is_simple_value( value[first_key] ) -end - -function is_simple_value (value) - -- Predicate: value is either nil, a boolean, a number, a short string or a - -- short table. - - return SIMPLE_VALUE_TYPES[ type(value) ] - or type(value) == 'string' and #value <= SHORT_STRING_MAX_LEN - or type(value) == 'table' and is_short_table(value) -end - -------------------------------------------------------------------------------- local function get_table_info (t) @@ -210,7 +166,6 @@ local function get_table_info (t) info.has_map = info.map_elems > 0 info.is_set = is_set(t) and info.nr_elems >= MINIMUM_NUMBER_OF_SET_ELEMENTS info.is_tabular = is_tabular(t) - info.is_short = is_short_table(t) -- TODO: Remove this. It's not used for anything. -- Determine type of table if not info.has_seq and not info.has_map then info.type = TABLE_TYPE.EMPTY diff --git a/test/test_analyze_structure.lua b/test/test_analyze_structure.lua index 7fb98c6..1385c56 100644 --- a/test/test_analyze_structure.lua +++ b/test/test_analyze_structure.lua @@ -125,48 +125,6 @@ SUITE:addTest('Not Tabular, due to varying lengths', function () assert(table_info.is_tabular == false) end) -SUITE:addTest('Very short/empty table', function () - local input = { } - local table_info = analyze_structure(input)[input] - - assert(table_info.is_short == true) -end) - -SUITE:addTest('Very short table', function () - local input = { 1 } - local table_info = analyze_structure(input)[input] - - assert(table_info.is_short == true) -end) - -SUITE:addTest('Recursive tables are not simple', function () - local input = { {} } - local table_info = analyze_structure(input)[input] - - assert(table_info.is_short == false) -end) - -SUITE:addTest('Short strings are simple', function () - local input = { 'hello' } - local table_info = analyze_structure(input)[input] - - assert(table_info.is_short == true) -end) - -SUITE:addTest('Long strings are not', function () - local input = { 'hello world' } - local table_info = analyze_structure(input)[input] - - assert(table_info.is_short == false) -end) - -SUITE:addTest('Even maps can be simple!', function () - local input = { a = 4 } - local table_info = analyze_structure(input)[input] - - assert(table_info.is_short == true) -end) - -------------------------------------------------------------------------------- -- Corner cases.