more docs
This commit is contained in:
parent
7eb314b02c
commit
6b8a1e2087
10 changed files with 83 additions and 142 deletions
|
|
@ -83,34 +83,6 @@ local function parse_test_cases_from_cache(platform, contest_id, problem_id)
|
|||
return test_cases
|
||||
end
|
||||
|
||||
---@param input_file string
|
||||
---@return TestCase[]
|
||||
local function parse_test_cases_from_files(input_file, _)
|
||||
local base_name = vim.fn.fnamemodify(input_file, ':r')
|
||||
local test_cases = {}
|
||||
|
||||
local i = 1
|
||||
while true do
|
||||
local individual_input_file = base_name .. '.' .. i .. '.cpin'
|
||||
local individual_expected_file = base_name .. '.' .. i .. '.cpout'
|
||||
|
||||
if
|
||||
vim.fn.filereadable(individual_input_file) == 1
|
||||
and vim.fn.filereadable(individual_expected_file) == 1
|
||||
then
|
||||
local input_content = table.concat(vim.fn.readfile(individual_input_file), '\n')
|
||||
local expected_content = table.concat(vim.fn.readfile(individual_expected_file), '\n')
|
||||
|
||||
table.insert(test_cases, create_test_case(i, input_content, expected_content))
|
||||
i = i + 1
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return test_cases
|
||||
end
|
||||
|
||||
---@param platform string
|
||||
---@param contest_id string
|
||||
---@param problem_id string?
|
||||
|
|
@ -136,28 +108,11 @@ end
|
|||
local function run_single_test_case(contest_config, cp_config, test_case)
|
||||
local state = require('cp.state')
|
||||
local source_file = state.get_source_file()
|
||||
if not source_file then
|
||||
return {
|
||||
status = 'fail',
|
||||
actual = '',
|
||||
error = 'No source file found',
|
||||
time_ms = 0,
|
||||
}
|
||||
end
|
||||
|
||||
local language = vim.fn.fnamemodify(source_file, ':e')
|
||||
local language_name = constants.filetype_to_language[language] or contest_config.default_language
|
||||
local language_config = contest_config[language_name]
|
||||
|
||||
if not language_config then
|
||||
return {
|
||||
status = 'fail',
|
||||
actual = '',
|
||||
error = 'No language configuration',
|
||||
time_ms = 0,
|
||||
}
|
||||
end
|
||||
|
||||
local function substitute_template(cmd_template, substitutions)
|
||||
local result = {}
|
||||
for _, arg in ipairs(cmd_template) do
|
||||
|
|
@ -208,6 +163,7 @@ local function run_single_test_case(contest_config, cp_config, test_case)
|
|||
ok = false,
|
||||
signal = nil,
|
||||
timed_out = false,
|
||||
actual_highlights = {},
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -298,11 +254,7 @@ function M.load_test_cases(state)
|
|||
state.get_problem_id()
|
||||
) or {}
|
||||
|
||||
if vim.tbl_isempty(test_cases) then
|
||||
local input_file = state.get_input_file()
|
||||
local expected_file = state.get_expected_file()
|
||||
test_cases = parse_test_cases_from_files(input_file, expected_file)
|
||||
end
|
||||
-- TODO: re-fetch/cache-populating mechanism to ge the test cases if not in the cache
|
||||
|
||||
run_panel_state.test_cases = test_cases
|
||||
run_panel_state.current_index = 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue