diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/helpers.lua | 5 | ||||
-rw-r--r-- | test/functional/legacy/100_lispwords_spec.lua | 47 | ||||
-rw-r--r-- | test/functional/legacy/100_undo_level_spec.lua | 142 | ||||
-rw-r--r-- | test/functional/legacy/assert_spec.lua | 145 | ||||
-rw-r--r-- | test/functional/legacy/undolevels_spec.lua | 58 |
5 files changed, 255 insertions, 142 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 50fa3fb1bd..1fba15c2c3 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -1,4 +1,5 @@ require('coxpcall') +local ffi = require('ffi') local lfs = require('lfs') local assert = require('luassert') local Loop = require('nvim.loop') @@ -246,9 +247,13 @@ end local function source(code) local tmpname = os.tmpname() + if ffi.os == 'OSX' and string.match(tmpname, '^/tmp') then + tmpname = '/private'..tmpname + end write_file(tmpname, code) nvim_command('source '..tmpname) os.remove(tmpname) + return tmpname end local function eq(expected, actual) diff --git a/test/functional/legacy/100_lispwords_spec.lua b/test/functional/legacy/100_lispwords_spec.lua new file mode 100644 index 0000000000..739a02f0b3 --- /dev/null +++ b/test/functional/legacy/100_lispwords_spec.lua @@ -0,0 +1,47 @@ +-- Tests for 'lispwords' setting being global-local + +local helpers = require('test.functional.helpers') +local source = helpers.source +local clear, expect = helpers.clear, helpers.expect + +describe('lispwords', function() + setup(clear) + + it('global-local', function() + source([[ + setglobal lispwords=foo,bar,baz + setlocal lispwords-=foo + setlocal lispwords+=quux + redir @A + echo "Testing 'lispwords' local value" + setglobal lispwords? + setlocal lispwords? + echo &lispwords + echo '' + redir end + setlocal lispwords< + redir @A + echo "Testing 'lispwords' value reset" + setglobal lispwords? + setlocal lispwords? + echo &lispwords + redir end + + 0put a + $d + ]]) + + -- Assert buffer contents. + expect([[ + + Testing 'lispwords' local value + lispwords=foo,bar,baz + lispwords=bar,baz,quux + bar,baz,quux + + Testing 'lispwords' value reset + lispwords=foo,bar,baz + lispwords=foo,bar,baz + foo,bar,baz]]) + end) +end) diff --git a/test/functional/legacy/100_undo_level_spec.lua b/test/functional/legacy/100_undo_level_spec.lua deleted file mode 100644 index 3bf72341d6..0000000000 --- a/test/functional/legacy/100_undo_level_spec.lua +++ /dev/null @@ -1,142 +0,0 @@ --- Tests for 'undolevel' setting being global-local - -local helpers = require('test.functional.helpers') -local source = helpers.source -local clear, expect = helpers.clear, helpers.expect - -describe('undolevel', function() - setup(clear) - - it('is working', function() - source([[ - set ul=5 - fu! FillBuffer() - for i in range(1,13) - put=i - exe "setg ul=" . &g:ul - endfor - endfu - fu! UndoLevel() - redir @z - setglobal undolevels? - echon ' global' - setlocal undolevels? - echon ' local' - redir end - $put z - endfu - - 0put ='ONE: expecting global undolevels: 5, local undolevels: -123456 (default)' - call FillBuffer() - setlocal undolevels< - earlier 10 - call UndoLevel() - set ff=unix - %yank A - %delete - - 0put ='TWO: expecting global undolevels: 5, local undolevels: 2 (first) then 10 (afterwards)' - setlocal ul=2 - call FillBuffer() - earlier 10 - call UndoLevel() - setlocal ul=10 - call UndoLevel() - set ff=unix - %yank A - %delete - setlocal undolevels< - redir @A - echo "global value shouldn't be changed and still be 5!" - echo 'ONE: expecting global undolevels: 5, local undolevels: -123456 (default)' - setglobal undolevels? - echon ' global' - setlocal undolevels? - echon ' local' - echo "" - redir end - - setglobal ul=50 - 1put ='global value should be changed to 50' - 2put ='THREE: expecting global undolevels: 50, local undolevels: -123456 (default)' - call UndoLevel() - set ff=unix - %yank A - %delete - setglobal lispwords=foo,bar,baz - setlocal lispwords-=foo - setlocal lispwords+=quux - redir @A - echo "Testing 'lispwords' local value" - setglobal lispwords? - setlocal lispwords? - echo &lispwords - echo '' - redir end - setlocal lispwords< - redir @A - echo "Testing 'lispwords' value reset" - setglobal lispwords? - setlocal lispwords? - echo &lispwords - redir end - - 0put a - $d - ]]) - - -- Assert buffer contents. - expect([[ - ONE: expecting global undolevels: 5, local undolevels: -123456 (default) - 1 - 2 - 3 - 4 - 5 - 6 - 7 - - - undolevels=5 global - undolevels=-123456 local - TWO: expecting global undolevels: 5, local undolevels: 2 (first) then 10 (afterwards) - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - - - undolevels=5 global - undolevels=2 local - - undolevels=5 global - undolevels=10 local - - global value shouldn't be changed and still be 5! - ONE: expecting global undolevels: 5, local undolevels: -123456 (default) - undolevels=5 global - undolevels=-123456 local - - global value should be changed to 50 - THREE: expecting global undolevels: 50, local undolevels: -123456 (default) - - undolevels=50 global - undolevels=-123456 local - - Testing 'lispwords' local value - lispwords=foo,bar,baz - lispwords=bar,baz,quux - bar,baz,quux - - Testing 'lispwords' value reset - lispwords=foo,bar,baz - lispwords=foo,bar,baz - foo,bar,baz]]) - end) -end) diff --git a/test/functional/legacy/assert_spec.lua b/test/functional/legacy/assert_spec.lua new file mode 100644 index 0000000000..1ce665360d --- /dev/null +++ b/test/functional/legacy/assert_spec.lua @@ -0,0 +1,145 @@ +local helpers = require('test.functional.helpers') +local nvim, call = helpers.meths, helpers.call +local clear, eq = helpers.clear, helpers.eq +local source, execute = helpers.source, helpers.execute + +local function expected_errors(errors) + eq(errors, nvim.get_vvar('errors')) +end + +local function expected_empty() + eq({}, nvim.get_vvar('errors')) +end + +describe('assert function:', function() + + before_each(function() + clear() + end) + + -- assert_equal({expected}, {actual}, [, {msg}]) + describe('assert_equal', function() + it('should not change v:errors when expected is equal to actual', function() + source([[ + let s = 'foo' + call assert_equal('foo', s) + let n = 4 + call assert_equal(4, n) + let l = [1, 2, 3] + call assert_equal([1, 2, 3], l) + fu Func() + endfu + let F1 = function('Func') + let F2 = function('Func') + call assert_equal(F1, F2) + ]]) + expected_empty() + end) + + it('should not change v:errors when expected is equal to actual', function() + call('assert_equal', '', '') + call('assert_equal', 'string', 'string') + expected_empty() + end) + + it('should change v:errors when expected is not equal to actual', function() + call('assert_equal', 0, {0}) + expected_errors({'Expected 0 but got [0]'}) + end) + + it('should change v:errors when expected is not equal to actual', function() + call('assert_equal', 0, "0") + expected_errors({"Expected 0 but got '0'"}) + end) + + it('should change v:errors when expected is not equal to actual', function() + -- Lua does not tell integer from float. + execute('call assert_equal(1, 1.0)') + expected_errors({'Expected 1 but got 1.0'}) + end) + + it('should change v:errors when expected is not equal to actual', function() + call('assert_equal', 'true', 'false') + expected_errors({"Expected 'true' but got 'false'"}) + end) + end) + + -- assert_false({actual}, [, {msg}]) + describe('assert_false', function() + it('should not change v:errors when actual is false', function() + call('assert_false', 0) + call('assert_false', false) + expected_empty() + end) + + it('should change v:errors when actual is not false', function() + call('assert_false', 1) + expected_errors({'Expected False but got 1'}) + end) + + it('should change v:errors when actual is not false', function() + call('assert_false', {}) + expected_errors({'Expected False but got []'}) + end) + end) + + -- assert_true({actual}, [, {msg}]) + describe('assert_true', function() + it('should not change v:errors when actual is true', function() + call('assert_true', 1) + call('assert_true', -1) -- In Vim script, non-zero Numbers are TRUE. + call('assert_true', true) + expected_empty() + end) + + it('should change v:errors when actual is not true', function() + call('assert_true', 1.5) + expected_errors({'Expected True but got 1.5'}) + end) + end) + + describe('v:errors', function() + it('should be initialized at startup', function() + expected_empty() + end) + + it('should have function names and relative line numbers', function() + source([[ + fu Func_one() + call assert_equal([0], {'0' : 0}) + call assert_false('False') + call assert_true("True") + endfu + fu Func_two() + " for shifting a line number + call assert_true('line two') + endfu + ]]) + call('Func_one') + call('Func_two') + expected_errors({ + "function Func_one line 1: Expected [0] but got {'0': 0}", + "function Func_one line 2: Expected False but got 'False'", + "function Func_one line 3: Expected True but got 'True'", + "function Func_two line 2: Expected True but got 'line two'", + }) + end) + + it('should have file names and passed messages', function() + local tmpname_one = source([[ + call assert_equal(1, 100, 'equal assertion failed') + call assert_false('true', 'true assertion failed') + call assert_true('false', 'false assertion failed') + ]]) + local tmpname_two = source([[ + call assert_true('', 'file two') + ]]) + expected_errors({ + tmpname_one .. " line 1: 'equal assertion failed'", + tmpname_one .. " line 2: 'true assertion failed'", + tmpname_one .. " line 3: 'false assertion failed'", + tmpname_two .. " line 1: 'file two'", + }) + end) + end) +end) diff --git a/test/functional/legacy/undolevels_spec.lua b/test/functional/legacy/undolevels_spec.lua new file mode 100644 index 0000000000..41274b3a04 --- /dev/null +++ b/test/functional/legacy/undolevels_spec.lua @@ -0,0 +1,58 @@ +local helpers = require('test.functional.helpers') +local source, clear = helpers.source, helpers.clear +local eq, nvim = helpers.eq, helpers.meths + +describe('undolevel', function() + setup(clear) + + it('is working', function() + source([[ + func FillBuffer() + for i in range(1,13) + put=i + " Set 'undolevels' to split undo. + exe "setg ul=" . &g:ul + endfor + endfunc + + func Test_global_local_undolevels() + new one + set undolevels=5 + call FillBuffer() + " will only undo the last 5 changes, end up with 13 - (5 + 1) = 7 lines + earlier 10 + call assert_equal(5, &g:undolevels) + call assert_equal(-123456, &l:undolevels) + call assert_equal('7', getline('$')) + + new two + setlocal undolevels=2 + call FillBuffer() + " will only undo the last 2 changes, end up with 13 - (2 + 1) = 10 lines + earlier 10 + call assert_equal(5, &g:undolevels) + call assert_equal(2, &l:undolevels) + call assert_equal('10', getline('$')) + + setlocal ul=10 + call assert_equal(5, &g:undolevels) + call assert_equal(10, &l:undolevels) + + " Setting local value in "two" must not change local value in "one" + wincmd p + call assert_equal(5, &g:undolevels) + call assert_equal(-123456, &l:undolevels) + + new three + setglobal ul=50 + call assert_equal(50, &g:undolevels) + call assert_equal(-123456, &l:undolevels) + + endfunc + + call Test_global_local_undolevels() + ]]) + + eq({}, nvim.get_vvar('errors')) + end) +end) |