2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2023-02-27 08:31:05 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2024-04-20 08:44:13 -07:00
|
|
|
|
|
|
|
local clear = n.clear
|
|
|
|
local connect = n.connect
|
2024-11-11 14:15:19 -07:00
|
|
|
local get_session = n.get_session
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
2024-04-20 08:44:13 -07:00
|
|
|
local fn = n.fn
|
2024-04-08 02:03:20 -07:00
|
|
|
local is_os = t.is_os
|
2024-04-20 08:44:13 -07:00
|
|
|
local nvim_prog = n.nvim_prog
|
2015-05-04 21:15:09 -07:00
|
|
|
|
|
|
|
describe('has()', function()
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
it('"nvim-x.y.z"', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, fn.has('nvim-'))
|
|
|
|
eq(0, fn.has('nvim- '))
|
|
|
|
eq(0, fn.has('nvim- \t '))
|
|
|
|
eq(0, fn.has('nvim-0. 1. 1'))
|
|
|
|
eq(0, fn.has('nvim-0. 1.1'))
|
|
|
|
eq(0, fn.has('nvim-0.1. 1'))
|
|
|
|
eq(0, fn.has('nvim-a'))
|
|
|
|
eq(0, fn.has('nvim-a.b.c'))
|
|
|
|
eq(0, fn.has('nvim-0.b.c'))
|
|
|
|
eq(0, fn.has('nvim-0.0.c'))
|
|
|
|
eq(0, fn.has('nvim-0.b.0'))
|
|
|
|
eq(0, fn.has('nvim-a.b.0'))
|
|
|
|
eq(0, fn.has('nvim-.0.0.0'))
|
|
|
|
eq(0, fn.has('nvim-.0'))
|
|
|
|
eq(0, fn.has('nvim-0.'))
|
|
|
|
eq(0, fn.has('nvim-0..'))
|
|
|
|
eq(0, fn.has('nvim-.'))
|
|
|
|
eq(0, fn.has('nvim-..'))
|
|
|
|
eq(0, fn.has('nvim-...'))
|
|
|
|
eq(0, fn.has('nvim-42'))
|
|
|
|
eq(0, fn.has('nvim-9999'))
|
|
|
|
eq(0, fn.has('nvim-99.001.05'))
|
2015-05-04 21:15:09 -07:00
|
|
|
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, fn.has('nvim'))
|
|
|
|
eq(1, fn.has('nvim-0'))
|
|
|
|
eq(1, fn.has('nvim-0.1'))
|
|
|
|
eq(1, fn.has('nvim-0.0.0'))
|
|
|
|
eq(1, fn.has('nvim-0.1.1.'))
|
|
|
|
eq(1, fn.has('nvim-0.1.1.abc'))
|
|
|
|
eq(1, fn.has('nvim-0.1.1..'))
|
|
|
|
eq(1, fn.has('nvim-0.1.1.. ..'))
|
|
|
|
eq(1, fn.has('nvim-0.1.1.... '))
|
|
|
|
eq(1, fn.has('nvim-0.0.0'))
|
|
|
|
eq(1, fn.has('nvim-0.0.1'))
|
|
|
|
eq(1, fn.has('nvim-0.1.0'))
|
|
|
|
eq(1, fn.has('nvim-0.1.1'))
|
|
|
|
eq(1, fn.has('nvim-0.1.5'))
|
|
|
|
eq(1, fn.has('nvim-0000.001.05'))
|
|
|
|
eq(1, fn.has('nvim-0.01.005'))
|
|
|
|
eq(1, fn.has('nvim-00.001.05'))
|
2015-05-04 21:15:09 -07:00
|
|
|
end)
|
|
|
|
|
2017-02-18 06:04:46 -07:00
|
|
|
it('"unnamedplus"', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
if (not is_os('win')) and fn.has('clipboard') == 1 then
|
|
|
|
eq(1, fn.has('unnamedplus'))
|
2017-02-18 06:04:46 -07:00
|
|
|
else
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, fn.has('unnamedplus'))
|
2017-02-18 06:04:46 -07:00
|
|
|
end
|
|
|
|
end)
|
2017-09-27 11:38:24 -07:00
|
|
|
|
|
|
|
it('"wsl"', function()
|
2024-01-12 05:03:25 -07:00
|
|
|
local is_wsl = vim.uv.os_uname()['release']:lower():match('microsoft') and true or false
|
2021-10-29 16:55:32 -07:00
|
|
|
if is_wsl then
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, fn.has('wsl'))
|
2021-10-29 16:55:32 -07:00
|
|
|
else
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, fn.has('wsl'))
|
2017-09-27 11:38:24 -07:00
|
|
|
end
|
|
|
|
end)
|
2022-04-26 20:58:25 -07:00
|
|
|
|
2023-02-27 08:31:05 -07:00
|
|
|
it('"gui_running"', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, fn.has('gui_running'))
|
2024-11-11 14:15:19 -07:00
|
|
|
local tui_session = get_session()
|
2024-01-12 10:59:57 -07:00
|
|
|
local gui_session = connect(fn.serverstart())
|
|
|
|
eq(0, fn.has('gui_running'))
|
2024-11-11 14:15:19 -07:00
|
|
|
local tui = Screen.new(50, 5, { rgb = true, stdin_tty = true, stdout_tty = true }, tui_session)
|
|
|
|
eq(0, fn.has('gui_running'))
|
|
|
|
local gui = Screen.new(50, 15, { ext_multigrid = true, rgb = true }, gui_session)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, fn.has('gui_running'))
|
2023-02-27 08:31:05 -07:00
|
|
|
tui:detach()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, fn.has('gui_running'))
|
2023-02-27 08:31:05 -07:00
|
|
|
gui:detach()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, fn.has('gui_running'))
|
2023-02-27 08:31:05 -07:00
|
|
|
end)
|
|
|
|
|
2022-04-26 20:58:25 -07:00
|
|
|
it('does not change v:shell_error', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.system({ nvim_prog, '-es', '+73cquit' })
|
|
|
|
fn.has('python3') -- use a call whose implementation shells out
|
|
|
|
eq(73, fn.eval('v:shell_error'))
|
2022-04-26 20:58:25 -07:00
|
|
|
end)
|
2015-05-04 21:15:09 -07:00
|
|
|
end)
|