From 21956adb6edc82a18cb8e9ea96bf177f54239f2d Mon Sep 17 00:00:00 2001 From: watiko Date: Sat, 28 Nov 2015 00:41:50 +0900 Subject: tests: Migrate legacy test autocmd_option. --- test/functional/legacy/autocmd_option_spec.lua | 144 +++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 test/functional/legacy/autocmd_option_spec.lua (limited to 'test') diff --git a/test/functional/legacy/autocmd_option_spec.lua b/test/functional/legacy/autocmd_option_spec.lua new file mode 100644 index 0000000000..146c82d29b --- /dev/null +++ b/test/functional/legacy/autocmd_option_spec.lua @@ -0,0 +1,144 @@ +-- Test for option autocommand + +local helpers = require('test.functional.helpers') +local feed, source = helpers.feed, helpers.source +local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect + +describe('autocmd_option', function() + setup(clear) + + it('is working', function() + execute('so small.vim') + + source([[ + fu! AutoCommand(match) + let c=g:testcase + let item=remove(g:options, 0) + let c.=printf("Expected: Name: <%s>, Oldval: <%s>, NewVal: <%s>, Scope: <%s>\n", + \item[0], item[1], item[2], item[3]) + let c.=printf("Autocmd Option: <%s>,", a:match) + let c.=printf(" OldVal: <%s>,", v:option_old) + let c.=printf(" NewVal: <%s>,", v:option_new) + let c.=printf(" Scope: <%s>\n", v:option_type) + call setreg('r', printf("%s\n%s", getreg('r'), c)) + endfu + ]]) + + execute('au OptionSet * :call AutoCommand(expand(""))') + + source([=[ + let g:testcase="1: Setting number option\n" + let g:options=[['number', 0, 1, 'global']] + set nu + let g:testcase="2: Setting local number option\n" + let g:options=[['number', 1, 0, 'local']] + setlocal nonu + let g:testcase="3: Setting global number option\n" + let g:options=[['number', 1, 0, 'global']] + setglobal nonu + let g:testcase="4: Setting local autoindent option\n" + let g:options=[['autoindent', 0, 1, 'local']] + setlocal ai + let g:testcase="5: Setting global autoindent option\n" + let g:options=[['autoindent', 0, 1, 'global']] + setglobal ai + let g:testcase="6: Setting global autoindent option\n" + let g:options=[['autoindent', 1, 0, 'global']] + set ai! + ]=]) + + -- Should not print anything, use :noa. + source([=[ + noa :set nonu + let g:testcase="7: Setting several global list and number option\n" + let g:options=[['list', 0, 1, 'global'], ['number', 0, 1, 'global']] + set list nu + noa set nolist nonu + let g:testcase="8: Setting global acd\n" + let g:options=[['autochdir', 0, 1, 'global']] + setlocal acd + let g:testcase="9: Setting global autoread\n" + let g:options=[['autoread', 1, 0, 'global']] + set noar + let g:testcase="10: Setting local autoread\n" + let g:options=[['autoread', 0, 1, 'local']] + setlocal ar + let g:testcase="11: Setting global autoread\n" + let g:options=[['autoread', 0, 1, 'global']] + setglobal invar + let g:testcase="12: Setting option backspace through :let\n" + let g:options=[['backspace', 'indent,eol,start', '', 'global']] + let &bs="" + let g:testcase="13: Setting option backspace through setbufvar()\n" + let g:options=[['backup', '', '1', 'local']] + ]=]) + + -- Try twice, first time, shouldn't trigger because option name is invalid, second time, it should trigger. + execute('call setbufvar(1, "&l:bk", 1)') + -- Should trigger, use correct option name. + execute('call setbufvar(1, "&backup", 1)') + -- Write register now + execute('$put! r') + + -- Remove the first and last blank lines. + feed('ggddGdd') + + -- Assert buffer contents. + expect([=[ + 1: Setting number option + Expected: Name: , Oldval: <0>, NewVal: <1>, Scope: + Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: + + 2: Setting local number option + Expected: Name: , Oldval: <1>, NewVal: <0>, Scope: + Autocmd Option: , OldVal: <1>, NewVal: <0>, Scope: + + 3: Setting global number option + Expected: Name: , Oldval: <1>, NewVal: <0>, Scope: + Autocmd Option: , OldVal: <1>, NewVal: <0>, Scope: + + 4: Setting local autoindent option + Expected: Name: , Oldval: <0>, NewVal: <1>, Scope: + Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: + + 5: Setting global autoindent option + Expected: Name: , Oldval: <0>, NewVal: <1>, Scope: + Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: + + 6: Setting global autoindent option + Expected: Name: , Oldval: <1>, NewVal: <0>, Scope: + Autocmd Option: , OldVal: <1>, NewVal: <0>, Scope: + + 7: Setting several global list and number option + Expected: Name: , Oldval: <0>, NewVal: <1>, Scope: + Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: + + 7: Setting several global list and number option + Expected: Name: , Oldval: <0>, NewVal: <1>, Scope: + Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: + + 8: Setting global acd + Expected: Name: , Oldval: <0>, NewVal: <1>, Scope: + Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: + + 9: Setting global autoread + Expected: Name: , Oldval: <1>, NewVal: <0>, Scope: + Autocmd Option: , OldVal: <1>, NewVal: <0>, Scope: + + 10: Setting local autoread + Expected: Name: , Oldval: <0>, NewVal: <1>, Scope: + Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: + + 11: Setting global autoread + Expected: Name: , Oldval: <0>, NewVal: <1>, Scope: + Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: + + 12: Setting option backspace through :let + Expected: Name: , Oldval: , NewVal: <>, Scope: + Autocmd Option: , OldVal: , NewVal: <>, Scope: + + 13: Setting option backspace through setbufvar() + Expected: Name: , Oldval: <>, NewVal: <1>, Scope: + Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: ]=]) + end) +end) -- cgit From d9c029382442ab9d6e50ca83aece0c2a2f9b817b Mon Sep 17 00:00:00 2001 From: watiko Date: Sat, 28 Nov 2015 17:06:23 +0900 Subject: tests: Improve legacy test autocmd_option. --- test/functional/legacy/autocmd_option_spec.lua | 260 ++++++++++++------------- 1 file changed, 122 insertions(+), 138 deletions(-) (limited to 'test') diff --git a/test/functional/legacy/autocmd_option_spec.lua b/test/functional/legacy/autocmd_option_spec.lua index 146c82d29b..dffddd2cfa 100644 --- a/test/functional/legacy/autocmd_option_spec.lua +++ b/test/functional/legacy/autocmd_option_spec.lua @@ -1,144 +1,128 @@ --- Test for option autocommand - local helpers = require('test.functional.helpers') -local feed, source = helpers.feed, helpers.source -local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect +local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq +local source, execute = helpers.source, helpers.execute -describe('autocmd_option', function() +describe('au OptionSet', function() setup(clear) - it('is working', function() - execute('so small.vim') - - source([[ - fu! AutoCommand(match) - let c=g:testcase - let item=remove(g:options, 0) - let c.=printf("Expected: Name: <%s>, Oldval: <%s>, NewVal: <%s>, Scope: <%s>\n", - \item[0], item[1], item[2], item[3]) - let c.=printf("Autocmd Option: <%s>,", a:match) - let c.=printf(" OldVal: <%s>,", v:option_old) - let c.=printf(" NewVal: <%s>,", v:option_new) - let c.=printf(" Scope: <%s>\n", v:option_type) - call setreg('r', printf("%s\n%s", getreg('r'), c)) - endfu - ]]) - - execute('au OptionSet * :call AutoCommand(expand(""))') - - source([=[ - let g:testcase="1: Setting number option\n" - let g:options=[['number', 0, 1, 'global']] - set nu - let g:testcase="2: Setting local number option\n" - let g:options=[['number', 1, 0, 'local']] - setlocal nonu - let g:testcase="3: Setting global number option\n" - let g:options=[['number', 1, 0, 'global']] - setglobal nonu - let g:testcase="4: Setting local autoindent option\n" - let g:options=[['autoindent', 0, 1, 'local']] - setlocal ai - let g:testcase="5: Setting global autoindent option\n" - let g:options=[['autoindent', 0, 1, 'global']] - setglobal ai - let g:testcase="6: Setting global autoindent option\n" - let g:options=[['autoindent', 1, 0, 'global']] - set ai! - ]=]) - - -- Should not print anything, use :noa. - source([=[ - noa :set nonu - let g:testcase="7: Setting several global list and number option\n" - let g:options=[['list', 0, 1, 'global'], ['number', 0, 1, 'global']] - set list nu - noa set nolist nonu - let g:testcase="8: Setting global acd\n" - let g:options=[['autochdir', 0, 1, 'global']] - setlocal acd - let g:testcase="9: Setting global autoread\n" - let g:options=[['autoread', 1, 0, 'global']] - set noar - let g:testcase="10: Setting local autoread\n" - let g:options=[['autoread', 0, 1, 'local']] - setlocal ar - let g:testcase="11: Setting global autoread\n" - let g:options=[['autoread', 0, 1, 'global']] - setglobal invar - let g:testcase="12: Setting option backspace through :let\n" - let g:options=[['backspace', 'indent,eol,start', '', 'global']] - let &bs="" - let g:testcase="13: Setting option backspace through setbufvar()\n" - let g:options=[['backup', '', '1', 'local']] - ]=]) - - -- Try twice, first time, shouldn't trigger because option name is invalid, second time, it should trigger. - execute('call setbufvar(1, "&l:bk", 1)') - -- Should trigger, use correct option name. - execute('call setbufvar(1, "&backup", 1)') - -- Write register now - execute('$put! r') - - -- Remove the first and last blank lines. - feed('ggddGdd') - - -- Assert buffer contents. - expect([=[ - 1: Setting number option - Expected: Name: , Oldval: <0>, NewVal: <1>, Scope: - Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: - - 2: Setting local number option - Expected: Name: , Oldval: <1>, NewVal: <0>, Scope: - Autocmd Option: , OldVal: <1>, NewVal: <0>, Scope: - - 3: Setting global number option - Expected: Name: , Oldval: <1>, NewVal: <0>, Scope: - Autocmd Option: , OldVal: <1>, NewVal: <0>, Scope: - - 4: Setting local autoindent option - Expected: Name: , Oldval: <0>, NewVal: <1>, Scope: - Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: - - 5: Setting global autoindent option - Expected: Name: , Oldval: <0>, NewVal: <1>, Scope: - Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: - - 6: Setting global autoindent option - Expected: Name: , Oldval: <1>, NewVal: <0>, Scope: - Autocmd Option: , OldVal: <1>, NewVal: <0>, Scope: - - 7: Setting several global list and number option - Expected: Name: , Oldval: <0>, NewVal: <1>, Scope: - Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: - - 7: Setting several global list and number option - Expected: Name: , Oldval: <0>, NewVal: <1>, Scope: - Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: - - 8: Setting global acd - Expected: Name: , Oldval: <0>, NewVal: <1>, Scope: - Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: - - 9: Setting global autoread - Expected: Name: , Oldval: <1>, NewVal: <0>, Scope: - Autocmd Option: , OldVal: <1>, NewVal: <0>, Scope: - - 10: Setting local autoread - Expected: Name: , Oldval: <0>, NewVal: <1>, Scope: - Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: - - 11: Setting global autoread - Expected: Name: , Oldval: <0>, NewVal: <1>, Scope: - Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: - - 12: Setting option backspace through :let - Expected: Name: , Oldval: , NewVal: <>, Scope: - Autocmd Option: , OldVal: , NewVal: <>, Scope: - - 13: Setting option backspace through setbufvar() - Expected: Name: , Oldval: <>, NewVal: <1>, Scope: - Autocmd Option: , OldVal: <0>, NewVal: <1>, Scope: ]=]) + describe('with * as ', function() + describe('matches when being set any option', function() + + local function expected_str(option, oldval, newval, scope) + return '' + .. string.format('Autocmd Option: <%s>,', option) + .. string.format(' OldVal: <%s>,', oldval) + .. string.format(' NewVal: <%s>,', newval) + .. string.format(' Scope: <%s>', scope) + end + + local function get_result() + return nvim('get_var', 'ret') + end + + local function expected_combination(option, oldval, newval, scope) + eq(expected_str(option, oldval, newval, scope), get_result()) + end + + local function expected_empty() + eq('', get_result()) + end + + setup(function() + + source([[ + fu! AutoCommand(match) + let g:ret.=printf('Autocmd Option: <%s>,', a:match) + let g:ret.=printf(' OldVal: <%s>,', v:option_old) + let g:ret.=printf(' NewVal: <%s>,', v:option_new) + let g:ret.=printf(' Scope: <%s>', v:option_type) + endfu + + au OptionSet * :call AutoCommand(expand("")) + ]]) + end) + + before_each(function() + execute([[let g:ret = '']]) + end) + + it('should set number option', function() + execute('set nu') + expected_combination('number', 0, 1, 'global') + end) + + it('should set local nonumber option',function() + execute('setlocal nonu') + expected_combination('number', 1, 0, 'local') + end) + + it('should set global nonumber option',function() + execute('setglobal nonu') + expected_combination('number', 1, 0, 'global') + end) + + it('should set local autoindent option',function() + execute('setlocal ai') + expected_combination('autoindent', 0, 1, 'local') + end) + + it('should set global autoindent option',function() + execute('setglobal ai') + expected_combination('autoindent', 0, 1, 'global') + end) + + it('should invert global autoindent option',function() + execute('set ai!') + expected_combination('autoindent', 1, 0, 'global') + end) + + it('should set several global list and number option',function() + execute('set list nu') + eq(expected_str('list', 0, 1, 'global') .. expected_str('number', 0, 1, 'global'), + get_result()) + end) + + it('should not print anything, use :noa.', function() + execute('noa set nolist nonu') + expected_empty() + end) + + it('should set global acd', function() + execute('setlocal acd') + expected_combination('autochdir', 0, 1, 'local') + end) + + it('should set global noautoread', function() + execute('set noar') + expected_combination('autoread', 1, 0, 'global') + end) + + it('should set local autoread', function() + execute('setlocal ar') + expected_combination('autoread', 0, 1, 'local') + end) + + it('should invert global autoread', function() + execute('setglobal invar') + expected_combination('autoread', 0, 1, 'global') + end) + + it('should set option backspace through :let', function() + execute('let &bs=""') + expected_combination('backspace', 'indent,eol,start', '', 'global') + end) + + describe('setting option through setbufvar()', function() + it('shouldn\'t trigger because option name is invalid', function() + execute('call setbufvar(1, "&l:bk", 1)') + expected_empty() + end) + + it('should trigger, use correct option name.', function() + execute('call setbufvar(1, "&backup", 1)') + expected_combination('backup', 0, 1, 'local') + end) + end) + end) end) end) -- cgit From 8c00c34b91b44115275dc8d1c10bab95ae62a7a9 Mon Sep 17 00:00:00 2001 From: watiko Date: Sat, 28 Nov 2015 20:09:56 +0900 Subject: tests: Keep each autocmd_option's test in isolation. --- test/functional/legacy/autocmd_option_spec.lua | 28 +++++++++----------------- 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'test') diff --git a/test/functional/legacy/autocmd_option_spec.lua b/test/functional/legacy/autocmd_option_spec.lua index dffddd2cfa..257a4ac5d4 100644 --- a/test/functional/legacy/autocmd_option_spec.lua +++ b/test/functional/legacy/autocmd_option_spec.lua @@ -3,11 +3,8 @@ local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq local source, execute = helpers.source, helpers.execute describe('au OptionSet', function() - setup(clear) - describe('with * as ', function() describe('matches when being set any option', function() - local function expected_str(option, oldval, newval, scope) return '' .. string.format('Autocmd Option: <%s>,', option) @@ -22,13 +19,15 @@ describe('au OptionSet', function() local function expected_combination(option, oldval, newval, scope) eq(expected_str(option, oldval, newval, scope), get_result()) + execute([[let g:ret = '']]) end local function expected_empty() eq('', get_result()) end - setup(function() + before_each(function() + clear() source([[ fu! AutoCommand(match) @@ -40,40 +39,35 @@ describe('au OptionSet', function() au OptionSet * :call AutoCommand(expand("")) ]]) - end) - before_each(function() execute([[let g:ret = '']]) end) it('should set number option', function() execute('set nu') expected_combination('number', 0, 1, 'global') - end) - it('should set local nonumber option',function() execute('setlocal nonu') expected_combination('number', 1, 0, 'local') - end) - it('should set global nonumber option',function() execute('setglobal nonu') expected_combination('number', 1, 0, 'global') end) - it('should set local autoindent option',function() + it('should set autoindent option',function() execute('setlocal ai') expected_combination('autoindent', 0, 1, 'local') - end) - it('should set global autoindent option',function() execute('setglobal ai') expected_combination('autoindent', 0, 1, 'global') + + execute('set noai') + expected_combination('autoindent', 1, 0, 'global') end) it('should invert global autoindent option',function() execute('set ai!') - expected_combination('autoindent', 1, 0, 'global') + expected_combination('autoindent', 0, 1, 'global') end) it('should set several global list and number option',function() @@ -92,19 +86,17 @@ describe('au OptionSet', function() expected_combination('autochdir', 0, 1, 'local') end) - it('should set global noautoread', function() + it('should set autoread', function() execute('set noar') expected_combination('autoread', 1, 0, 'global') - end) - it('should set local autoread', function() execute('setlocal ar') expected_combination('autoread', 0, 1, 'local') end) it('should invert global autoread', function() execute('setglobal invar') - expected_combination('autoread', 0, 1, 'global') + expected_combination('autoread', 1, 0, 'global') end) it('should set option backspace through :let', function() -- cgit From a3a8df835985f77e7bc8d0786c0e3851cfe3dc44 Mon Sep 17 00:00:00 2001 From: watiko Date: Tue, 1 Dec 2015 23:41:03 +0900 Subject: tests: Improve legacy autocmd_option. * Compare tables instead of strings * Add neovim specific test --- test/functional/legacy/autocmd_option_spec.lua | 323 ++++++++++++++++++------- 1 file changed, 240 insertions(+), 83 deletions(-) (limited to 'test') diff --git a/test/functional/legacy/autocmd_option_spec.lua b/test/functional/legacy/autocmd_option_spec.lua index 257a4ac5d4..855e9c6271 100644 --- a/test/functional/legacy/autocmd_option_spec.lua +++ b/test/functional/legacy/autocmd_option_spec.lua @@ -1,119 +1,276 @@ local helpers = require('test.functional.helpers') -local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq +local nvim = helpers.meths +local clear, eq, neq = helpers.clear, helpers.eq, helpers.neq +local curbuf, buf = helpers.curbuf, helpers.bufmeths local source, execute = helpers.source, helpers.execute -describe('au OptionSet', function() - describe('with * as ', function() - describe('matches when being set any option', function() - local function expected_str(option, oldval, newval, scope) - return '' - .. string.format('Autocmd Option: <%s>,', option) - .. string.format(' OldVal: <%s>,', oldval) - .. string.format(' NewVal: <%s>,', newval) - .. string.format(' Scope: <%s>', scope) - end +local function declare_hook_function() + source([[ + fu! AutoCommand(match, bufnr, winnr) + let l:acc = { + \ 'option' : a:match, + \ 'oldval' : v:option_old, + \ 'newval' : v:option_new, + \ 'scope' : v:option_type, + \ 'attr' : { + \ 'bufnr' : a:bufnr, + \ 'winnr' : a:winnr, + \ } + \ } + call add(g:ret, l:acc) + endfu + ]]) +end + +local function set_hook(pattern) + execute( + 'au OptionSet ' + .. pattern .. + ' :call AutoCommand(expand(""), bufnr("%"), winnr())' + ) +end - local function get_result() - return nvim('get_var', 'ret') - end +local function init_var() + execute('let g:ret = []') +end - local function expected_combination(option, oldval, newval, scope) - eq(expected_str(option, oldval, newval, scope), get_result()) - execute([[let g:ret = '']]) - end +local function get_result() + local ret = nvim.get_var('ret') + init_var() + return ret +end + +local function expected_table(option, oldval, newval, scope, attr) + return { + option = option, + oldval = tostring(oldval), + newval = tostring(newval), + scope = scope, + attr = attr, + } +end + +local function expected_combination(...) + local args = {...} + local ret = get_result() + + if not (#args == #ret) then + local expecteds = {} + for _, v in pairs(args) do + table.insert(expecteds, expected_table(unpack(v))) + end + eq(expecteds, ret) + return + end - local function expected_empty() - eq('', get_result()) + for i, v in ipairs(args) do + local attr = v[5] + if not attr then + -- remove attr entries + ret[i].attr = nil + else + -- remove attr entries which are not required + for k in pairs(ret[i].attr) do + if not attr[k] then + ret[i].attr[k] = nil + end end + end + eq(expected_table(unpack(v)), ret[i]) + end +end - before_each(function() - clear() - - source([[ - fu! AutoCommand(match) - let g:ret.=printf('Autocmd Option: <%s>,', a:match) - let g:ret.=printf(' OldVal: <%s>,', v:option_old) - let g:ret.=printf(' NewVal: <%s>,', v:option_new) - let g:ret.=printf(' Scope: <%s>', v:option_type) - endfu - - au OptionSet * :call AutoCommand(expand("")) - ]]) - - execute([[let g:ret = '']]) - end) +local function expected_empty() + eq({}, get_result()) +end - it('should set number option', function() - execute('set nu') - expected_combination('number', 0, 1, 'global') +local function make_buffer() + local old_buf = curbuf() + execute('new') + local new_buf = curbuf() + execute('wincmd p') -- move previous window - execute('setlocal nonu') - expected_combination('number', 1, 0, 'local') + neq(old_buf, new_buf) + eq(old_buf, curbuf()) - execute('setglobal nonu') - expected_combination('number', 1, 0, 'global') - end) + return new_buf +end + +describe('au OptionSet', function() + describe('with any opton (*)', function() + + before_each(function() + clear() + declare_hook_function() + init_var() + set_hook('*') + end) + + it('should be called in setting number option', function() + execute('set nu') + expected_combination({'number', 0, 1, 'global'}) + + execute('setlocal nonu') + expected_combination({'number', 1, 0, 'local'}) + + execute('setglobal nonu') + expected_combination({'number', 1, 0, 'global'}) + end) + + it('should be called in setting autoindent option',function() + execute('setlocal ai') + expected_combination({'autoindent', 0, 1, 'local'}) + + execute('setglobal ai') + expected_combination({'autoindent', 0, 1, 'global'}) + + execute('set noai') + expected_combination({'autoindent', 1, 0, 'global'}) + end) + + it('should be called in inverting global autoindent option',function() + execute('set ai!') + expected_combination({'autoindent', 0, 1, 'global'}) + end) + + it('should be called in being unset local autoindent option',function() + execute('setlocal ai') + expected_combination({'autoindent', 0, 1, 'local'}) + + execute('setlocal ai<') + expected_combination({'autoindent', 1, 0, 'local'}) + end) + + it('should be called in setting global list and number option at the same time',function() + execute('set list nu') + expected_combination( + {'list', 0, 1, 'global'}, + {'number', 0, 1, 'global'} + ) + end) - it('should set autoindent option',function() - execute('setlocal ai') - expected_combination('autoindent', 0, 1, 'local') + it('should not print anything, use :noa', function() + execute('noa set nolist nonu') + expected_empty() + end) + + it('should be called in setting local acd', function() + execute('setlocal acd') + expected_combination({'autochdir', 0, 1, 'local'}) + end) + + it('should be called in setting autoread', function() + execute('set noar') + expected_combination({'autoread', 1, 0, 'global'}) + + execute('setlocal ar') + expected_combination({'autoread', 0, 1, 'local'}) + end) + + it('should be called in inverting global autoread', function() + execute('setglobal invar') + expected_combination({'autoread', 1, 0, 'global'}) + end) - execute('setglobal ai') - expected_combination('autoindent', 0, 1, 'global') + it('should be called in setting backspace option through :let', function() + execute('let &bs=""') + expected_combination({'backspace', 'indent,eol,start', '', 'global'}) + end) - execute('set noai') - expected_combination('autoindent', 1, 0, 'global') + describe('being set by setbufvar()', function() + it('should not trigger because option name is invalid', function() + execute('call setbufvar(1, "&l:bk", 1)') + expected_empty() end) - it('should invert global autoindent option',function() - execute('set ai!') - expected_combination('autoindent', 0, 1, 'global') + it('should trigger using correct option name', function() + execute('call setbufvar(1, "&backup", 1)') + expected_combination({'backup', 0, 1, 'local'}) end) - it('should set several global list and number option',function() - execute('set list nu') - eq(expected_str('list', 0, 1, 'global') .. expected_str('number', 0, 1, 'global'), - get_result()) + it('should trigger if the current buffer is different from the targetted buffer', function() + local new_buffer = make_buffer() + local new_bufnr = buf.get_number(new_buffer) + + execute('call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")') + expected_combination({'buftype', '', 'nofile', 'local', {bufnr = new_bufnr}}) end) + end) + end) + + describe('with specific option', function() - it('should not print anything, use :noa.', function() - execute('noa set nolist nonu') + before_each(function() + clear() + declare_hook_function() + init_var() + end) + + it('should be called iff setting readonly', function() + set_hook('readonly') + + execute('set nu') + expected_empty() + + execute('setlocal ro') + expected_combination({'readonly', 0, 1, 'local'}) + + execute('setglobal ro') + expected_combination({'readonly', 0, 1, 'global'}) + + execute('set noro') + expected_combination({'readonly', 1, 0, 'global'}) + end) + + describe('being set by setbufvar()', function() + it('should not trigger because option name does not match with backup', function() + set_hook('backup') + + execute('call setbufvar(1, "&l:bk", 1)') expected_empty() end) - it('should set global acd', function() - execute('setlocal acd') - expected_combination('autochdir', 0, 1, 'local') + it('should trigger, use correct option name backup', function() + set_hook('backup') + + execute('call setbufvar(1, "&backup", 1)') + expected_combination({'backup', 0, 1, 'local'}) end) - it('should set autoread', function() - execute('set noar') - expected_combination('autoread', 1, 0, 'global') + it('should trigger if the current buffer is different from the targetted buffer', function() + set_hook('buftype') + + local new_buffer = make_buffer() + local new_bufnr = buf.get_number(new_buffer) - execute('setlocal ar') - expected_combination('autoread', 0, 1, 'local') + execute('call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")') + expected_combination({'buftype', '', 'nofile', 'local', {bufnr = new_bufnr}}) end) + end) + + describe('being set by neovim api', function() + it('should trigger if a boolean option be set globally', function() + set_hook('autochdir') - it('should invert global autoread', function() - execute('setglobal invar') - expected_combination('autoread', 1, 0, 'global') + nvim.set_option('autochdir', true) + eq(true, nvim.get_option('autochdir')) + expected_combination({'autochdir', '0', '1', 'global'}) end) - it('should set option backspace through :let', function() - execute('let &bs=""') - expected_combination('backspace', 'indent,eol,start', '', 'global') + it('should trigger if a number option be set globally', function() + set_hook('cmdheight') + + nvim.set_option('cmdheight', 5) + eq(5, nvim.get_option('cmdheight')) + expected_combination({'cmdheight', 1, 5, 'global'}) end) - describe('setting option through setbufvar()', function() - it('shouldn\'t trigger because option name is invalid', function() - execute('call setbufvar(1, "&l:bk", 1)') - expected_empty() - end) + it('should trigger if a string option be set globally', function() + set_hook('ambiwidth') - it('should trigger, use correct option name.', function() - execute('call setbufvar(1, "&backup", 1)') - expected_combination('backup', 0, 1, 'local') - end) + nvim.set_option('ambiwidth', 'double') + eq('double', nvim.get_option('ambiwidth')) + expected_combination({'ambiwidth', 'single', 'double', 'global'}) end) end) end) -- cgit