1
0

Very minor work on recursion.

This commit is contained in:
Jon Michael Aanes 2017-01-16 16:22:46 +01:00
parent cad8258a6f
commit d848c96fb1
2 changed files with 28 additions and 3 deletions

View File

@ -196,7 +196,7 @@ local function escape_string (str)
end end
local function get_function_info (f) local function get_function_info (f)
-- NOTE: Functions best in LuaJIT or Lua 5.2+ -- NOTE: Works best in LuaJIT or Lua 5.2+
-- Regarding get-info: -- Regarding get-info:
-- * No need to includ 'f'. Function is already known -- * No need to includ 'f'. Function is already known
@ -454,9 +454,11 @@ function format_table (t, options, depth, l)
-- Empty or exteeding max-depth? -- Empty or exteeding max-depth?
if table_type == TABLE_TYPE_EMPTY then l[#l+1] = '{}'; return if table_type == TABLE_TYPE_EMPTY then l[#l+1] = '{}'; return
elseif depth ~= 'max' and depth >= options.max_depth then l[#l+1] = '{...}'; return elseif depth ~= 'max' and depth >= options.max_depth or l.visited[t] then l[#l+1] = '{...}'; return
end end
l.visited[t] = true
-- Single line? -- Single line?
if is_single_line_table(t) then format_single_line_map(t, options, l); return end if is_single_line_table(t) then format_single_line_map(t, options, l); return end
@ -651,7 +653,7 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local function pretty_format (value, options) local function pretty_format (value, options)
local l = {} local l = { visited = { next_mark = 1 } }
local options = options or {} local options = options or {}
options.max_depth = options.max_depth or math.huge options.max_depth = options.max_depth or math.huge
options.indent = options.indent or '\t' options.indent = options.indent or '\t'

View File

@ -650,6 +650,29 @@ format_test {
expect = '{\n\t{ a = \'hello\', b = \'hi\' },\n\t{ a = \'hi\', b = \'hello\' }\n}', expect = '{\n\t{ a = \'hello\', b = \'hi\' },\n\t{ a = \'hi\', b = \'hello\' }\n}',
} }
--------------------------------------------------------------------------------
-- Table recursion
do
local recursive = {}
recursive[1] = recursive
format_test {
input = recursive,
options = { max_depth = 5 },
expect = '{ {...} }',
}
format_test {
input = recursive,
options = { max_depth = 5, recursion = 'ignore' },
expect = '{ {...} }',
}
format_test {
input = recursive,
options = { max_depth = 5, recursion = 'marked' },
expect = '<1>{ <1>{...} }',
}
end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Table Sorting -- Table Sorting