num_options_spec.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. -- Tests for :setlocal and :setglobal
  2. local helpers = require('test.functional.helpers')(after_each)
  3. local clear, feed_command, eval, eq, meths =
  4. helpers.clear, helpers.feed_command, helpers.eval, helpers.eq, helpers.meths
  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(meths.set_option, opt, value)
  13. eq(status, false)
  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. meths.set_option(opt, value)
  21. eq(value, meths.get_option(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, meths.get_option('iminsert'))
  28. feed_command('setlocal iminsert=1')
  29. eq(0, meths.get_option('iminsert'))
  30. eq(0, meths.get_option('imsearch'))
  31. feed_command('setlocal imsearch=1')
  32. eq(0, meths.get_option('imsearch'))
  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', 0, '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('scrolloff', -1, 'E49')
  62. should_fail('sidescrolloff', -1, 'E487')
  63. should_fail('sidescroll', -1, 'E487')
  64. should_fail('cmdwinheight', 0, 'E487')
  65. should_fail('updatetime', -1, 'E487')
  66. should_fail('foldlevel', -5, 'E487')
  67. should_fail('foldcolumn', 13, 'E474')
  68. should_fail('conceallevel', 4, 'E474')
  69. should_fail('numberwidth', 11, 'E474')
  70. should_fail('numberwidth', 0, 'E487')
  71. -- If smaller than 1 this one is set to 'lines'-1
  72. feed_command('setglobal window=-10')
  73. meths.set_option('window', -10)
  74. eq(23, meths.get_option('window'))
  75. eq('', eval("v:errmsg"))
  76. end)
  77. it('set wmh/wh wmw/wiw checks', function()
  78. feed_command('set winheight=2')
  79. feed_command('set winminheight=3')
  80. eq('E591', eval("v:errmsg"):match("E%d*"))
  81. feed_command('set winwidth=2')
  82. feed_command('set winminwidth=3')
  83. eq('E592', eval("v:errmsg"):match("E%d*"))
  84. end)
  85. it('set maxcombine resets to 6', function()
  86. local function setto(value)
  87. feed_command('setglobal maxcombine=' .. value)
  88. feed_command('setlocal maxcombine=' .. value)
  89. meths.set_option('maxcombine', value)
  90. eq(6, meths.get_option('maxcombine'))
  91. eq('', eval("v:errmsg"))
  92. end
  93. setto(0)
  94. setto(1)
  95. setto(6)
  96. setto(7)
  97. end)
  98. end)