aboutsummaryrefslogtreecommitdiff
path: root/test/functional/vimscript/has_spec.lua
blob: 82b3db5b67b1e15d385bea9bb7fb09577078a9d0 (plain) (blame)
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
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local connect = helpers.connect
local eq = helpers.eq
local fn = helpers.fn
local is_os = helpers.is_os
local nvim_prog = helpers.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('"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 = Screen.new(50, 15)
    local gui_session = connect(fn.serverstart())
    local gui = Screen.new(50, 15)
    eq(0, fn.has('gui_running'))
    tui:attach({ ext_linegrid = true, rgb = true, stdin_tty = true, stdout_tty = true })
    gui:attach({ 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)
end)