fix: better tests
This commit is contained in:
parent
30c1c0f2cf
commit
a2b3de51d7
3 changed files with 39 additions and 2 deletions
|
|
@ -63,7 +63,8 @@ describe('cp command parsing', function()
|
||||||
|
|
||||||
local mock_restore = {
|
local mock_restore = {
|
||||||
restore_from_current_file = function()
|
restore_from_current_file = function()
|
||||||
error('No file is currently open')
|
logged_messages[#logged_messages + 1] =
|
||||||
|
{ msg = 'No file is currently open', level = vim.log.levels.ERROR }
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
package.loaded['cp.restore'] = mock_restore
|
package.loaded['cp.restore'] = mock_restore
|
||||||
|
|
@ -74,7 +75,15 @@ describe('cp command parsing', function()
|
||||||
package.loaded['cp.commands.picker'] = mock_picker
|
package.loaded['cp.commands.picker'] = mock_picker
|
||||||
|
|
||||||
local mock_cache_commands = {
|
local mock_cache_commands = {
|
||||||
handle_cache_command = function() end,
|
handle_cache_command = function(cmd)
|
||||||
|
if cmd.subcommand == 'clear' then
|
||||||
|
if cmd.platform then
|
||||||
|
logged_messages[#logged_messages + 1] = { msg = 'cleared cache for ' .. cmd.platform }
|
||||||
|
else
|
||||||
|
logged_messages[#logged_messages + 1] = { msg = 'cleared all cache' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
package.loaded['cp.commands.cache'] = mock_cache_commands
|
package.loaded['cp.commands.cache'] = mock_cache_commands
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,15 @@ describe('Panel integration', function()
|
||||||
state.set_platform(platform)
|
state.set_platform(platform)
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
setup_contest = function(platform, contest, problem, language)
|
||||||
|
state.set_platform(platform)
|
||||||
|
state.set_contest_id(contest)
|
||||||
|
if problem then
|
||||||
|
state.set_problem_id(problem)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
setup_problem = function() end,
|
||||||
|
navigate_problem = function() end,
|
||||||
}
|
}
|
||||||
package.loaded['cp.setup'] = mock_setup
|
package.loaded['cp.setup'] = mock_setup
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -183,12 +183,31 @@ describe('cp.picker', function()
|
||||||
|
|
||||||
it('returns empty list when scraping fails', function()
|
it('returns empty list when scraping fails', function()
|
||||||
local cache = require('cp.cache')
|
local cache = require('cp.cache')
|
||||||
|
local utils = require('cp.utils')
|
||||||
|
|
||||||
cache.load = function() end
|
cache.load = function() end
|
||||||
cache.get_contest_data = function(_, _)
|
cache.get_contest_data = function(_, _)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
utils.setup_python_env = function()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
utils.get_plugin_path = function()
|
||||||
|
return '/tmp'
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.system = function()
|
||||||
|
return {
|
||||||
|
wait = function()
|
||||||
|
return {
|
||||||
|
code = 1,
|
||||||
|
stderr = 'Scraping failed',
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
picker = spec_helper.fresh_require('cp.pickers', { 'cp.pickers.init' })
|
picker = spec_helper.fresh_require('cp.pickers', { 'cp.pickers.init' })
|
||||||
|
|
||||||
local problems = picker.get_problems_for_contest('test_platform', 'test_contest')
|
local problems = picker.get_problems_for_contest('test_platform', 'test_contest')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue