test: add simple window unit test

This commit is contained in:
JuanZoran
2023-03-31 12:51:11 +08:00
parent b27bc4ed26
commit 987e1a3341
5 changed files with 120 additions and 20 deletions

View File

@ -53,6 +53,7 @@ function M.get_str(mode)
end,
V = function()
print 'TODO'
return ''
end,
})[mode]():match '^%s*(.-)%s*$'
end
@ -174,7 +175,7 @@ end
---@param str string
---@return boolean
function M.is_word(str)
return str:match '%w+' == str
return str:find('%W') == nil
end
---@param list any[]

View File

@ -161,21 +161,9 @@ window.__index = window
---@alias WindowOpts
---|{style: string, border: string, focusable: boolean, noautocmd?: boolean, relative: string, width: integer, height: integer, col: integer, row: integer, zindex?: integer, title?: table | string}
---|{style: string, border: string, focusable: boolean, noautocmd?: boolean, relative: 'mouse'|'cursor'|'editor'|'win', width: integer, height: integer, col: integer, row: integer, zindex?: integer, title?: table | string}
---@class TransWindowOpts
local default_opts = {
enter = false,
winid = -1,
---@type WindowOpts
win_opts = {
style = 'minimal',
border = 'rounded',
focusable = false,
noautocmd = true,
},
}
---@class TransWindow
@ -197,11 +185,37 @@ local default_opts = {
-- relative = relative,
-- }
local default_opts = {
enter = false,
winid = -1,
---@type WindowOpts
win_opts = {
-- INFO : ensured options
-- col
-- row
-- width
-- height
-- relative
-- zindex
style = 'minimal',
border = 'rounded',
focusable = false,
noautocmd = true,
},
}
---@class TransWindowOpts
---@field buffer TransBuffer attached buffer object
---@field enter? boolean cursor should [enter] window when open,default: false
---@field win_opts WindowOpts window config [**When open**]
---@field animation? table? Hover Window Animation
---Create new window
---@param opts TransWindowOpts window config
---@return TransWindow
function window.new(opts)
opts = vim.tbl_deep_extend('keep', opts, default_opts)
opts.animation = opts.animation or { interval = 12 }
local win = setmetatable(opts, window)
---@cast win TransWindow