feat(cli): :CP run with numbered test cases
This commit is contained in:
parent
71efb24cda
commit
e1c8c4beaf
2 changed files with 83 additions and 33 deletions
|
|
@ -75,7 +75,7 @@ local function parse_command(args)
|
||||||
return { type = 'action', action = 'edit', test_index = test_index }
|
return { type = 'action', action = 'edit', test_index = test_index }
|
||||||
elseif first == 'run' or first == 'panel' then
|
elseif first == 'run' or first == 'panel' then
|
||||||
local debug = false
|
local debug = false
|
||||||
local test_index = nil
|
local test_indices = nil
|
||||||
local mode = 'combined'
|
local mode = 'combined'
|
||||||
|
|
||||||
if #args == 2 then
|
if #args == 2 then
|
||||||
|
|
@ -83,12 +83,30 @@ local function parse_command(args)
|
||||||
debug = true
|
debug = true
|
||||||
elseif args[2] == 'all' then
|
elseif args[2] == 'all' then
|
||||||
mode = 'individual'
|
mode = 'individual'
|
||||||
|
else
|
||||||
|
if args[2]:find(',') then
|
||||||
|
local indices = {}
|
||||||
|
for num in args[2]:gmatch('[^,]+') do
|
||||||
|
local idx = tonumber(num)
|
||||||
|
if not idx or idx < 1 or idx ~= math.floor(idx) then
|
||||||
|
return {
|
||||||
|
type = 'error',
|
||||||
|
message = ("Invalid test index '%s' in list"):format(num),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
table.insert(indices, idx)
|
||||||
|
end
|
||||||
|
if #indices == 0 then
|
||||||
|
return { type = 'error', message = 'No valid test indices provided' }
|
||||||
|
end
|
||||||
|
test_indices = indices
|
||||||
|
mode = 'individual'
|
||||||
else
|
else
|
||||||
local idx = tonumber(args[2])
|
local idx = tonumber(args[2])
|
||||||
if not idx then
|
if not idx then
|
||||||
return {
|
return {
|
||||||
type = 'error',
|
type = 'error',
|
||||||
message = ("Invalid argument '%s': expected test number, 'all', or --debug"):format(
|
message = ("Invalid argument '%s': expected test number(s), 'all', or --debug"):format(
|
||||||
args[2]
|
args[2]
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
@ -96,9 +114,10 @@ local function parse_command(args)
|
||||||
if idx < 1 or idx ~= math.floor(idx) then
|
if idx < 1 or idx ~= math.floor(idx) then
|
||||||
return { type = 'error', message = ("'%s' is not a valid test index"):format(idx) }
|
return { type = 'error', message = ("'%s' is not a valid test index"):format(idx) }
|
||||||
end
|
end
|
||||||
test_index = idx
|
test_indices = { idx }
|
||||||
mode = 'individual'
|
mode = 'individual'
|
||||||
end
|
end
|
||||||
|
end
|
||||||
elseif #args == 3 then
|
elseif #args == 3 then
|
||||||
if args[2] == 'all' then
|
if args[2] == 'all' then
|
||||||
mode = 'individual'
|
mode = 'individual'
|
||||||
|
|
@ -109,6 +128,30 @@ local function parse_command(args)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
debug = true
|
debug = true
|
||||||
|
elseif args[2]:find(',') then
|
||||||
|
local indices = {}
|
||||||
|
for num in args[2]:gmatch('[^,]+') do
|
||||||
|
local idx = tonumber(num)
|
||||||
|
if not idx or idx < 1 or idx ~= math.floor(idx) then
|
||||||
|
return {
|
||||||
|
type = 'error',
|
||||||
|
message = ("Invalid test index '%s' in list"):format(num),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
table.insert(indices, idx)
|
||||||
|
end
|
||||||
|
if #indices == 0 then
|
||||||
|
return { type = 'error', message = 'No valid test indices provided' }
|
||||||
|
end
|
||||||
|
if args[3] ~= '--debug' then
|
||||||
|
return {
|
||||||
|
type = 'error',
|
||||||
|
message = ("Invalid argument '%s': expected --debug"):format(args[3]),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
test_indices = indices
|
||||||
|
mode = 'individual'
|
||||||
|
debug = true
|
||||||
else
|
else
|
||||||
local idx = tonumber(args[2])
|
local idx = tonumber(args[2])
|
||||||
if not idx then
|
if not idx then
|
||||||
|
|
@ -126,21 +169,23 @@ local function parse_command(args)
|
||||||
message = ("Invalid argument '%s': expected --debug"):format(args[3]),
|
message = ("Invalid argument '%s': expected --debug"):format(args[3]),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
test_index = idx
|
test_indices = { idx }
|
||||||
mode = 'individual'
|
mode = 'individual'
|
||||||
debug = true
|
debug = true
|
||||||
end
|
end
|
||||||
elseif #args > 3 then
|
elseif #args > 3 then
|
||||||
return {
|
return {
|
||||||
type = 'error',
|
type = 'error',
|
||||||
message = 'Too many arguments. Usage: :CP ' .. first .. ' [all|test_num] [--debug]',
|
message = 'Too many arguments. Usage: :CP '
|
||||||
|
.. first
|
||||||
|
.. ' [all|test_num[,test_num...]] [--debug]',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type = 'action',
|
type = 'action',
|
||||||
action = first,
|
action = first,
|
||||||
test_index = test_index,
|
test_indices = test_indices,
|
||||||
debug = debug,
|
debug = debug,
|
||||||
mode = mode,
|
mode = mode,
|
||||||
}
|
}
|
||||||
|
|
@ -221,9 +266,12 @@ function M.handle_command(opts)
|
||||||
if cmd.action == 'interact' then
|
if cmd.action == 'interact' then
|
||||||
ui.toggle_interactive(cmd.interactor_cmd)
|
ui.toggle_interactive(cmd.interactor_cmd)
|
||||||
elseif cmd.action == 'run' then
|
elseif cmd.action == 'run' then
|
||||||
ui.run_io_view(cmd.test_index, cmd.debug, cmd.mode)
|
ui.run_io_view(cmd.test_indices, cmd.debug, cmd.mode)
|
||||||
elseif cmd.action == 'panel' then
|
elseif cmd.action == 'panel' then
|
||||||
ui.toggle_panel({ debug = cmd.debug, test_index = cmd.test_index })
|
ui.toggle_panel({
|
||||||
|
debug = cmd.debug,
|
||||||
|
test_index = cmd.test_indices and cmd.test_indices[1] or nil,
|
||||||
|
})
|
||||||
elseif cmd.action == 'next' then
|
elseif cmd.action == 'next' then
|
||||||
setup.navigate_problem(1, cmd.language)
|
setup.navigate_problem(1, cmd.language)
|
||||||
elseif cmd.action == 'prev' then
|
elseif cmd.action == 'prev' then
|
||||||
|
|
|
||||||
|
|
@ -287,7 +287,7 @@ function M.ensure_io_view()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
io_view_state.current_test_index = new_index
|
io_view_state.current_test_index = new_index
|
||||||
M.run_io_view(new_index)
|
M.run_io_view({ new_index }, false, 'individual')
|
||||||
end
|
end
|
||||||
|
|
||||||
if cfg.ui.run.next_test_key then
|
if cfg.ui.run.next_test_key then
|
||||||
|
|
@ -338,7 +338,7 @@ function M.ensure_io_view()
|
||||||
vim.api.nvim_set_current_win(solution_win)
|
vim.api.nvim_set_current_win(solution_win)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.run_io_view(test_index, debug, mode)
|
function M.run_io_view(test_indices_arg, debug, mode)
|
||||||
mode = mode or 'combined'
|
mode = mode or 'combined'
|
||||||
|
|
||||||
local platform, contest_id, problem_id =
|
local platform, contest_id, problem_id =
|
||||||
|
|
@ -380,19 +380,21 @@ function M.run_io_view(test_index, debug, mode)
|
||||||
if mode == 'individual' then
|
if mode == 'individual' then
|
||||||
local test_state = run.get_panel_state()
|
local test_state = run.get_panel_state()
|
||||||
|
|
||||||
if test_index then
|
if test_indices_arg then
|
||||||
if test_index < 1 or test_index > #test_state.test_cases then
|
for _, idx in ipairs(test_indices_arg) do
|
||||||
|
if idx < 1 or idx > #test_state.test_cases then
|
||||||
logger.log(
|
logger.log(
|
||||||
string.format(
|
string.format(
|
||||||
'Test %d does not exist (only %d tests available)',
|
'Test %d does not exist (only %d tests available)',
|
||||||
test_index,
|
idx,
|
||||||
#test_state.test_cases
|
#test_state.test_cases
|
||||||
),
|
),
|
||||||
vim.log.levels.WARN
|
vim.log.levels.WARN
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
test_indices = { test_index }
|
end
|
||||||
|
test_indices = test_indices_arg
|
||||||
else
|
else
|
||||||
for i = 1, #test_state.test_cases do
|
for i = 1, #test_state.test_cases do
|
||||||
test_indices[i] = i
|
test_indices[i] = i
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue