fix(test): mock
This commit is contained in:
parent
76cb1e456e
commit
a84b1697bf
4 changed files with 52 additions and 3 deletions
|
|
@ -75,10 +75,15 @@ describe('async integration', function()
|
|||
end,
|
||||
}
|
||||
|
||||
vim.cmd = {
|
||||
local cmd_methods = {
|
||||
e = function() end,
|
||||
only = function() end,
|
||||
startinsert = function() end,
|
||||
stopinsert = function() end,
|
||||
}
|
||||
vim.cmd = setmetatable(function() end, {
|
||||
__index = cmd_methods,
|
||||
})
|
||||
vim.api.nvim_get_current_buf = function()
|
||||
return 1
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ describe('cp.async.setup', function()
|
|||
},
|
||||
})
|
||||
end,
|
||||
scrape_problem_async = function(platform, contest_id, problem_id, callback)
|
||||
scrape_problem_async = function(_, _, problem_id, callback)
|
||||
callback({
|
||||
success = true,
|
||||
problem_id = problem_id,
|
||||
|
|
@ -69,10 +69,15 @@ describe('cp.async.setup', function()
|
|||
end,
|
||||
}
|
||||
|
||||
vim.cmd = {
|
||||
local cmd_methods = {
|
||||
e = function() end,
|
||||
only = function() end,
|
||||
startinsert = function() end,
|
||||
stopinsert = function() end,
|
||||
}
|
||||
vim.cmd = setmetatable(function() end, {
|
||||
__index = cmd_methods,
|
||||
})
|
||||
vim.api.nvim_get_current_buf = function()
|
||||
return 1
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,6 +4,19 @@ describe('cp.cache', function()
|
|||
|
||||
before_each(function()
|
||||
spec_helper.setup()
|
||||
|
||||
local mock_file_content = '{}'
|
||||
vim.fn.filereadable = function()
|
||||
return 1
|
||||
end
|
||||
vim.fn.readfile = function()
|
||||
return { mock_file_content }
|
||||
end
|
||||
vim.fn.writefile = function(lines)
|
||||
mock_file_content = table.concat(lines, '\n')
|
||||
end
|
||||
vim.fn.mkdir = function() end
|
||||
|
||||
cache = require('cp.cache')
|
||||
cache.load()
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,29 @@ describe('cp command parsing', function()
|
|||
}
|
||||
package.loaded['cp.log'] = mock_logger
|
||||
|
||||
local mock_async_setup = {
|
||||
setup_contest_async = function() end,
|
||||
handle_full_setup_async = function() end,
|
||||
setup_problem_async = function() end,
|
||||
}
|
||||
package.loaded['cp.async.setup'] = mock_async_setup
|
||||
local mock_setup = {
|
||||
set_platform = function()
|
||||
return true
|
||||
end,
|
||||
}
|
||||
package.loaded['cp.setup'] = mock_setup
|
||||
|
||||
local mock_state = {
|
||||
get_platform = function()
|
||||
return 'atcoder'
|
||||
end,
|
||||
get_contest_id = function()
|
||||
return 'abc123'
|
||||
end,
|
||||
}
|
||||
package.loaded['cp.state'] = mock_state
|
||||
|
||||
cp = require('cp')
|
||||
cp.setup({
|
||||
contests = {
|
||||
|
|
@ -29,6 +52,9 @@ describe('cp command parsing', function()
|
|||
|
||||
after_each(function()
|
||||
package.loaded['cp.log'] = nil
|
||||
package.loaded['cp.async.setup'] = nil
|
||||
package.loaded['cp.setup'] = nil
|
||||
package.loaded['cp.state'] = nil
|
||||
end)
|
||||
|
||||
describe('empty arguments', function()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue