Skip to content

Commit

Permalink
test: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
finxxi authored and xixiaofinland committed Jul 28, 2024
1 parent 00aae29 commit a4bcfb6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
12 changes: 11 additions & 1 deletion tests/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Helpers.new_child_neovim = function()
end

child.setup = function()
child.restart({'-u', 'scripts/minimal_init.lua'})
child.restart({ '-u', 'scripts/minimal_init.lua' })
child.bo.readonly = false
end

Expand All @@ -34,6 +34,16 @@ Helpers.new_child_neovim = function()
child.lua(req_cmd, { config })
end

child.open_in_sf_dir = function(file)
local lua_cmd = string.format('edit tests/dir/sf-project/%s', file)
child.cmd(lua_cmd)
end

child.open_in_non_sf_dir = function(file)
local lua_cmd = string.format('edit tests/dir/non-sf-project/%s', file)
child.cmd(lua_cmd)
end

return child
end

Expand Down
22 changes: 11 additions & 11 deletions tests/test_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ local expect_config = function(field, value) eq(child.lua_get('vim.g.sf.' .. fie
T['setup()'] = new_set()

T['setup()']['has filetypes defined'] = function()
child.cmd('edit tests/dir/sf-project/SfProject.cls')
child.open_in_sf_dir('SfProject.cls')
eq(child.lua_get('vim.bo.filetype'), 'apex')

child.cmd('edit tests/dir/sf-project/Account.trigger')
child.open_in_sf_dir('Account.trigger')
eq(child.lua_get('vim.bo.filetype'), 'apex')

child.cmd('edit tests/dir/sf-project/abc.soql')
child.open_in_sf_dir('abc.soql')
eq(child.lua_get('vim.bo.filetype'), 'soql')

child.cmd('edit tests/dir/sf-project/query.sosl')
child.open_in_sf_dir('query.sosl')
eq(child.lua_get('vim.bo.filetype'), 'sosl')

child.cmd('edit tests/dir/sf-project/page.html')
child.open_in_sf_dir('page.html')
eq(child.lua_get('vim.bo.filetype'), 'html')
end

Expand Down Expand Up @@ -134,7 +134,7 @@ T['setup()']['has default code sign config'] = function()
end

T['setup()']['no user-keys when non-sf-project dir'] = function()
child.cmd('edit tests/dir/non-sf-project/NonsfProject.cls')
child.open_in_non_sf_dir('NonsfProject.cls')

-- global;
no_nmap('<leader>ss')
Expand All @@ -148,7 +148,7 @@ T['setup()']['no user-keys when non-sf-project dir'] = function()
end

T['setup()']['only global user-keys when sf-project dir but file not in "hotkeys_in_filetypes"'] = function()
child.cmd('edit tests/dir/sf-project/test.txt')
child.open_in_sf_dir('test.txt')

-- global;
has_nmap('<leader>ss')
Expand All @@ -162,7 +162,7 @@ T['setup()']['only global user-keys when sf-project dir but file not in "hotkeys
end

T['setup()']['has all user-keys when opening Apex in sf-project dir'] = function()
child.cmd('edit tests/dir/sf-project/SfProject.cls')
child.open_in_sf_dir('SfProject.cls')

-- global;
has_nmap('<leader>ss')
Expand All @@ -176,7 +176,7 @@ T['setup()']['has all user-keys when opening Apex in sf-project dir'] = function
end

T['setup()']['SFTerm filetype has its user-keys defined by autocmd despite of non-sf-project dir.'] = function()
child.cmd('edit tests/dir/non-sf-project/SFTerm')
child.open_in_non_sf_dir('SFTerm')
no_nmap('<leader><leader>')
no_nmap('<C-c>')

Expand All @@ -196,13 +196,13 @@ T['setup()']['the VimEnter event can be disabled by custom config'] = function()
end

T['setup()']['no user commands in non-sf-project dir'] = function()
child.cmd('edit tests/dir/non-sf-project/test.txt')
child.open_in_non_sf_dir('test.txt')

eq(child.api.nvim_get_commands({})['SF'], nil)
end

T['setup()']['has user commands in sf-project dir'] = function()
child.cmd('edit tests/dir/sf-project/text.txt')
child.open_in_sf_dir('text.txt')

eq(child.api.nvim_get_commands({})['SF'].name, 'SF')
end
Expand Down
23 changes: 9 additions & 14 deletions tests/test_core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,14 @@ end

T['copy_apex_name()'] = new_set()

T['copy_apex_name()']['return apex name'] = function()
local apex_name = 'SfProject'
local lua_cmd = string.format('edit tests/dir/sf-project/%s.cls', apex_name)
child.cmd(lua_cmd)

child.type_keys('<leader>cc')

eq(child.lua_get('vim.bo.filetype'), 'apex')
eq(child.bo.filetype, 'apex')

-- TODO: fix
-- eq(child.lua_get([[vim.fn.getreg("*")]]), apex_name)
-- eq(child.fn.getreg("*"), apex_name)
end
-- TODO: works only locally, fail in CI
-- T['copy_apex_name()']['return apex name'] = function()
-- local apex_name = 'SfProject'
-- child.open_in_sf_dir(apex_name .. '.cls')
--
-- child.lua([[Sf.copy_apex_name()]])
-- -- eq(child.fn.getreg("*"), apex_name)
-- eq(child.lua_get('vim.fn.getreg("*")'), apex_name)
-- end

return T

0 comments on commit a4bcfb6

Please sign in to comment.