2016-04-23 16:53:11 -07:00
|
|
|
local assert = require('luassert')
|
|
|
|
local lfs = require('lfs')
|
|
|
|
|
|
|
|
local check_logs_useless_lines = {
|
|
|
|
['Warning: noted but unhandled ioctl']=1,
|
|
|
|
['could cause spurious value errors to appear']=2,
|
|
|
|
['See README_MISSING_SYSCALL_OR_IOCTL for guidance']=3,
|
|
|
|
}
|
|
|
|
|
|
|
|
local eq = function(exp, act)
|
|
|
|
return assert.are.same(exp, act)
|
|
|
|
end
|
|
|
|
local neq = function(exp, act)
|
|
|
|
return assert.are_not.same(exp, act)
|
|
|
|
end
|
|
|
|
local ok = function(res)
|
|
|
|
return assert.is_true(res)
|
|
|
|
end
|
|
|
|
|
2017-04-09 06:49:31 -07:00
|
|
|
-- initial_path: directory to recurse into
|
|
|
|
-- re: include pattern (string)
|
|
|
|
-- exc_re: exclude pattern(s) (string or table)
|
2016-11-04 08:20:58 -07:00
|
|
|
local function glob(initial_path, re, exc_re)
|
2017-04-09 06:49:31 -07:00
|
|
|
exc_re = type(exc_re) == 'table' and exc_re or { exc_re }
|
2016-11-04 08:20:58 -07:00
|
|
|
local paths_to_check = {initial_path}
|
|
|
|
local ret = {}
|
|
|
|
local checked_files = {}
|
2017-04-09 06:49:31 -07:00
|
|
|
local function is_excluded(path)
|
|
|
|
for _, pat in pairs(exc_re) do
|
|
|
|
if path:match(pat) then return true end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2017-04-14 11:34:54 -07:00
|
|
|
if is_excluded(initial_path) then
|
|
|
|
return ret
|
|
|
|
end
|
2016-11-04 08:20:58 -07:00
|
|
|
while #paths_to_check > 0 do
|
|
|
|
local cur_path = paths_to_check[#paths_to_check]
|
|
|
|
paths_to_check[#paths_to_check] = nil
|
|
|
|
for e in lfs.dir(cur_path) do
|
|
|
|
local full_path = cur_path .. '/' .. e
|
|
|
|
local checked_path = full_path:sub(#initial_path + 1)
|
2017-04-09 06:49:31 -07:00
|
|
|
if (not is_excluded(checked_path)) and e:sub(1, 1) ~= '.' then
|
2016-11-04 08:20:58 -07:00
|
|
|
local attrs = lfs.attributes(full_path)
|
2017-03-11 14:25:55 -07:00
|
|
|
if attrs then
|
|
|
|
local check_key = attrs.dev .. ':' .. tostring(attrs.ino)
|
|
|
|
if not checked_files[check_key] then
|
|
|
|
checked_files[check_key] = true
|
|
|
|
if attrs.mode == 'directory' then
|
|
|
|
paths_to_check[#paths_to_check + 1] = full_path
|
|
|
|
elseif not re or checked_path:match(re) then
|
|
|
|
ret[#ret + 1] = full_path
|
|
|
|
end
|
2016-11-04 08:20:58 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2016-04-23 16:53:11 -07:00
|
|
|
local function check_logs()
|
|
|
|
local log_dir = os.getenv('LOG_DIR')
|
|
|
|
local runtime_errors = 0
|
|
|
|
if log_dir and lfs.attributes(log_dir, 'mode') == 'directory' then
|
|
|
|
for tail in lfs.dir(log_dir) do
|
|
|
|
if tail:sub(1, 30) == 'valgrind-' or tail:find('san%.') then
|
|
|
|
local file = log_dir .. '/' .. tail
|
|
|
|
local fd = io.open(file)
|
|
|
|
local start_msg = ('='):rep(20) .. ' File ' .. file .. ' ' .. ('='):rep(20)
|
|
|
|
local lines = {}
|
|
|
|
local warning_line = 0
|
|
|
|
for line in fd:lines() do
|
|
|
|
local cur_warning_line = check_logs_useless_lines[line]
|
|
|
|
if cur_warning_line == warning_line + 1 then
|
|
|
|
warning_line = cur_warning_line
|
|
|
|
else
|
|
|
|
lines[#lines + 1] = line
|
|
|
|
end
|
|
|
|
end
|
|
|
|
fd:close()
|
|
|
|
os.remove(file)
|
|
|
|
if #lines > 0 then
|
|
|
|
-- local out = os.getenv('TRAVIS_CI_BUILD') and io.stdout or io.stderr
|
|
|
|
local out = io.stdout
|
|
|
|
out:write(start_msg .. '\n')
|
|
|
|
out:write('= ' .. table.concat(lines, '\n= ') .. '\n')
|
|
|
|
out:write(select(1, start_msg:gsub('.', '=')) .. '\n')
|
|
|
|
runtime_errors = runtime_errors + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
assert(0 == runtime_errors)
|
|
|
|
end
|
|
|
|
|
2017-01-02 22:46:44 -07:00
|
|
|
-- Tries to get platform name from $SYSTEM_NAME, uname; fallback is "Windows".
|
|
|
|
local uname = (function()
|
|
|
|
local platform = nil
|
|
|
|
return (function()
|
|
|
|
if platform then
|
|
|
|
return platform
|
|
|
|
end
|
|
|
|
|
|
|
|
platform = os.getenv("SYSTEM_NAME")
|
|
|
|
if platform then
|
|
|
|
return platform
|
|
|
|
end
|
|
|
|
|
|
|
|
local status, f = pcall(io.popen, "uname -s")
|
|
|
|
if status then
|
|
|
|
platform = f:read("*l")
|
2017-01-14 01:47:33 -07:00
|
|
|
f:close()
|
2017-01-02 22:46:44 -07:00
|
|
|
else
|
|
|
|
platform = 'Windows'
|
|
|
|
end
|
|
|
|
return platform
|
|
|
|
end)
|
|
|
|
end)()
|
|
|
|
|
2017-04-09 06:49:31 -07:00
|
|
|
local function tmpdir_get()
|
|
|
|
return os.getenv('TMPDIR') and os.getenv('TMPDIR') or os.getenv('TEMP')
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Is temp directory `dir` defined local to the project workspace?
|
|
|
|
local function tmpdir_is_local(dir)
|
|
|
|
return not not (dir and string.find(dir, 'Xtest'))
|
|
|
|
end
|
|
|
|
|
2017-03-29 11:07:39 -07:00
|
|
|
local tmpname = (function()
|
|
|
|
local seq = 0
|
2017-04-09 06:49:31 -07:00
|
|
|
local tmpdir = tmpdir_get()
|
2017-03-29 11:07:39 -07:00
|
|
|
return (function()
|
2017-04-09 06:49:31 -07:00
|
|
|
if tmpdir_is_local(tmpdir) then
|
2017-03-29 11:07:39 -07:00
|
|
|
-- Cannot control os.tmpname() dir, so hack our own tmpname() impl.
|
|
|
|
seq = seq + 1
|
|
|
|
local fname = tmpdir..'/nvim-test-lua-'..seq
|
|
|
|
io.open(fname, 'w'):close()
|
|
|
|
return fname
|
|
|
|
else
|
|
|
|
local fname = os.tmpname()
|
|
|
|
if uname() == 'Windows' and fname:sub(1, 2) == '\\s' then
|
|
|
|
-- In Windows tmpname() returns a filename starting with
|
|
|
|
-- special sequence \s, prepend $TEMP path
|
|
|
|
return tmpdir..fname
|
|
|
|
elseif fname:match('^/tmp') and uname() == 'Darwin' then
|
|
|
|
-- In OS X /tmp links to /private/tmp
|
|
|
|
return '/private'..fname
|
|
|
|
else
|
|
|
|
return fname
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end)()
|
2017-01-02 22:46:44 -07:00
|
|
|
|
put fixup, esp. ". register close #5709 #5781
Note some bugs were judged to have too ugly a fix to solve, tests to
demonstrate these problems, and the explanation behind not fixing them
are below.
describe('register . problems', function()
before_each(reset)
-- The difficulty here is: The basic requirement is that the text
-- inserted is treated as if it were typed in insert mode. This is why
-- the paste method is to enter insert mode and enter the ". register
-- into readbuf1.
-- We can't add a count into the readbuf here because the insert mode
-- count is implemented with readbuf2 which is checked for characters
-- after readbuf1.
-- Hence, the ".gp command (which adds extra characters into readbuf1
-- to emulate leaving the cursor after the text by moving the cursor
-- after inserting the text) would insert the motion characters into
-- the buffer instead of using them to move after the insert has been
-- done.
-- I could probably get this working properly with a special flag put
-- into start_redo_ins() and set in do_put(), but I think this adds
-- much more complexity than fixing this bug justifies.
pending('should not change the ". register with ".2p', function()
local orig_register = funcs.getreg('.')
feed('2".p')
eq(orig_register, funcs.getreg('.'))
end)
describe("cursor positioning after undo and redo with '.'", function()
before_each(reset)
local function make_cursor_test(macro_string)
return function()
feed(macro_string)
local afterpos = funcs.getcurpos()
local orig_string = curbuf_contents()
feed('u.')
eq(afterpos, funcs.getcurpos())
expect(orig_string)
end
end
-- The difficulty here is: setting the cursor after the end of the
-- pasted text is done by adding a motion command to the
-- stuffbuffer after the insert.
-- Modifying 'redobuff' is done in the code that handles inserting
-- text and moving around.
-- I could add a special case in ins_esc() that checks for a flag
-- set in do_put() to add the motion character to the redo buffer,
-- but I think that is starting to get way too convoluted for the
-- benefit.
pending('should be the same after ".gp and ".gpu.',
make_cursor_test('".gp'))
-- The difficulty here is: putting forwards is implemented by using
-- 'a' instead of 'i' to start insert.
-- Undoing with 'u' an insert that began with 'a' leaves the cursor
-- where the first character was inserted, not where the cursor was
-- when the 'a' was pressed.
-- We account for this the first time by saving the cursor position
-- in do_put(), but this isn't stored in redobuff for a second time
-- around.
-- We can't change how such a fundamental action as undo after
-- inserting with 'a' behaves, we could add in a special case
-- whereby we set a flag in do_put() and read it when entering
-- insert mode but this seems like way too much to fix such a minor
-- bug.
pending('should be the same after ".pu. and ".pu.u.',
make_cursor_test('".pu.'))
end)
end)
2016-12-12 07:04:44 -07:00
|
|
|
local function map(func, tab)
|
|
|
|
local rettab = {}
|
|
|
|
for k, v in pairs(tab) do
|
|
|
|
rettab[k] = func(v)
|
|
|
|
end
|
|
|
|
return rettab
|
|
|
|
end
|
|
|
|
|
|
|
|
local function filter(filter_func, tab)
|
|
|
|
local rettab = {}
|
|
|
|
for _, entry in pairs(tab) do
|
|
|
|
if filter_func(entry) then
|
|
|
|
table.insert(rettab, entry)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return rettab
|
|
|
|
end
|
|
|
|
|
2016-11-04 08:20:58 -07:00
|
|
|
local function hasenv(name)
|
|
|
|
local env = os.getenv(name)
|
|
|
|
if env and env ~= '' then
|
|
|
|
return env
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
local tests_skipped = 0
|
|
|
|
|
2017-04-05 22:23:33 -07:00
|
|
|
local function check_cores(app, force)
|
2016-11-04 08:20:58 -07:00
|
|
|
app = app or 'build/bin/nvim'
|
|
|
|
local initial_path, re, exc_re
|
|
|
|
local gdb_db_cmd = 'gdb -n -batch -ex "thread apply all bt full" "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"'
|
|
|
|
local lldb_db_cmd = 'lldb -Q -o "bt all" -f "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"'
|
|
|
|
local random_skip = false
|
2017-04-14 11:34:54 -07:00
|
|
|
-- Workspace-local $TMPDIR, scrubbed and pattern-escaped.
|
|
|
|
-- "./Xtest-tmpdir/" => "Xtest%-tmpdir"
|
|
|
|
local local_tmpdir = (tmpdir_is_local(tmpdir_get())
|
|
|
|
and tmpdir_get():gsub('^[ ./]+',''):gsub('%/+$',''):gsub('([^%w])', '%%%1')
|
|
|
|
or nil)
|
2016-11-04 08:20:58 -07:00
|
|
|
local db_cmd
|
|
|
|
if hasenv('NVIM_TEST_CORE_GLOB_DIRECTORY') then
|
|
|
|
initial_path = os.getenv('NVIM_TEST_CORE_GLOB_DIRECTORY')
|
|
|
|
re = os.getenv('NVIM_TEST_CORE_GLOB_RE')
|
2017-04-09 06:49:31 -07:00
|
|
|
exc_re = { os.getenv('NVIM_TEST_CORE_EXC_RE'), local_tmpdir }
|
2016-11-04 08:20:58 -07:00
|
|
|
db_cmd = os.getenv('NVIM_TEST_CORE_DB_CMD') or gdb_db_cmd
|
|
|
|
random_skip = os.getenv('NVIM_TEST_CORE_RANDOM_SKIP')
|
|
|
|
elseif os.getenv('TRAVIS_OS_NAME') == 'osx' then
|
|
|
|
initial_path = '/cores'
|
|
|
|
re = nil
|
2017-04-09 06:49:31 -07:00
|
|
|
exc_re = { local_tmpdir }
|
2016-11-04 08:20:58 -07:00
|
|
|
db_cmd = lldb_db_cmd
|
|
|
|
else
|
|
|
|
initial_path = '.'
|
2017-02-13 14:32:18 -07:00
|
|
|
re = '/core[^/]*$'
|
2017-04-09 06:49:31 -07:00
|
|
|
exc_re = { '^/%.deps$', local_tmpdir }
|
2016-11-04 08:20:58 -07:00
|
|
|
db_cmd = gdb_db_cmd
|
|
|
|
random_skip = true
|
|
|
|
end
|
|
|
|
-- Finding cores takes too much time on linux
|
2017-04-05 22:23:33 -07:00
|
|
|
if not force and random_skip and math.random() < 0.9 then
|
2016-11-04 08:20:58 -07:00
|
|
|
tests_skipped = tests_skipped + 1
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local cores = glob(initial_path, re, exc_re)
|
|
|
|
local found_cores = 0
|
|
|
|
local out = io.stdout
|
|
|
|
for _, core in ipairs(cores) do
|
|
|
|
local len = 80 - #core - #('Core file ') - 2
|
|
|
|
local esigns = ('='):rep(len / 2)
|
|
|
|
out:write(('\n%s Core file %s %s\n'):format(esigns, core, esigns))
|
|
|
|
out:flush()
|
2017-09-05 08:38:14 -07:00
|
|
|
os.execute(db_cmd:gsub('%$_NVIM_TEST_APP', app):gsub('%$_NVIM_TEST_CORE', core) .. ' 2>&1')
|
|
|
|
out:write('\n')
|
2016-11-04 08:20:58 -07:00
|
|
|
found_cores = found_cores + 1
|
|
|
|
os.remove(core)
|
|
|
|
end
|
|
|
|
if found_cores ~= 0 then
|
|
|
|
out:write(('\nTests covered by this check: %u\n'):format(tests_skipped + 1))
|
|
|
|
end
|
|
|
|
tests_skipped = 0
|
2017-02-22 11:14:06 -07:00
|
|
|
if found_cores > 0 then
|
|
|
|
error("crash detected (see above)")
|
|
|
|
end
|
2016-11-04 08:20:58 -07:00
|
|
|
end
|
|
|
|
|
2017-03-11 03:28:18 -07:00
|
|
|
local function which(exe)
|
|
|
|
local pipe = io.popen('which ' .. exe, 'r')
|
|
|
|
local ret = pipe:read('*a')
|
|
|
|
pipe:close()
|
2017-03-11 13:13:09 -07:00
|
|
|
if ret == '' then
|
|
|
|
return nil
|
|
|
|
else
|
|
|
|
return ret:sub(1, -2)
|
|
|
|
end
|
2017-03-11 03:28:18 -07:00
|
|
|
end
|
|
|
|
|
2017-01-20 14:00:47 -07:00
|
|
|
local function shallowcopy(orig)
|
2017-11-12 15:10:39 -07:00
|
|
|
if type(orig) ~= 'table' then
|
|
|
|
return orig
|
|
|
|
end
|
2017-01-20 14:00:47 -07:00
|
|
|
local copy = {}
|
|
|
|
for orig_key, orig_value in pairs(orig) do
|
|
|
|
copy[orig_key] = orig_value
|
|
|
|
end
|
|
|
|
return copy
|
|
|
|
end
|
|
|
|
|
2017-11-05 11:06:12 -07:00
|
|
|
local deepcopy
|
|
|
|
|
|
|
|
local function id(v)
|
|
|
|
return v
|
|
|
|
end
|
|
|
|
|
|
|
|
local deepcopy_funcs = {
|
|
|
|
table = function(orig)
|
|
|
|
local copy = {}
|
|
|
|
for k, v in pairs(orig) do
|
|
|
|
copy[deepcopy(k)] = deepcopy(v)
|
|
|
|
end
|
2017-12-03 10:22:09 -07:00
|
|
|
return copy
|
2017-11-05 11:06:12 -07:00
|
|
|
end,
|
|
|
|
number = id,
|
|
|
|
string = id,
|
|
|
|
['nil'] = id,
|
|
|
|
boolean = id,
|
|
|
|
}
|
|
|
|
|
|
|
|
deepcopy = function(orig)
|
|
|
|
return deepcopy_funcs[type(orig)](orig)
|
|
|
|
end
|
|
|
|
|
|
|
|
local REMOVE_THIS = {}
|
|
|
|
|
|
|
|
local function mergedicts_copy(d1, d2)
|
|
|
|
local ret = shallowcopy(d1)
|
|
|
|
for k, v in pairs(d2) do
|
|
|
|
if d2[k] == REMOVE_THIS then
|
|
|
|
ret[k] = nil
|
2017-11-06 10:28:37 -07:00
|
|
|
elseif type(d1[k]) == 'table' and type(v) == 'table' then
|
|
|
|
ret[k] = mergedicts_copy(d1[k], v)
|
2017-11-05 11:06:12 -07:00
|
|
|
else
|
2017-11-06 10:28:37 -07:00
|
|
|
ret[k] = v
|
2017-11-05 11:06:12 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2017-11-12 08:52:49 -07:00
|
|
|
-- dictdiff: find a diff so that mergedicts_copy(d1, diff) is equal to d2
|
|
|
|
--
|
2017-11-12 15:10:39 -07:00
|
|
|
-- Note: does not do copies of d2 values used.
|
2017-11-12 08:52:49 -07:00
|
|
|
local function dictdiff(d1, d2)
|
|
|
|
local ret = {}
|
|
|
|
local hasdiff = false
|
|
|
|
for k, v in pairs(d1) do
|
|
|
|
if d2[k] == nil then
|
|
|
|
hasdiff = true
|
|
|
|
ret[k] = REMOVE_THIS
|
|
|
|
elseif type(v) == type(d2[k]) then
|
2017-11-12 15:10:39 -07:00
|
|
|
if type(v) == 'table' then
|
2017-11-12 08:52:49 -07:00
|
|
|
local subdiff = dictdiff(v, d2[k])
|
|
|
|
if subdiff ~= nil then
|
|
|
|
hasdiff = true
|
|
|
|
ret[k] = subdiff
|
|
|
|
end
|
|
|
|
elseif v ~= d2[k] then
|
|
|
|
ret[k] = d2[k]
|
2017-11-12 15:10:39 -07:00
|
|
|
hasdiff = true
|
2017-11-12 08:52:49 -07:00
|
|
|
end
|
|
|
|
else
|
|
|
|
ret[k] = d2[k]
|
2017-11-12 15:10:39 -07:00
|
|
|
hasdiff = true
|
2017-11-12 08:52:49 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
for k, v in pairs(d2) do
|
|
|
|
if d1[k] == nil then
|
2017-11-12 15:10:39 -07:00
|
|
|
ret[k] = shallowcopy(v)
|
2017-11-12 08:52:49 -07:00
|
|
|
hasdiff = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if hasdiff then
|
|
|
|
return ret
|
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-06 10:15:05 -07:00
|
|
|
local function updated(d, d2)
|
|
|
|
for k, v in pairs(d2) do
|
|
|
|
d[k] = v
|
|
|
|
end
|
|
|
|
return d
|
|
|
|
end
|
|
|
|
|
2017-03-04 15:09:55 -07:00
|
|
|
local function concat_tables(...)
|
|
|
|
local ret = {}
|
|
|
|
for i = 1, select('#', ...) do
|
|
|
|
local tbl = select(i, ...)
|
|
|
|
if tbl then
|
|
|
|
for _, v in ipairs(tbl) do
|
|
|
|
ret[#ret + 1] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2017-06-20 08:17:19 -07:00
|
|
|
local function dedent(str, leave_indent)
|
2017-04-01 02:52:28 -07:00
|
|
|
-- find minimum common indent across lines
|
|
|
|
local indent = nil
|
|
|
|
for line in str:gmatch('[^\n]+') do
|
|
|
|
local line_indent = line:match('^%s+') or ''
|
|
|
|
if indent == nil or #line_indent < #indent then
|
|
|
|
indent = line_indent
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if indent == nil or #indent == 0 then
|
|
|
|
-- no minimum common indent
|
|
|
|
return str
|
|
|
|
end
|
2017-06-20 08:17:19 -07:00
|
|
|
local left_indent = (' '):rep(leave_indent or 0)
|
2017-04-01 02:52:28 -07:00
|
|
|
-- create a pattern for the indent
|
|
|
|
indent = indent:gsub('%s', '[ \t]')
|
|
|
|
-- strip it from the first line
|
2017-06-20 08:17:19 -07:00
|
|
|
str = str:gsub('^'..indent, left_indent)
|
2017-04-01 02:52:28 -07:00
|
|
|
-- strip it from the remaining lines
|
2017-06-20 08:17:19 -07:00
|
|
|
str = str:gsub('[\n]'..indent, '\n' .. left_indent)
|
2017-04-01 02:52:28 -07:00
|
|
|
return str
|
|
|
|
end
|
|
|
|
|
2017-11-19 11:40:34 -07:00
|
|
|
local function format_float(v)
|
|
|
|
-- On windows exponent appears to have three digits and not two
|
|
|
|
local ret = ('%.6e'):format(v)
|
|
|
|
local l, f, es, e = ret:match('^(%-?%d)%.(%d+)e([+%-])0*(%d%d+)$')
|
|
|
|
return l .. '.' .. f .. 'e' .. es .. e
|
|
|
|
end
|
|
|
|
|
2017-09-28 14:57:23 -07:00
|
|
|
local SUBTBL = {
|
|
|
|
'\\000', '\\001', '\\002', '\\003', '\\004',
|
|
|
|
'\\005', '\\006', '\\007', '\\008', '\\t',
|
|
|
|
'\\n', '\\011', '\\012', '\\r', '\\014',
|
|
|
|
'\\015', '\\016', '\\017', '\\018', '\\019',
|
|
|
|
'\\020', '\\021', '\\022', '\\023', '\\024',
|
|
|
|
'\\025', '\\026', '\\027', '\\028', '\\029',
|
|
|
|
'\\030', '\\031',
|
|
|
|
}
|
|
|
|
|
|
|
|
local format_luav
|
|
|
|
|
2017-11-12 08:52:49 -07:00
|
|
|
format_luav = function(v, indent, opts)
|
|
|
|
opts = opts or {}
|
2017-09-28 14:57:23 -07:00
|
|
|
local linesep = '\n'
|
2017-11-12 08:52:49 -07:00
|
|
|
local next_indent_arg = nil
|
2017-11-12 15:10:39 -07:00
|
|
|
local indent_shift = opts.indent_shift or ' '
|
|
|
|
local next_indent
|
|
|
|
local nl = '\n'
|
2017-09-28 14:57:23 -07:00
|
|
|
if indent == nil then
|
|
|
|
indent = ''
|
|
|
|
linesep = ''
|
2017-11-12 15:10:39 -07:00
|
|
|
next_indent = ''
|
|
|
|
nl = ' '
|
2017-09-28 14:57:23 -07:00
|
|
|
else
|
2017-11-12 15:10:39 -07:00
|
|
|
next_indent_arg = indent .. indent_shift
|
|
|
|
next_indent = indent .. indent_shift
|
2017-09-28 14:57:23 -07:00
|
|
|
end
|
|
|
|
local ret = ''
|
|
|
|
if type(v) == 'string' then
|
2017-11-12 08:52:49 -07:00
|
|
|
if opts.literal_strings then
|
|
|
|
ret = v
|
|
|
|
else
|
2018-02-02 06:57:17 -07:00
|
|
|
local quote = opts.dquote_strings and '"' or '\''
|
2018-02-01 15:23:20 -07:00
|
|
|
ret = quote .. tostring(v):gsub(
|
|
|
|
opts.dquote_strings and '["\\]' or '[\'\\]',
|
|
|
|
'\\%0'):gsub(
|
|
|
|
'[%z\1-\31]', function(match)
|
|
|
|
return SUBTBL[match:byte() + 1]
|
|
|
|
end) .. quote
|
2017-09-28 14:57:23 -07:00
|
|
|
end
|
2017-11-12 08:52:49 -07:00
|
|
|
elseif type(v) == 'table' then
|
|
|
|
if v == REMOVE_THIS then
|
|
|
|
ret = 'REMOVE_THIS'
|
|
|
|
else
|
|
|
|
local processed_keys = {}
|
|
|
|
ret = '{' .. linesep
|
2017-11-12 15:10:39 -07:00
|
|
|
local non_empty = false
|
2017-11-12 08:52:49 -07:00
|
|
|
for i, subv in ipairs(v) do
|
2017-11-12 15:10:39 -07:00
|
|
|
ret = ('%s%s%s,%s'):format(ret, next_indent,
|
|
|
|
format_luav(subv, next_indent_arg, opts), nl)
|
2017-11-12 08:52:49 -07:00
|
|
|
processed_keys[i] = true
|
2017-11-12 15:10:39 -07:00
|
|
|
non_empty = true
|
2017-11-12 08:52:49 -07:00
|
|
|
end
|
|
|
|
for k, subv in pairs(v) do
|
|
|
|
if not processed_keys[k] then
|
|
|
|
if type(k) == 'string' and k:match('^[a-zA-Z_][a-zA-Z0-9_]*$') then
|
|
|
|
ret = ret .. next_indent .. k .. ' = '
|
|
|
|
else
|
|
|
|
ret = ('%s%s[%s] = '):format(ret, next_indent,
|
|
|
|
format_luav(k, nil, opts))
|
|
|
|
end
|
2017-11-12 15:10:39 -07:00
|
|
|
ret = ret .. format_luav(subv, next_indent_arg, opts) .. ',' .. nl
|
|
|
|
non_empty = true
|
2017-09-28 14:57:23 -07:00
|
|
|
end
|
|
|
|
end
|
2017-11-12 15:10:39 -07:00
|
|
|
if nl == ' ' and non_empty then
|
|
|
|
ret = ret:sub(1, -3)
|
|
|
|
end
|
2017-11-12 08:52:49 -07:00
|
|
|
ret = ret .. indent .. '}'
|
2017-09-28 14:57:23 -07:00
|
|
|
end
|
2017-10-15 09:06:41 -07:00
|
|
|
elseif type(v) == 'number' then
|
|
|
|
if v % 1 == 0 then
|
|
|
|
ret = ('%d'):format(v)
|
|
|
|
else
|
2017-11-19 11:40:34 -07:00
|
|
|
ret = format_float(v)
|
2017-10-15 09:06:41 -07:00
|
|
|
end
|
2017-10-15 10:05:35 -07:00
|
|
|
elseif type(v) == 'nil' then
|
|
|
|
ret = 'nil'
|
2017-09-28 14:57:23 -07:00
|
|
|
else
|
2017-10-15 09:06:41 -07:00
|
|
|
print(type(v))
|
2017-09-28 14:57:23 -07:00
|
|
|
-- Not implemented yet
|
|
|
|
assert(false)
|
|
|
|
end
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
local function format_string(fmt, ...)
|
|
|
|
local i = 0
|
|
|
|
local args = {...}
|
|
|
|
local function getarg()
|
|
|
|
i = i + 1
|
|
|
|
return args[i]
|
|
|
|
end
|
|
|
|
local ret = fmt:gsub('%%[0-9*]*%.?[0-9*]*[cdEefgGiouXxqsr%%]', function(match)
|
2017-10-29 15:48:32 -07:00
|
|
|
local subfmt = match:gsub('%*', function()
|
|
|
|
return tostring(getarg())
|
2017-09-28 14:57:23 -07:00
|
|
|
end)
|
|
|
|
local arg = nil
|
|
|
|
if subfmt:sub(-1) ~= '%' then
|
|
|
|
arg = getarg()
|
|
|
|
end
|
2018-02-01 15:23:20 -07:00
|
|
|
if subfmt:sub(-1) == 'r' or subfmt:sub(-1) == 'q' then
|
2018-02-02 06:57:17 -07:00
|
|
|
-- %r is like built-in %q, but it is supposed to single-quote strings and
|
2018-02-01 15:23:20 -07:00
|
|
|
-- not double-quote them, and also work not only for strings.
|
|
|
|
-- Builtin %q is replaced here as it gives invalid and inconsistent with
|
|
|
|
-- luajit results for e.g. "\e" on lua: luajit transforms that into `\27`,
|
|
|
|
-- lua leaves as-is.
|
|
|
|
arg = format_luav(arg, nil, {dquote_strings = (subfmt:sub(-1) == 'q')})
|
2017-09-28 14:57:23 -07:00
|
|
|
subfmt = subfmt:sub(1, -2) .. 's'
|
|
|
|
end
|
2017-11-19 11:40:34 -07:00
|
|
|
if subfmt == '%e' then
|
|
|
|
return format_float(arg)
|
|
|
|
else
|
|
|
|
return subfmt:format(arg)
|
|
|
|
end
|
2017-09-28 14:57:23 -07:00
|
|
|
end)
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2017-11-04 16:41:44 -07:00
|
|
|
local function intchar2lua(ch)
|
|
|
|
ch = tonumber(ch)
|
|
|
|
return (20 <= ch and ch < 127) and ('%c'):format(ch) or ch
|
|
|
|
end
|
|
|
|
|
2017-11-12 15:10:39 -07:00
|
|
|
local fixtbl_metatable = {
|
|
|
|
__newindex = function()
|
|
|
|
assert(false)
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
local function fixtbl(tbl)
|
|
|
|
return setmetatable(tbl, fixtbl_metatable)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function fixtbl_rec(tbl)
|
2017-11-19 11:13:27 -07:00
|
|
|
for _, v in pairs(tbl) do
|
2017-11-12 15:10:39 -07:00
|
|
|
if type(v) == 'table' then
|
|
|
|
fixtbl_rec(v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return fixtbl(tbl)
|
|
|
|
end
|
|
|
|
|
2016-04-23 16:53:11 -07:00
|
|
|
return {
|
|
|
|
eq = eq,
|
|
|
|
neq = neq,
|
|
|
|
ok = ok,
|
|
|
|
check_logs = check_logs,
|
2017-01-02 22:46:44 -07:00
|
|
|
uname = uname,
|
|
|
|
tmpname = tmpname,
|
put fixup, esp. ". register close #5709 #5781
Note some bugs were judged to have too ugly a fix to solve, tests to
demonstrate these problems, and the explanation behind not fixing them
are below.
describe('register . problems', function()
before_each(reset)
-- The difficulty here is: The basic requirement is that the text
-- inserted is treated as if it were typed in insert mode. This is why
-- the paste method is to enter insert mode and enter the ". register
-- into readbuf1.
-- We can't add a count into the readbuf here because the insert mode
-- count is implemented with readbuf2 which is checked for characters
-- after readbuf1.
-- Hence, the ".gp command (which adds extra characters into readbuf1
-- to emulate leaving the cursor after the text by moving the cursor
-- after inserting the text) would insert the motion characters into
-- the buffer instead of using them to move after the insert has been
-- done.
-- I could probably get this working properly with a special flag put
-- into start_redo_ins() and set in do_put(), but I think this adds
-- much more complexity than fixing this bug justifies.
pending('should not change the ". register with ".2p', function()
local orig_register = funcs.getreg('.')
feed('2".p')
eq(orig_register, funcs.getreg('.'))
end)
describe("cursor positioning after undo and redo with '.'", function()
before_each(reset)
local function make_cursor_test(macro_string)
return function()
feed(macro_string)
local afterpos = funcs.getcurpos()
local orig_string = curbuf_contents()
feed('u.')
eq(afterpos, funcs.getcurpos())
expect(orig_string)
end
end
-- The difficulty here is: setting the cursor after the end of the
-- pasted text is done by adding a motion command to the
-- stuffbuffer after the insert.
-- Modifying 'redobuff' is done in the code that handles inserting
-- text and moving around.
-- I could add a special case in ins_esc() that checks for a flag
-- set in do_put() to add the motion character to the redo buffer,
-- but I think that is starting to get way too convoluted for the
-- benefit.
pending('should be the same after ".gp and ".gpu.',
make_cursor_test('".gp'))
-- The difficulty here is: putting forwards is implemented by using
-- 'a' instead of 'i' to start insert.
-- Undoing with 'u' an insert that began with 'a' leaves the cursor
-- where the first character was inserted, not where the cursor was
-- when the 'a' was pressed.
-- We account for this the first time by saving the cursor position
-- in do_put(), but this isn't stored in redobuff for a second time
-- around.
-- We can't change how such a fundamental action as undo after
-- inserting with 'a' behaves, we could add in a special case
-- whereby we set a flag in do_put() and read it when entering
-- insert mode but this seems like way too much to fix such a minor
-- bug.
pending('should be the same after ".pu. and ".pu.u.',
make_cursor_test('".pu.'))
end)
end)
2016-12-12 07:04:44 -07:00
|
|
|
map = map,
|
|
|
|
filter = filter,
|
2016-11-04 08:20:58 -07:00
|
|
|
glob = glob,
|
|
|
|
check_cores = check_cores,
|
|
|
|
hasenv = hasenv,
|
2017-03-11 03:28:18 -07:00
|
|
|
which = which,
|
2017-01-20 14:00:47 -07:00
|
|
|
shallowcopy = shallowcopy,
|
2017-11-05 11:06:12 -07:00
|
|
|
deepcopy = deepcopy,
|
|
|
|
mergedicts_copy = mergedicts_copy,
|
2017-11-12 08:52:49 -07:00
|
|
|
dictdiff = dictdiff,
|
2017-11-05 11:06:12 -07:00
|
|
|
REMOVE_THIS = REMOVE_THIS,
|
2017-03-04 15:09:55 -07:00
|
|
|
concat_tables = concat_tables,
|
2017-04-01 02:52:28 -07:00
|
|
|
dedent = dedent,
|
2017-09-28 14:57:23 -07:00
|
|
|
format_luav = format_luav,
|
|
|
|
format_string = format_string,
|
2017-11-04 16:41:44 -07:00
|
|
|
intchar2lua = intchar2lua,
|
2017-11-06 10:15:05 -07:00
|
|
|
updated = updated,
|
2017-11-12 15:10:39 -07:00
|
|
|
fixtbl = fixtbl,
|
|
|
|
fixtbl_rec = fixtbl_rec,
|
2016-04-23 16:53:11 -07:00
|
|
|
}
|