has_spec.lua 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local Screen = require('test.functional.ui.screen')
  4. local clear = n.clear
  5. local connect = n.connect
  6. local get_session = n.get_session
  7. local eq = t.eq
  8. local fn = n.fn
  9. local is_os = t.is_os
  10. local nvim_prog = n.nvim_prog
  11. describe('has()', function()
  12. before_each(clear)
  13. it('"nvim-x.y.z"', function()
  14. eq(0, fn.has('nvim-'))
  15. eq(0, fn.has('nvim- '))
  16. eq(0, fn.has('nvim- \t '))
  17. eq(0, fn.has('nvim-0. 1. 1'))
  18. eq(0, fn.has('nvim-0. 1.1'))
  19. eq(0, fn.has('nvim-0.1. 1'))
  20. eq(0, fn.has('nvim-a'))
  21. eq(0, fn.has('nvim-a.b.c'))
  22. eq(0, fn.has('nvim-0.b.c'))
  23. eq(0, fn.has('nvim-0.0.c'))
  24. eq(0, fn.has('nvim-0.b.0'))
  25. eq(0, fn.has('nvim-a.b.0'))
  26. eq(0, fn.has('nvim-.0.0.0'))
  27. eq(0, fn.has('nvim-.0'))
  28. eq(0, fn.has('nvim-0.'))
  29. eq(0, fn.has('nvim-0..'))
  30. eq(0, fn.has('nvim-.'))
  31. eq(0, fn.has('nvim-..'))
  32. eq(0, fn.has('nvim-...'))
  33. eq(0, fn.has('nvim-42'))
  34. eq(0, fn.has('nvim-9999'))
  35. eq(0, fn.has('nvim-99.001.05'))
  36. eq(1, fn.has('nvim'))
  37. eq(1, fn.has('nvim-0'))
  38. eq(1, fn.has('nvim-0.1'))
  39. eq(1, fn.has('nvim-0.0.0'))
  40. eq(1, fn.has('nvim-0.1.1.'))
  41. eq(1, fn.has('nvim-0.1.1.abc'))
  42. eq(1, fn.has('nvim-0.1.1..'))
  43. eq(1, fn.has('nvim-0.1.1.. ..'))
  44. eq(1, fn.has('nvim-0.1.1.... '))
  45. eq(1, fn.has('nvim-0.0.0'))
  46. eq(1, fn.has('nvim-0.0.1'))
  47. eq(1, fn.has('nvim-0.1.0'))
  48. eq(1, fn.has('nvim-0.1.1'))
  49. eq(1, fn.has('nvim-0.1.5'))
  50. eq(1, fn.has('nvim-0000.001.05'))
  51. eq(1, fn.has('nvim-0.01.005'))
  52. eq(1, fn.has('nvim-00.001.05'))
  53. end)
  54. it('"unnamedplus"', function()
  55. if (not is_os('win')) and fn.has('clipboard') == 1 then
  56. eq(1, fn.has('unnamedplus'))
  57. else
  58. eq(0, fn.has('unnamedplus'))
  59. end
  60. end)
  61. it('"wsl"', function()
  62. local is_wsl = vim.uv.os_uname()['release']:lower():match('microsoft') and true or false
  63. if is_wsl then
  64. eq(1, fn.has('wsl'))
  65. else
  66. eq(0, fn.has('wsl'))
  67. end
  68. end)
  69. it('"gui_running"', function()
  70. eq(0, fn.has('gui_running'))
  71. local tui_session = get_session()
  72. local gui_session = connect(fn.serverstart())
  73. eq(0, fn.has('gui_running'))
  74. local tui = Screen.new(50, 5, { rgb = true, stdin_tty = true, stdout_tty = true }, tui_session)
  75. eq(0, fn.has('gui_running'))
  76. local gui = Screen.new(50, 15, { ext_multigrid = true, rgb = true }, gui_session)
  77. eq(1, fn.has('gui_running'))
  78. tui:detach()
  79. eq(1, fn.has('gui_running'))
  80. gui:detach()
  81. eq(0, fn.has('gui_running'))
  82. end)
  83. it('does not change v:shell_error', function()
  84. fn.system({ nvim_prog, '-es', '+73cquit' })
  85. fn.has('python3') -- use a call whose implementation shells out
  86. eq(73, fn.eval('v:shell_error'))
  87. end)
  88. end)