robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
4.5 KiB152 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each, pending = t.describe, t.it, t.before_each, t.pending
6local clear = n.clear
7local connect = n.connect
8local get_session = n.get_session
9local eq = t.eq
10local fn = n.fn
11local is_os = t.is_os
12local nvim_prog = n.nvim_prog
13
14describe('has()', function()
15  before_each(clear)
16
17  it('"nvim-x.y.z"', function()
18    eq(0, fn.has('nvim-'))
19    eq(0, fn.has('nvim-  '))
20    eq(0, fn.has('nvim- \t '))
21    eq(0, fn.has('nvim-0. 1. 1'))
22    eq(0, fn.has('nvim-0. 1.1'))
23    eq(0, fn.has('nvim-0.1. 1'))
24    eq(0, fn.has('nvim-a'))
25    eq(0, fn.has('nvim-a.b.c'))
26    eq(0, fn.has('nvim-0.b.c'))
27    eq(0, fn.has('nvim-0.0.c'))
28    eq(0, fn.has('nvim-0.b.0'))
29    eq(0, fn.has('nvim-a.b.0'))
30    eq(0, fn.has('nvim-.0.0.0'))
31    eq(0, fn.has('nvim-.0'))
32    eq(0, fn.has('nvim-0.'))
33    eq(0, fn.has('nvim-0..'))
34    eq(0, fn.has('nvim-.'))
35    eq(0, fn.has('nvim-..'))
36    eq(0, fn.has('nvim-...'))
37    eq(0, fn.has('nvim-42'))
38    eq(0, fn.has('nvim-9999'))
39    eq(0, fn.has('nvim-99.001.05'))
40
41    eq(1, fn.has('nvim'))
42    eq(1, fn.has('nvim-0'))
43    eq(1, fn.has('nvim-0.1'))
44    eq(1, fn.has('nvim-0.0.0'))
45    eq(1, fn.has('nvim-0.1.1.'))
46    eq(1, fn.has('nvim-0.1.1.abc'))
47    eq(1, fn.has('nvim-0.1.1..'))
48    eq(1, fn.has('nvim-0.1.1.. ..'))
49    eq(1, fn.has('nvim-0.1.1.... '))
50    eq(1, fn.has('nvim-0.0.0'))
51    eq(1, fn.has('nvim-0.0.1'))
52    eq(1, fn.has('nvim-0.1.0'))
53    eq(1, fn.has('nvim-0.1.1'))
54    eq(1, fn.has('nvim-0.1.5'))
55    eq(1, fn.has('nvim-0000.001.05'))
56    eq(1, fn.has('nvim-0.01.005'))
57    eq(1, fn.has('nvim-00.001.05'))
58  end)
59
60  it('"unnamedplus"', function()
61    if (not is_os('win')) and fn.has('clipboard') == 1 then
62      eq(1, fn.has('unnamedplus'))
63    else
64      eq(0, fn.has('unnamedplus'))
65    end
66  end)
67
68  it('"terminfo"', function()
69    local version = n.exec_capture('verbose version')
70    local compilation_string = version:match('Compilation: (.*)')
71    -- zig builds currently show only TODO for the compilation string
72    if not compilation_string or compilation_string:match('TODO') then
73      pending('no compilation string present')
74    end
75    -- Looks like "HAVE_UNIBILIUM ", "HAVE_UNIBILIUM=1", "HAVE_UNIBILIUM off", ….
76    -- Capture group returns the "1"/"off"/….
77    local build_flag =
78      vim.trim((compilation_string:match('HAVE_UNIBILIUM([^-]+)') or 'missing'):lower())
79    local is_enabled = not (
80      build_flag == 'missing'
81      or build_flag == 'false'
82      or build_flag == '0'
83      or build_flag == 'off'
84    )
85    eq(is_enabled and 1 or 0, fn.has('terminfo'))
86  end)
87
88  it('"wsl"', function()
89    local is_wsl = vim.uv.os_uname()['release']:lower():match('microsoft') and true or false
90    if is_wsl then
91      eq(1, fn.has('wsl'))
92    else
93      eq(0, fn.has('wsl'))
94    end
95  end)
96
97  it('"gui_running"', function()
98    eq(0, fn.has('gui_running'))
99    local tui_session = get_session()
100    local gui_session = connect(fn.serverstart())
101    eq(0, fn.has('gui_running'))
102    local tui = Screen.new(50, 5, { rgb = true, stdin_tty = true, stdout_tty = true }, tui_session)
103    eq(0, fn.has('gui_running'))
104    local gui = Screen.new(50, 15, { ext_multigrid = true, rgb = true }, gui_session)
105    eq(1, fn.has('gui_running'))
106    tui:detach()
107    eq(1, fn.has('gui_running'))
108    gui:detach()
109    eq(0, fn.has('gui_running'))
110  end)
111
112  it('does not change v:shell_error', function()
113    fn.system({ nvim_prog, '-es', '+73cquit' })
114    fn.has('python3') -- use a call whose implementation shells out
115    eq(73, fn.eval('v:shell_error'))
116  end)
117
118  it('"patch[0-9]\\+"', function()
119    eq(1, fn.has('patch0'))
120    eq(1, fn.has('patch1'))
121  end)
122
123  it('"patch-x.y.z"', function()
124    -- versions older than current v:version always succeed
125    -- unless minor version has 2+ digits
126    eq(1, fn.has('patch-7.4.0'))
127    eq(0, fn.has('patch-7.40.0'))
128    eq(1, fn.has('patch-8.0.0'))
129    eq(0, fn.has('patch-8.00.0'))
130
131    eq(1, fn.has('patch-8.1.0'))
132    eq(1, fn.has('patch-8.1.1'))
133    eq(1, fn.has('patch-8.1.0001'))
134    eq(1, fn.has('patch-8.1.1939'))
135    eq(1, fn.has('patch-8.1.2424'))
136
137    eq(0, fn.has('patch-8.2.0'))
138    eq(1, fn.has('patch-8.2.1'))
139    eq(1, fn.has('patch-8.2.2999'))
140    eq(1, fn.has('patch-8.2.5171'))
141
142    eq(0, fn.has('patch-9.0.0'))
143    eq(1, fn.has('patch-9.0.1'))
144    eq(1, fn.has('patch-9.0.998'))
145    eq(1, fn.has('patch-9.0.2190'))
146
147    eq(1, fn.has('patch-9.1.0'))
148    eq(1, fn.has('patch-9.1.1'))
149    eq(1, fn.has('patch-9.1.690'))
150    eq(1, fn.has('patch-9.1.1934'))
151  end)
152end)