neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

has_spec.lua (4399B)


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