ci: more tests (#359)

* more tests

* lint
This commit is contained in:
TJ DeVries
2020-12-23 13:31:05 -05:00
committed by GitHub
parent 4850c6df6d
commit 049602a2c5
5 changed files with 93 additions and 54 deletions

View File

@@ -30,17 +30,16 @@ tester.picker_feed = function(input, test_cases, debug)
end
end
vim.wait(100, function() end)
vim.wait(10, function() end)
local timer = vim.loop.new_timer()
timer:start(200, 0, vim.schedule_wrap(function()
timer:start(20, 0, vim.schedule_wrap(function()
if test_cases.post_close then
for k, v in ipairs(test_cases.post_close) do
io.stderr:write(vim.fn.json_encode({ case = k, expected = v[1], actual = v[2]() }))
io.stderr:write("\n")
end
end
vim.wait(10)
if debug then
return
@@ -48,7 +47,7 @@ tester.picker_feed = function(input, test_cases, debug)
vim.defer_fn(function()
vim.cmd [[qa!]]
end, 15)
end, 10)
end))
if not debug then
@@ -74,10 +73,25 @@ end
-- { "README.md", function() return "README.md" end },
-- },
-- }
local _VALID_KEYS = {
post_typed = true,
post_close = true,
}
tester.builtin_picker = function(key, input, test_cases, opts)
opts = opts or {}
local debug = opts.debug or false
for k, _ in pairs(test_cases) do
if not _VALID_KEYS[k] then
-- TODO: Make an error type for the json protocol.
io.stderr:write(vim.fn.json_encode({ case = k, expected = '<a valid key>', actual = k }))
io.stderr:write("\n")
vim.cmd [[qa!]]
end
end
opts.on_complete = {
tester.picker_feed(input, test_cases, debug)
}
@@ -119,32 +133,10 @@ tester.run_string = function(contents)
local tempname = vim.fn.tempname()
contents = [[
-- TODO: Add globals!
-- local tester = require('telescope.pickers._tests')
local tester = require('telescope.pickers._tests')
local tester = require('telescope.pickers._test')
local helper = require('telescope.pickers._test_helpers')
local get_picker = function()
local state = require('telescope.state')
return state.get_status(vim.api.nvim_get_current_buf()).picker
end
local get_results_bufnr = function()
local state = require('telescope.state')
return state.get_status(vim.api.nvim_get_current_buf()).results_bufnr
end
local GetFile = function() return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ":t") end
local GetPrompt = function() return vim.api.nvim_buf_get_lines(0, 0, -1, false)[1] end
local GetResults = function()
return vim.api.nvim_buf_get_lines(get_results_bufnr(), 0, -1, false)
end
local GetLastResult = function()
local results = GetResults()
return results[#results]
end
helper.make_globals()
]] .. contents
vim.fn.writefile(vim.split(contents, "\n"), tempname)
@@ -162,6 +154,4 @@ tester.run_file = function(filename)
assert.are.same(result_table.expected, result_table.actual)
end
return tester

View File

@@ -0,0 +1,50 @@
local test_helpers = {}
test_helpers.get_picker = function()
local state = require('telescope.state')
return state.get_status(vim.api.nvim_get_current_buf()).picker
end
test_helpers.get_results_bufnr = function()
local state = require('telescope.state')
return state.get_status(vim.api.nvim_get_current_buf()).results_bufnr
end
test_helpers.get_file = function()
return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ":t")
end
test_helpers.get_prompt = function()
return vim.api.nvim_buf_get_lines(0, 0, -1, false)[1]
end
test_helpers.get_results = function()
return vim.api.nvim_buf_get_lines(test_helpers.get_results_bufnr(), 0, -1, false)
end
test_helpers.get_last_result = function()
local results = test_helpers.get_results()
return results[#results]
end
test_helpers.get_selection = function()
local state = require('telescope.state')
return state.get_global_key('selected_entry')
end
test_helpers.get_selection_value = function()
return test_helpers.get_selection().value
end
test_helpers.make_globals = function()
GetFile = test_helpers.get_file -- luacheck: globals GetFile
GetPrompt = test_helpers.get_prompt -- luacheck: globals GetPrompt
GetResults = test_helpers.get_results -- luacheck: globals GetResults
GetLastResult = test_helpers.get_last_result -- luacheck: globals GetLastResult
GetSelection = test_helpers.get_selection -- luacheck: globals GetSelection
GetSelectionValue = test_helpers.get_selection_value -- luacheck: globals GetSelectionValue
end
return test_helpers