fix(config): easier language default per-contest
This commit is contained in:
parent
d4f1678b03
commit
e48e70a5f9
3 changed files with 38 additions and 9 deletions
|
|
@ -267,12 +267,7 @@ function M.setup(user_config)
|
||||||
error('No language configurations found')
|
error('No language configurations found')
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.tbl_contains(available_langs, 'cpp') then
|
contest_config.default_language = available_langs[1]
|
||||||
contest_config.default_language = 'cpp'
|
|
||||||
else
|
|
||||||
table.sort(available_langs)
|
|
||||||
contest_config.default_language = available_langs[1]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -159,8 +159,10 @@ end
|
||||||
---@param contest_id string Contest identifier
|
---@param contest_id string Contest identifier
|
||||||
---@param problem_id string Problem identifier
|
---@param problem_id string Problem identifier
|
||||||
local function setup_problem(platform, contest_id, problem_id)
|
local function setup_problem(platform, contest_id, problem_id)
|
||||||
local cp = require('cp')
|
vim.schedule(function()
|
||||||
cp.handle_command({ fargs = { platform, contest_id, problem_id } })
|
local cp = require('cp')
|
||||||
|
cp.handle_command({ fargs = { platform, contest_id, problem_id } })
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.get_platforms = get_platforms
|
M.get_platforms = get_platforms
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ describe('cp.config', function()
|
||||||
assert.equals('cpp', result.contests.test.default_language)
|
assert.equals('cpp', result.contests.test.default_language)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('sets default_language to first available when cpp not present', function()
|
it('sets default_language to single available language when only one configured', function()
|
||||||
local user_config = {
|
local user_config = {
|
||||||
contests = {
|
contests = {
|
||||||
test = {
|
test = {
|
||||||
|
|
@ -183,6 +183,38 @@ describe('cp.config', function()
|
||||||
assert.equals('python', result.contests.test.default_language)
|
assert.equals('python', result.contests.test.default_language)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('sets default_language to single available language even when not cpp', function()
|
||||||
|
local user_config = {
|
||||||
|
contests = {
|
||||||
|
test = {
|
||||||
|
rust = {
|
||||||
|
test = { './target/release/solution' },
|
||||||
|
extension = 'rs'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local result = config.setup(user_config)
|
||||||
|
|
||||||
|
assert.equals('rust', result.contests.test.default_language)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('uses first available language when multiple configured', function()
|
||||||
|
local user_config = {
|
||||||
|
contests = {
|
||||||
|
test = {
|
||||||
|
python = { test = { 'python3' } },
|
||||||
|
cpp = { compile = { 'g++' } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local result = config.setup(user_config)
|
||||||
|
|
||||||
|
assert.is_true(vim.tbl_contains({'cpp', 'python'}, result.contests.test.default_language))
|
||||||
|
end)
|
||||||
|
|
||||||
it('preserves explicit default_language', function()
|
it('preserves explicit default_language', function()
|
||||||
local user_config = {
|
local user_config = {
|
||||||
contests = {
|
contests = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue