From 628d0335b8e402008b3c03db9f5d2a109d5e8ef2 Mon Sep 17 00:00:00 2001 From: Jakob Schnitzer Date: Mon, 27 Mar 2017 09:51:14 +0200 Subject: options: add some tests --- test/functional/options/num_options_spec.lua | 42 ++++++++++++++++++++++ .../functional/options/setlocal_setglobal_spec.lua | 22 ------------ 2 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 test/functional/options/num_options_spec.lua delete mode 100644 test/functional/options/setlocal_setglobal_spec.lua diff --git a/test/functional/options/num_options_spec.lua b/test/functional/options/num_options_spec.lua new file mode 100644 index 0000000000..c37bbeffc3 --- /dev/null +++ b/test/functional/options/num_options_spec.lua @@ -0,0 +1,42 @@ +-- Tests for :setlocal and :setglobal + +local helpers = require('test.functional.helpers')(after_each) +local clear, execute, eval, eq, nvim = + helpers.clear, helpers.execute, helpers.eval, helpers.eq, helpers.nvim + +local function get_num_option_global(opt) + return nvim('command_output', 'setglobal ' .. opt .. '?'):match('%d+') +end + +local function should_fail(opt, value, errmsg) + execute('let v:errmsg = ""') + execute('setglobal ' .. opt .. '=' .. value) + eq(errmsg, eval("v:errmsg"):match("E%d*:")) + execute('let v:errmsg = ""') + execute('setlocal ' .. opt .. '=' .. value) + eq(errmsg, eval("v:errmsg"):match("E%d*:")) + execute('let v:errmsg = ""') +end + +describe(':setlocal', function() + before_each(clear) + + it('setlocal sets only local value', function() + eq('0', get_num_option_global('iminsert')) + execute('setlocal iminsert=1') + eq('0', get_num_option_global('iminsert')) + eq('0', get_num_option_global('imsearch')) + execute('setlocal imsearch=1') + eq('0', get_num_option_global('imsearch')) + end) +end) + +describe(':set validation', function() + before_each(clear) + + it('setlocal and setglobal validate values', function() + should_fail('shiftwidth', -10, 'E487') + should_fail('tabstop', -10, 'E487') + should_fail('winheight', -10, 'E487') + end) +end) diff --git a/test/functional/options/setlocal_setglobal_spec.lua b/test/functional/options/setlocal_setglobal_spec.lua deleted file mode 100644 index 6902437403..0000000000 --- a/test/functional/options/setlocal_setglobal_spec.lua +++ /dev/null @@ -1,22 +0,0 @@ --- Tests for :setlocal and :setglobal - -local helpers = require('test.functional.helpers')(after_each) -local clear, execute, eval, eq, nvim = - helpers.clear, helpers.execute, helpers.eval, helpers.eq, helpers.nvim - -local function get_num_option_global(opt) - return nvim('command_output', 'setglobal ' .. opt .. '?'):match('%d+') -end - -describe(':setlocal', function() - before_each(clear) - - it('setlocal sets only local value', function() - eq('0', get_num_option_global('iminsert')) - execute('setlocal iminsert=1') - eq('0', get_num_option_global('iminsert')) - eq('0', get_num_option_global('imsearch')) - execute('setlocal imsearch=1') - eq('0', get_num_option_global('imsearch')) - end) -end) -- cgit