diff options
author | Jakob Schnitzer <mail@jakobschnitzer.de> | 2017-03-31 18:30:06 +0200 |
---|---|---|
committer | Jakob Schnitzer <mail@jakobschnitzer.de> | 2017-03-31 18:30:06 +0200 |
commit | 8a55f9b1c8bab2cf22e266d7e1eecde85119d75d (patch) | |
tree | 0ece163e052d96c99d587712710e93eeaa7de1e8 | |
parent | db095f65636664afb4b09a3920571bf0565c7763 (diff) | |
download | rneovim-8a55f9b1c8bab2cf22e266d7e1eecde85119d75d.tar.gz rneovim-8a55f9b1c8bab2cf22e266d7e1eecde85119d75d.tar.bz2 rneovim-8a55f9b1c8bab2cf22e266d7e1eecde85119d75d.zip |
update for changes in master; fix 'window'; tests
-rw-r--r-- | src/nvim/option.c | 10 | ||||
-rw-r--r-- | test/functional/options/num_options_spec.lua | 57 |
2 files changed, 48 insertions, 19 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index d5bc3c1765..eddfdd6218 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3997,7 +3997,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, // Many number options assume their value is in the signed int range. if (value < INT_MIN || value > INT_MAX) { - return e_invarg; + return (char *)e_invarg; } // Options that need some validation. @@ -4129,7 +4129,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, errmsg = e_positive; } } else if (pp == &curbuf->b_p_ts || pp == &p_ts) { - if (value <= 0) { + if (value < 1) { errmsg = e_positive; } } else if (pp == &curbuf->b_p_tw || pp == &p_tw) { @@ -4140,7 +4140,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, // Don't change the value and return early if validation failed. if (errmsg != NULL) { - return errmsg; + return (char *)errmsg; } *pp = value; @@ -4150,7 +4150,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, // For these options we want to fix some invalid values. if (pp == &p_window) { if (p_window < 1) { - p_window = 1; + p_window = Rows - 1; } else if (p_window >= Rows) { p_window = Rows - 1; } @@ -4188,7 +4188,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) { foldUpdateAll(curwin); } - } else if (pp == &curbuf->b_p_sw || pp == (long *)&curbuf->b_p_ts) { + } else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts) { // 'shiftwidth' or 'tabstop' if (foldmethodIsIndent(curwin)) { foldUpdateAll(curwin); diff --git a/test/functional/options/num_options_spec.lua b/test/functional/options/num_options_spec.lua index d0b63d3f91..620e758141 100644 --- a/test/functional/options/num_options_spec.lua +++ b/test/functional/options/num_options_spec.lua @@ -1,12 +1,8 @@ -- 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 clear, execute, eval, eq, meths = + helpers.clear, helpers.execute, helpers.eval, helpers.eq, helpers.meths local function should_fail(opt, value, errmsg) execute('let v:errmsg = ""') @@ -18,16 +14,23 @@ local function should_fail(opt, value, errmsg) execute('let v:errmsg = ""') end +local function should_succeed(opt, value) + execute('setglobal ' .. opt .. '=' .. value) + eq('', eval("v:errmsg")) + execute('setlocal ' .. opt .. '=' .. value) + eq('', eval("v:errmsg")) +end + describe(':setlocal', function() before_each(clear) it('setlocal sets only local value', function() - eq('0', get_num_option_global('iminsert')) + eq(0, meths.get_option('iminsert')) execute('setlocal iminsert=1') - eq('0', get_num_option_global('iminsert')) - eq('0', get_num_option_global('imsearch')) + eq(0, meths.get_option('iminsert')) + eq(0, meths.get_option('imsearch')) execute('setlocal imsearch=1') - eq('0', get_num_option_global('imsearch')) + eq(0, meths.get_option('imsearch')) end) end) @@ -36,17 +39,43 @@ describe(':set validation', function() it('setlocal and setglobal validate values', function() should_fail('shiftwidth', -10, 'E487') + should_succeed('shiftwidth', 0) should_fail('tabstop', -10, 'E487') should_fail('winheight', -10, 'E487') - should_fail('helpheight', -10, 'E487') - should_fail('maxcombine', 10, 'E474') + should_fail('winheight', 0, 'E487') + should_fail('winminheight', -1, 'E487') + should_succeed('winminheight', 0) + should_fail('winwidth', 0, 'E487') + should_fail('helpheight', -1, 'E487') + should_fail('maxcombine', 7, 'E474') + should_fail('iminsert', 3, 'E474') + should_fail('imsearch', 3, 'E474') + should_fail('titlelen', -1, 'E487') + should_fail('cmdheight', 0, 'E487') + should_fail('updatecount', -1, 'E487') + should_fail('textwidth', -1, 'E487') + should_fail('tabstop', 0, 'E487') + should_fail('timeoutlen', -1, 'E487') should_fail('history', 1000000, 'E474') + should_fail('regexpengine', -1, 'E474') should_fail('regexpengine', 3, 'E474') + should_succeed('regexpengine', 2) + should_fail('report', -1, 'E487') + should_succeed('report', 0) + should_fail('scrolloff', -1, 'E49') + should_fail('sidescrolloff', -1, 'E487') + should_fail('sidescroll', -1, 'E487') + should_fail('cmdwinheight', 0, 'E487') + should_fail('updatetime', -1, 'E487') should_fail('foldlevel', -5, 'E487') - should_fail('foldcolumn', 100, 'E474') + should_fail('foldcolumn', 13, 'E474') should_fail('conceallevel', 4, 'E474') - should_fail('numberwidth', 20, 'E474') + should_fail('numberwidth', 11, 'E474') + should_fail('numberwidth', 0, 'E487') + + -- If smaller than one this one is set to 'lines'-1 + should_succeed('window', -10) end) it('set wmh/wh wmw/wiw checks', function() |