feat(test): config
This commit is contained in:
parent
78071b119b
commit
41117feee7
1 changed files with 66 additions and 23 deletions
|
|
@ -1,4 +1,3 @@
|
|||
-- Unit tests for configuration management
|
||||
describe('cp.config', function()
|
||||
local config
|
||||
|
||||
|
|
@ -7,40 +6,84 @@ describe('cp.config', function()
|
|||
end)
|
||||
|
||||
describe('setup', function()
|
||||
it('returns default config when no user config provided', function()
|
||||
-- Test default configuration values
|
||||
it('returns defaults with nil input', function()
|
||||
local result = config.setup()
|
||||
|
||||
assert.equals('table', type(result.contests))
|
||||
assert.equals('table', type(result.snippets))
|
||||
assert.equals('table', type(result.hooks))
|
||||
assert.equals('table', type(result.scrapers))
|
||||
assert.is_false(result.debug)
|
||||
assert.is_nil(result.filename)
|
||||
end)
|
||||
|
||||
it('merges user config with defaults', function()
|
||||
-- Test config merging behavior
|
||||
local user_config = {
|
||||
debug = true,
|
||||
contests = { test_contest = { cpp = { extension = 'cpp' } } }
|
||||
}
|
||||
|
||||
local result = config.setup(user_config)
|
||||
|
||||
assert.is_true(result.debug)
|
||||
assert.equals('table', type(result.contests.test_contest))
|
||||
assert.equals('table', type(result.scrapers))
|
||||
end)
|
||||
|
||||
it('validates contest configurations', function()
|
||||
-- Test contest config validation
|
||||
it('validates extension against supported filetypes', function()
|
||||
local invalid_config = {
|
||||
contests = {
|
||||
test_contest = {
|
||||
cpp = { extension = 'invalid' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.has_error(function()
|
||||
config.setup(invalid_config)
|
||||
end)
|
||||
end)
|
||||
|
||||
it('handles invalid config gracefully', function()
|
||||
-- Test error handling for bad configs
|
||||
it('validates scraper platforms', function()
|
||||
local invalid_config = {
|
||||
scrapers = { invalid_platform = true }
|
||||
}
|
||||
|
||||
assert.has_error(function()
|
||||
config.setup(invalid_config)
|
||||
end)
|
||||
end)
|
||||
|
||||
it('validates scraper values are booleans', function()
|
||||
local invalid_config = {
|
||||
scrapers = { atcoder = 'not_boolean' }
|
||||
}
|
||||
|
||||
assert.has_error(function()
|
||||
config.setup(invalid_config)
|
||||
end)
|
||||
end)
|
||||
|
||||
it('validates hook functions', function()
|
||||
local invalid_config = {
|
||||
hooks = { before_run = 'not_a_function' }
|
||||
}
|
||||
|
||||
assert.has_error(function()
|
||||
config.setup(invalid_config)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('platform validation', function()
|
||||
it('accepts valid platforms', function()
|
||||
-- Test platform validation
|
||||
describe('default_filename', function()
|
||||
it('generates lowercase contest filename', function()
|
||||
local result = config.default_filename('ABC123')
|
||||
assert.equals('abc123', result)
|
||||
end)
|
||||
|
||||
it('rejects invalid platforms', function()
|
||||
-- Test platform rejection
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('language configurations', function()
|
||||
it('provides correct file extensions for languages', function()
|
||||
-- Test language -> extension mappings
|
||||
end)
|
||||
|
||||
it('provides correct compile commands', function()
|
||||
-- Test compile command generation
|
||||
it('combines contest and problem ids', function()
|
||||
local result = config.default_filename('ABC123', 'A')
|
||||
assert.equals('abc123a', result)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue