fix(lua): bunch of typing
This commit is contained in:
parent
057b0890c2
commit
1974addbd2
10 changed files with 79 additions and 75 deletions
|
|
@ -1,10 +1,10 @@
|
|||
---@class TestCase
|
||||
---@class RanTestCase
|
||||
---@field index number
|
||||
---@field input string
|
||||
---@field expected string
|
||||
---@field status "pending"|"pass"|"fail"|"running"|"timeout"
|
||||
---@field actual string?
|
||||
---@field actual_highlights table[]?
|
||||
---@field actual_highlights? any[]
|
||||
---@field time_ms number?
|
||||
---@field error string?
|
||||
---@field stderr string?
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
---@field memory_mb number
|
||||
|
||||
---@class RunPanelState
|
||||
---@field test_cases TestCase[]
|
||||
---@field test_cases RanTestCase[]
|
||||
---@field current_index number
|
||||
---@field buffer number?
|
||||
---@field namespace number?
|
||||
|
|
@ -45,7 +45,7 @@ local run_panel_state = {
|
|||
---@param index number
|
||||
---@param input string
|
||||
---@param expected string
|
||||
---@return TestCase
|
||||
---@return RanTestCase
|
||||
local function create_test_case(index, input, expected)
|
||||
return {
|
||||
index = index,
|
||||
|
|
@ -62,7 +62,7 @@ end
|
|||
---@param platform string
|
||||
---@param contest_id string
|
||||
---@param problem_id string?
|
||||
---@return TestCase[]
|
||||
---@return RanTestCase[]
|
||||
local function parse_test_cases_from_cache(platform, contest_id, problem_id)
|
||||
local cache = require('cp.cache')
|
||||
cache.load()
|
||||
|
|
@ -103,13 +103,13 @@ local function load_constraints_from_cache(platform, contest_id, problem_id)
|
|||
end
|
||||
|
||||
---@param contest_config ContestConfig
|
||||
---@param test_case TestCase
|
||||
---@param test_case RanTestCase
|
||||
---@return table
|
||||
local function run_single_test_case(contest_config, cp_config, test_case)
|
||||
local state = require('cp.state')
|
||||
local source_file = state.get_source_file()
|
||||
|
||||
local language = vim.fn.fnamemodify(source_file, ':e')
|
||||
local language = vim.fn.fnamemodify(source_file or '', ':e')
|
||||
local language_name = constants.filetype_to_language[language] or contest_config.default_language
|
||||
local language_config = contest_config[language_name]
|
||||
|
||||
|
|
@ -297,7 +297,7 @@ end
|
|||
|
||||
---@param contest_config ContestConfig
|
||||
---@param cp_config cp.Config
|
||||
---@return TestCase[]
|
||||
---@return RanTestCase[]
|
||||
function M.run_all_test_cases(contest_config, cp_config)
|
||||
local results = {}
|
||||
for i, _ in ipairs(run_panel_state.test_cases) do
|
||||
|
|
|
|||
|
|
@ -23,22 +23,22 @@ local exit_code_names = {
|
|||
[143] = 'SIGCHLD',
|
||||
}
|
||||
|
||||
---@param test_case TestCase
|
||||
---@param ran_test_case RanTestCase
|
||||
---@return StatusInfo
|
||||
function M.get_status_info(test_case)
|
||||
if test_case.status == 'pass' then
|
||||
function M.get_status_info(ran_test_case)
|
||||
if ran_test_case.status == 'pass' then
|
||||
return { text = 'AC', highlight_group = 'CpTestAC' }
|
||||
elseif test_case.status == 'fail' then
|
||||
if test_case.timed_out then
|
||||
elseif ran_test_case.status == 'fail' then
|
||||
if ran_test_case.timed_out then
|
||||
return { text = 'TLE', highlight_group = 'CpTestTLE' }
|
||||
elseif test_case.code and test_case.code >= 128 then
|
||||
elseif ran_test_case.code and ran_test_case.code >= 128 then
|
||||
return { text = 'RTE', highlight_group = 'CpTestRTE' }
|
||||
else
|
||||
return { text = 'WA', highlight_group = 'CpTestWA' }
|
||||
end
|
||||
elseif test_case.status == 'timeout' then
|
||||
elseif ran_test_case.status == 'timeout' then
|
||||
return { text = 'TLE', highlight_group = 'CpTestTLE' }
|
||||
elseif test_case.status == 'running' then
|
||||
elseif ran_test_case.status == 'running' then
|
||||
return { text = '...', highlight_group = 'CpTestPending' }
|
||||
else
|
||||
return { text = '', highlight_group = 'CpTestPending' }
|
||||
|
|
@ -278,7 +278,7 @@ local function data_row(c, idx, tc, is_current, test_state)
|
|||
end
|
||||
|
||||
---@param test_state RunPanelState
|
||||
---@return string[], table[] lines and highlight positions
|
||||
---@return string[], any[] lines and highlight positions
|
||||
function M.render_test_list(test_state)
|
||||
local lines, highlights = {}, {}
|
||||
local c = compute_cols(test_state)
|
||||
|
|
@ -332,18 +332,18 @@ function M.render_test_list(test_state)
|
|||
return lines, highlights
|
||||
end
|
||||
|
||||
---@param test_case TestCase?
|
||||
---@param ran_test_case RanTestCase?
|
||||
---@return string
|
||||
function M.render_status_bar(test_case)
|
||||
if not test_case then
|
||||
function M.render_status_bar(ran_test_case)
|
||||
if not ran_test_case then
|
||||
return ''
|
||||
end
|
||||
local parts = {}
|
||||
if test_case.time_ms then
|
||||
table.insert(parts, string.format('%.2fms', test_case.time_ms))
|
||||
if ran_test_case.time_ms then
|
||||
table.insert(parts, string.format('%.2fms', ran_test_case.time_ms))
|
||||
end
|
||||
if test_case.code then
|
||||
table.insert(parts, string.format('Exit: %d', test_case.code))
|
||||
if ran_test_case.code then
|
||||
table.insert(parts, string.format('Exit: %d', ran_test_case.code))
|
||||
end
|
||||
return table.concat(parts, ' │ ')
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue