num_options_spec.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. -- Tests for :setlocal and :setglobal
  2. local t = require('test.testutil')
  3. local n = require('test.functional.testnvim')()
  4. local clear, feed_command, eval, eq, api = n.clear, n.feed_command, n.eval, t.eq, n.api
  5. local function should_fail(opt, value, errmsg)
  6. feed_command('setglobal ' .. opt .. '=' .. value)
  7. eq(errmsg, eval('v:errmsg'):match('E%d*'))
  8. feed_command('let v:errmsg = ""')
  9. feed_command('setlocal ' .. opt .. '=' .. value)
  10. eq(errmsg, eval('v:errmsg'):match('E%d*'))
  11. feed_command('let v:errmsg = ""')
  12. local status, err = pcall(api.nvim_set_option_value, opt, value, {})
  13. eq(false, status)
  14. eq(errmsg, err:match('E%d*'))
  15. eq('', eval('v:errmsg'))
  16. end
  17. local function should_succeed(opt, value)
  18. feed_command('setglobal ' .. opt .. '=' .. value)
  19. feed_command('setlocal ' .. opt .. '=' .. value)
  20. api.nvim_set_option_value(opt, value, {})
  21. eq(value, api.nvim_get_option_value(opt, {}))
  22. eq('', eval('v:errmsg'))
  23. end
  24. describe(':setlocal', function()
  25. before_each(clear)
  26. it('setlocal sets only local value', function()
  27. eq(0, api.nvim_get_option_value('iminsert', { scope = 'global' }))
  28. feed_command('setlocal iminsert=1')
  29. eq(0, api.nvim_get_option_value('iminsert', { scope = 'global' }))
  30. eq(-1, api.nvim_get_option_value('imsearch', { scope = 'global' }))
  31. feed_command('setlocal imsearch=1')
  32. eq(-1, api.nvim_get_option_value('imsearch', { scope = 'global' }))
  33. end)
  34. end)
  35. describe(':set validation', function()
  36. before_each(clear)
  37. it('setlocal and setglobal validate values', function()
  38. should_fail('shiftwidth', -10, 'E487')
  39. should_succeed('shiftwidth', 0)
  40. should_fail('tabstop', -10, 'E487')
  41. should_fail('winheight', -10, 'E487')
  42. should_fail('winheight', 0, 'E487')
  43. should_fail('winminheight', -1, 'E487')
  44. should_succeed('winminheight', 0)
  45. should_fail('winwidth', 0, 'E487')
  46. should_fail('helpheight', -1, 'E487')
  47. should_fail('iminsert', 3, 'E474')
  48. should_fail('imsearch', 3, 'E474')
  49. should_fail('titlelen', -1, 'E487')
  50. should_fail('cmdheight', -1, 'E487')
  51. should_fail('updatecount', -1, 'E487')
  52. should_fail('textwidth', -1, 'E487')
  53. should_fail('tabstop', 0, 'E487')
  54. should_fail('timeoutlen', -1, 'E487')
  55. should_fail('history', 1000000, 'E474')
  56. should_fail('regexpengine', -1, 'E474')
  57. should_fail('regexpengine', 3, 'E474')
  58. should_succeed('regexpengine', 2)
  59. should_fail('report', -1, 'E487')
  60. should_succeed('report', 0)
  61. should_fail('sidescroll', -1, 'E487')
  62. should_fail('cmdwinheight', 0, 'E487')
  63. should_fail('updatetime', -1, 'E487')
  64. should_fail('foldlevel', -5, 'E487')
  65. should_fail('foldcolumn', '13', 'E474')
  66. should_fail('conceallevel', 4, 'E474')
  67. should_fail('numberwidth', 21, 'E474')
  68. should_fail('numberwidth', 0, 'E487')
  69. -- If smaller than 1 this one is set to 'lines'-1
  70. feed_command('setglobal window=-10')
  71. api.nvim_set_option_value('window', -10, {})
  72. eq(23, api.nvim_get_option_value('window', {}))
  73. eq('', eval('v:errmsg'))
  74. -- 'scrolloff' and 'sidescrolloff' can have a -1 value when
  75. -- set for the current window, but not globally
  76. feed_command('setglobal scrolloff=-1')
  77. eq('E487', eval('v:errmsg'):match('E%d*'))
  78. feed_command('setglobal sidescrolloff=-1')
  79. eq('E487', eval('v:errmsg'):match('E%d*'))
  80. feed_command('let v:errmsg=""')
  81. feed_command('setlocal scrolloff=-1')
  82. eq('', eval('v:errmsg'))
  83. feed_command('setlocal sidescrolloff=-1')
  84. eq('', eval('v:errmsg'))
  85. end)
  86. it('set wmh/wh wmw/wiw checks', function()
  87. feed_command('set winheight=2')
  88. feed_command('set winminheight=3')
  89. eq('E591', eval('v:errmsg'):match('E%d*'))
  90. feed_command('set winwidth=2')
  91. feed_command('set winminwidth=3')
  92. eq('E592', eval('v:errmsg'):match('E%d*'))
  93. end)
  94. it('set maxcombine resets to 6', function()
  95. local function setto(value)
  96. feed_command('setglobal maxcombine=' .. value)
  97. feed_command('setlocal maxcombine=' .. value)
  98. api.nvim_set_option_value('maxcombine', value, {})
  99. eq(6, api.nvim_get_option_value('maxcombine', {}))
  100. eq('', eval('v:errmsg'))
  101. end
  102. setto(0)
  103. setto(1)
  104. setto(6)
  105. setto(7)
  106. end)
  107. end)