fix: cleanup config logic
This commit is contained in:
parent
9ea6f878de
commit
b34ace85a5
2 changed files with 12 additions and 47 deletions
|
|
@ -141,17 +141,6 @@ function M.setup(user_config)
|
||||||
|
|
||||||
for lang_name, lang_config in pairs(config) do
|
for lang_name, lang_config in pairs(config) do
|
||||||
if type(lang_config) == 'table' then
|
if type(lang_config) == 'table' then
|
||||||
if
|
|
||||||
lang_name ~= 'default_language'
|
|
||||||
and not vim.tbl_contains(vim.tbl_keys(constants.canonical_filetypes), lang_name)
|
|
||||||
then
|
|
||||||
return false,
|
|
||||||
("Invalid language '%s'. Valid languages: %s"):format(
|
|
||||||
lang_name,
|
|
||||||
table.concat(vim.tbl_keys(constants.canonical_filetypes), ', ')
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
if
|
if
|
||||||
lang_config.extension
|
lang_config.extension
|
||||||
and not vim.tbl_contains(
|
and not vim.tbl_contains(
|
||||||
|
|
@ -168,20 +157,6 @@ function M.setup(user_config)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if
|
|
||||||
config.default_language
|
|
||||||
and not vim.tbl_contains(
|
|
||||||
vim.tbl_keys(constants.canonical_filetypes),
|
|
||||||
config.default_language
|
|
||||||
)
|
|
||||||
then
|
|
||||||
return false,
|
|
||||||
("Invalid default_language '%s'. Valid languages: %s"):format(
|
|
||||||
config.default_language,
|
|
||||||
table.concat(vim.tbl_keys(constants.canonical_filetypes), ', ')
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
'contest configuration',
|
'contest configuration',
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,6 @@ describe('cp.config', function()
|
||||||
contests = {
|
contests = {
|
||||||
test = {
|
test = {
|
||||||
python = { test = { 'python3' } },
|
python = { test = { 'python3' } },
|
||||||
rust = { compile = { 'rustc' } },
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -192,36 +191,27 @@ describe('cp.config', function()
|
||||||
|
|
||||||
assert.has_error(function()
|
assert.has_error(function()
|
||||||
config.setup(invalid_config)
|
config.setup(invalid_config)
|
||||||
end, 'No language configurations found for test')
|
end, 'No language configurations found')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('validates language names against canonical_filetypes', function()
|
it('allows custom language names', function()
|
||||||
local invalid_config = {
|
local user_config = {
|
||||||
contests = {
|
|
||||||
test = {
|
|
||||||
invalid_lang = { compile = { 'gcc' } },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.has_error(function()
|
|
||||||
config.setup(invalid_config)
|
|
||||||
end, "Invalid language 'invalid_lang'")
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('validates default_language value', function()
|
|
||||||
local invalid_config = {
|
|
||||||
contests = {
|
contests = {
|
||||||
test = {
|
test = {
|
||||||
|
rust = {
|
||||||
|
compile = { 'rustc', '{source}', '-o', '{binary}' },
|
||||||
|
test = { '{binary}' },
|
||||||
|
extension = 'rs',
|
||||||
|
},
|
||||||
cpp = { compile = { 'g++' } },
|
cpp = { compile = { 'g++' } },
|
||||||
default_language = 'xd',
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.has_error(function()
|
assert.has_no.errors(function()
|
||||||
config.setup(invalid_config)
|
local result = config.setup(user_config)
|
||||||
end, "Invalid default_language 'xd'")
|
assert.equals('cpp', result.contests.test.default_language)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue