1
0

Made four spaces the default indent, instead of a tab character.

This commit is contained in:
Jon Michael Aanes 2017-06-09 17:24:05 +02:00
parent 25b294ec5d
commit 5c7354e40f
5 changed files with 24 additions and 25 deletions

View File

@ -172,6 +172,5 @@ end
return function (value, depth, l)
assert(type(value) == 'number')
assert(type(depth) == 'number' and type(l) == 'table')
-- TODO: Add support for more relaxed representations.
l[#l+1] = format_num(value, CAN_USE_SHORTHAND and l.options.math_shorthand, l.options.soft_numbers)
end

View File

@ -467,7 +467,7 @@ local KNOWN_OPTIONS = {
_all_function_info = { type = 'boolean', default = false },
cut_strings = { type = 'boolean', default = false },
include_closure = { type = 'boolean', default = false },
indent = { type = 'string', default = '\t' }, -- TODO: Change default to ' '.
indent = { type = 'string', default = ' ' },
math_shorthand = { type = 'boolean', default = false },
soft_numbers = { type = 'boolean', default = true }, -- TODO: Add support for maximally precise numbers.
max_depth = { type = 'number', default = math.huge },

View File

@ -93,7 +93,7 @@ do
input = function () l = SOME_RANDOM_UPVALUE end,
adv_getlocal = true,
options = { more_function_info = true },
expect = 'function ()\n\t-- source_file: \'./test/test_function.lua\' [Line: '..func_line..']\n\t-- up_values: { SOME_RANDOM_UPVALUE = false }\n\n\t...\nend'
expect = 'function ()\n -- source_file: \'./test/test_function.lua\' [Line: '..func_line..']\n -- up_values: { SOME_RANDOM_UPVALUE = false }\n\n ...\nend'
}
local func_line = curline(2) -- Must be exactly 2 lines above function
@ -101,7 +101,7 @@ do
input = function () SOME_RANDOM_UPVALUE = true end,
adv_getlocal = true,
options = { more_function_info = true },
expect = 'function ()\n\t-- source_file: \'./test/test_function.lua\' [Line: '..func_line..']\n\t-- up_values: { SOME_RANDOM_UPVALUE = false }\n\n\t...\nend'
expect = 'function ()\n -- source_file: \'./test/test_function.lua\' [Line: '..func_line..']\n -- up_values: { SOME_RANDOM_UPVALUE = false }\n\n ...\nend'
}
end
@ -111,7 +111,7 @@ do
input = function () end,
adv_getlocal = true,
options = { more_function_info = true },
expect = 'function ()\n\t-- source_file: \'./test/test_function.lua\' [Line: '..func_line..']\n\n\t...\nend'
expect = 'function ()\n -- source_file: \'./test/test_function.lua\' [Line: '..func_line..']\n\n ...\nend'
}
end
@ -129,7 +129,7 @@ do
input = function () index = index + 1; return index end,
adv_getlocal = true,
options = { more_function_info = true },
expect = 'function ()\n\t-- source_file: \'./test/test_function.lua\' [Line: '..func_line..']\n\t-- up_values: { index = 0 }\n\n\t...\nend'
expect = 'function ()\n -- source_file: \'./test/test_function.lua\' [Line: '..func_line..']\n -- up_values: { index = 0 }\n\n ...\nend'
}
end
@ -167,9 +167,9 @@ format_test {
format_test {
-- More function info allows one to even get the function whole, if it was defined in a string.
input = loadstring('return function (a, b)\n\treturn a + b\nend')(),
input = loadstring('return function (a, b)\n return a + b\nend')(),
options = { more_function_info = true },
expect = 'function (a, b)\n\treturn a + b\nend',
expect = 'function (a, b)\n return a + b\nend',
}
do
@ -180,7 +180,7 @@ do
end,
adv_getlocal = true,
options = { more_function_info = true },
expect = 'function ()\n\t-- source_file: \'./test/test_function.lua\' [Lines: '..func_line..' - '..(func_line+2)..']\n\n\t...\nend',
expect = 'function ()\n -- source_file: \'./test/test_function.lua\' [Lines: '..func_line..' - '..(func_line+2)..']\n\n ...\nend',
}
local func_line = curline(2) -- Must be exactly 2 lines above function
@ -188,7 +188,7 @@ do
input = function () --[[ NOTE: This function must cover a single line of code! ]] end,
adv_getlocal = true,
options = { more_function_info = true },
expect = 'function ()\n\t-- source_file: \'./test/test_function.lua\' [Line: '..func_line..']\n\n\t...\nend',
expect = 'function ()\n -- source_file: \'./test/test_function.lua\' [Line: '..func_line..']\n\n ...\nend',
}
end
@ -200,7 +200,7 @@ format_test {
format_test {
input = math.abs,
options = { more_function_info = true },
expect = 'builtin function (x)\n\t-- math.abs\n\t-- Returns the absolute value of x.\n\n\t...\nend',
expect = 'builtin function (x)\n -- math.abs\n -- Returns the absolute value of x.\n\n ...\nend',
}
format_test {
@ -211,13 +211,13 @@ format_test {
format_test {
input = math.random,
options = { more_function_info = true },
expect = 'builtin function ([m [, n])\n\t-- math.random\n\t-- When called without arguments, returns a uniform pseudo-random real number in the range [0,1). When called with an integer number m, math.random returns a uniform pseudo-random integer in the range [1, m]. When called with two integer numbers m and n, math.random returns a uniform pseudo-random integer in the range [m, n].\n\n\t...\nend',
expect = 'builtin function ([m [, n])\n -- math.random\n -- When called without arguments, returns a uniform pseudo-random real number in the range [0,1). When called with an integer number m, math.random returns a uniform pseudo-random integer in the range [1, m]. When called with two integer numbers m and n, math.random returns a uniform pseudo-random integer in the range [m, n].\n\n ...\nend',
}
format_test {
input = string.byte,
options = { more_function_info = true },
expect = 'builtin function (s [, i [, j]])\n\t-- string.byte\n\t-- Returns the internal numerical codes of the characters s[i], s[i+1], ..., s[j]. The default value for i is 1; the default value for j is i.\n\t-- Note that numerical codes are not necessarily portable across platforms.\n\n\t...\nend',
expect = 'builtin function (s [, i [, j]])\n -- string.byte\n -- Returns the internal numerical codes of the characters s[i], s[i+1], ..., s[j]. The default value for i is 1; the default value for j is i.\n -- Note that numerical codes are not necessarily portable across platforms.\n\n ...\nend',
}
-- short_builtins option: If an builtin is expected to be available by some name
@ -343,7 +343,7 @@ format_test {
name = 'Closures do not affect builtins',
input = math.abs,
options = { more_function_info = true, include_closure = true },
expect = 'builtin function (x)\n\t-- math.abs\n\t-- Returns the absolute value of x.\n\n\t...\nend',
expect = 'builtin function (x)\n -- math.abs\n -- Returns the absolute value of x.\n\n ...\nend',
}
--------------------------------------------------------------------------------
@ -352,14 +352,14 @@ format_test {
format_test {
-- The tail part should align, letting people focus on the important aspects.
input = { random = math.random, abs = math.abs },
expect = '{\n\tabs = builtin function (x) ... end,\n\trandom = builtin function ([m [, n]) ... end\n}',
expect = '{\n abs = builtin function (x) ... end,\n random = builtin function ([m [, n]) ... end\n}',
}
format_test {
-- The function part should align, if some are builtin and some are not.
adv_getlocal = true,
input = { random = math.random, abs = function (x) return x < 0 and -x or x end },
expect = '{\n\tabs = function (x) ... end,\n\trandom = builtin function ([m [, n]) ... end\n}',
expect = '{\n abs = function (x) ... end,\n random = builtin function ([m [, n]) ... end\n}',
}
format_test {
@ -368,7 +368,7 @@ format_test {
input = { max = function(a, b) return a > b and a or b end,
abs = function (x) return x < 0 and -x or x end
},
expect = '{\n\tabs = function (x) ... end,\n\tmax = function (a, b) ... end\n}',
expect = '{\n abs = function (x) ... end,\n max = function (a, b) ... end\n}',
}

View File

@ -293,7 +293,7 @@ format_test {
format_test {
-- Table view, with indent.
input = { { a = 'hello', b = 'hi' }, { a = 'hi', b = 'hello' } },
expect = '{\n\t{ a = \'hello\', b = \'hi\' },\n\t{ a = \'hi\', b = \'hello\' }\n}',
expect = '{\n { a = \'hello\', b = \'hi\' },\n { a = \'hi\', b = \'hello\' }\n}',
}
--------------------------------------------------------------------------------
@ -328,7 +328,7 @@ do
name = 'Top layers should be expanded, rather than lower layers.',
input = rec,
options = { max_depth = 5 },
expect = '{\n\ta = { {...} },\n\tb = { {...} }\n}',
expect = '{\n a = { {...} },\n b = { {...} }\n}',
}
end

View File

@ -52,7 +52,7 @@ format_test {
format_test {
input = { [1] = {}, [2] = {}, [3] = {}, ['down_info'] = {}, ['up_info'] = {} },
expect = '{\n\t[1] = {},\n\t[2] = {},\n\t[3] = {},\n\t[\'down_info\'] = {},\n\t[\'up_info\'] = {}\n}',
expect = '{\n [1] = {},\n [2] = {},\n [3] = {},\n [\'down_info\'] = {},\n [\'up_info\'] = {}\n}',
}
format_test {
@ -96,7 +96,7 @@ local EXAMPLE_1_INPUT = {
['z9.doc'] = 1,
}
local EXAMPLE_1_OUTPUT = [[{
local EXAMPLE_1_OUTPUT = ([[{
['z1.doc'] = 1,
['z2.doc'] = 1,
['z3.doc'] = 1,
@ -120,7 +120,7 @@ local EXAMPLE_1_OUTPUT = [[{
['z100.doc'] = 1,
['z101.doc'] = 1,
['z102.doc'] = 1
}]]
}]]):gsub('\t', ' ')
SUITE:addTest('alphanum algorithm example 1', function ()
-- This is a test-case taken from http://www.davekoelle.com/alphanum.html
@ -169,7 +169,7 @@ local EXAMPLE_2_INPUT = {
['Xiph Xlater 58'] = 1,
}
local EXAMPLE_2_OUTPUT = [[{
local EXAMPLE_2_OUTPUT = ([[{
['10X Radonius'] = 1,
['20X Radonius'] = 1,
['20X Radonius Prime'] = 1,
@ -205,7 +205,7 @@ local EXAMPLE_2_OUTPUT = [[{
['Xiph Xlater 2000'] = 1,
['Xiph Xlater 5000'] = 1,
['Xiph Xlater 10000'] = 1
}]]
}]]):gsub('\t', ' ')
SUITE:addTest('alphanum algorithm example 2', function ()
@ -217,7 +217,7 @@ end)
SUITE:addTest('alphanum algorithm extension 1', function ()
-- This is a test-case taken from http://www.davekoelle.com/alphanum.html
local OUTPUT = "{\n\t['z2'] = 1,\n\t['z2.'] = 1,\n\t['z2.z'] = 1,\n\t['z2.0'] = 1\n}"
local OUTPUT = "{\n ['z2'] = 1,\n ['z2.'] = 1,\n ['z2.z'] = 1,\n ['z2.0'] = 1\n}"
assert_equal(OUTPUT, pretty { ['z2.z'] = 1, ['z2.0'] = 1, ['z2.'] = 1, ['z2'] = 1 })
end)