summaryrefslogtreecommitdiffstatshomepage
path: root/test/functional/vimscript/has_spec.lua
blob: 3236e9dc3dfac454b4952555edfe60f2d06b29d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')

local clear = n.clear
local connect = n.connect
local get_session = n.get_session
local eq = t.eq
local fn = n.fn
local is_os = t.is_os
local nvim_prog = n.nvim_prog

describe('has()', function()
  before_each(clear)

  it('"nvim-x.y.z"', function()
    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'))

    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'))
  end)

  it('"unnamedplus"', function()
    if (not is_os('win')) and fn.has('clipboard') == 1 then
      eq(1, fn.has('unnamedplus'))
    else
      eq(0, fn.has('unnamedplus'))
    end
  end)

  it('"terminfo"', function()
    -- Looks like "HAVE_UNIBILIUM ", "HAVE_UNIBILIUM=1", "HAVE_UNIBILIUM off", ….
    -- Capture group returns the "1"/"off"/….
    local build_flag = vim.trim(
      (n.exec_capture('verbose version'):match('HAVE_UNIBILIUM([^-]+)') or 'missing'):lower()
    )
    -- XXX: the match() above fails in CI so currently we assume CI always builds with unibilium.
    local is_enabled = t.is_ci()
      or not (
        build_flag == 'missing'
        or build_flag == 'false'
        or build_flag == '0'
        or build_flag == 'off'
      )
    eq(is_enabled and 1 or 0, fn.has('terminfo'))
  end)

  it('"wsl"', function()
    local is_wsl = vim.uv.os_uname()['release']:lower():match('microsoft') and true or false
    if is_wsl then
      eq(1, fn.has('wsl'))
    else
      eq(0, fn.has('wsl'))
    end
  end)

  it('"gui_running"', function()
    eq(0, fn.has('gui_running'))
    local tui_session = get_session()
    local gui_session = connect(fn.serverstart())
    eq(0, fn.has('gui_running'))
    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)
    eq(1, fn.has('gui_running'))
    tui:detach()
    eq(1, fn.has('gui_running'))
    gui:detach()
    eq(0, fn.has('gui_running'))
  end)

  it('does not change v:shell_error', function()
    fn.system({ nvim_prog, '-es', '+73cquit' })
    fn.has('python3') -- use a call whose implementation shells out
    eq(73, fn.eval('v:shell_error'))
  end)

  it('"patch[0-9]\\+"', function()
    eq(1, fn.has('patch0'))
    eq(1, fn.has('patch1'))
  end)

  it('"patch-x.y.z"', function()
    -- versions older than current v:version always succeed
    -- unless minor version has 2+ digits
    eq(1, fn.has('patch-7.4.0'))
    eq(0, fn.has('patch-7.40.0'))
    eq(1, fn.has('patch-8.0.0'))
    eq(0, fn.has('patch-8.00.0'))

    eq(1, fn.has('patch-8.1.0'))
    eq(1, fn.has('patch-8.1.1'))
    eq(1, fn.has('patch-8.1.0001'))
    eq(1, fn.has('patch-8.1.1939'))
    eq(1, fn.has('patch-8.1.2424'))

    eq(0, fn.has('patch-8.2.0'))
    eq(1, fn.has('patch-8.2.1'))
    eq(1, fn.has('patch-8.2.2999'))
    eq(1, fn.has('patch-8.2.5171'))

    eq(0, fn.has('patch-9.0.0'))
    eq(1, fn.has('patch-9.0.1'))
    eq(1, fn.has('patch-9.0.998'))
    eq(1, fn.has('patch-9.0.2190'))

    eq(0, fn.has('patch-9.1.0'))
    eq(1, fn.has('patch-9.1.1'))
    eq(1, fn.has('patch-9.1.690'))
    eq(1, fn.has('patch-9.1.1934'))
  end)
end)