1
0

Figured out that even more tests require AST traversal. Now we insert ... instead of attempting to find them.

This commit is contained in:
Jon Michael Aanes 2017-07-15 21:25:32 +02:00
parent 410978c4c4
commit 8005e75794
2 changed files with 15 additions and 14 deletions

View File

@ -58,12 +58,13 @@ end
-- FUNCTION_DEFINITION_MATCH is a lua pattern, for finding a function definition.
-- NOTE: It will match malformed unicode sequences, and thus assumes that the
-- string checked against have been checked by the lua interpreter.
local FUNCTION_DEFINITION_MATCH =
'.*%f[%a_]function%f[^%a_]%s*' .. -- Look for the function keyword
local FUNCTION_KEYWORD_MATCH = '%f[%a_]function%f[^%a_]'
local FUNCTION_DEFINITION_MATCH = '.-' .. -- Look for stuff before the function
FUNCTION_KEYWORD_MATCH .. '%s*' .. -- Look for the function keyword
'([a-zA-Z0-9\128-\255_.:]*)%s*' .. -- Look for the function name, if any
'(%([a-zA-Z0-9\128-\255_,. \t]*%))' .. -- Look for the function parameter list.
'[ \t]*(.+)[ \t]*' .. -- Look for the function body
'end' -- Look for the end keyword
'end' -- Look for the end keyword
local NR_CHARS_IN_LONG_FUNCTION_BODY = 30
@ -250,7 +251,7 @@ return function (value, depth, l, format_value)
if info.defined_how == 'string' then
-- Function was defined as a string
local _, body = get_function_paramlist_and_body(info)
if #body <= NR_CHARS_IN_LONG_FUNCTION_BODY and not body:find '\n' then
if #body <= NR_CHARS_IN_LONG_FUNCTION_BODY and not body:find '\n' and not body:find(FUNCTION_KEYWORD_MATCH) then
function_body = body
end
end

View File

@ -270,15 +270,7 @@ format_test {
}
format_test {
name = 'Embed nested function, when they end on different lines',
single = true,
adv_getlocal = true,
input = loadstring('return function () return function () end\nend')()(),
expect = 'function () end',
}
format_test {
name = 'If embedding the correct function becomes too hard, ignore 1',
name = 'Embedding nested function, when on same line is too hard 1',
single = true,
adv_getlocal = true,
input = loadstring('return function () return function () end end')(),
@ -286,13 +278,21 @@ format_test {
}
format_test {
name = 'If embedding the correct function becomes too hard, ignore 2',
name = 'Embedding nested function, when on same line is too hard 2',
single = true,
adv_getlocal = true,
input = loadstring('return function () return function () end end')()(),
expect = 'function () ... end',
}
format_test {
name = 'Embedding nested function, when they end on different lines is too hard',
single = true,
adv_getlocal = true,
input = loadstring('return function () return function () end\nend')()(),
expect = 'function () ... end',
}
format_test {
name = 'Embed functions which contains the word "function"',
single = true,