From 803baf36317ff73162f1141f368bb4bb6739cdb4 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 2 Jun 2018 12:06:57 -0400 Subject: vim-patch:8.0.0261: not enough test coverage for eval functions Problem: Not enough test coverage for eval functions. Solution: Add more tests. (Dominique Pelle, closes vim/vim#1420) https://github.com/vim/vim/commit/24c2e48ef8b8b9053fa18039e6f6118337f908f8 --- src/nvim/testdir/test_functions.vim | 146 +++++++++++++++++++++++++++++++++++- 1 file changed, 145 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 398e9ab331..9323a7969f 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1,5 +1,78 @@ " Tests for various functions. +func Test_empty() + call assert_equal(1, empty('')) + call assert_equal(0, empty('a')) + + call assert_equal(1, empty(0)) + call assert_equal(1, empty(-0)) + call assert_equal(0, empty(1)) + call assert_equal(0, empty(-1)) + + call assert_equal(1, empty(0.0)) + call assert_equal(1, empty(-0.0)) + call assert_equal(0, empty(1.0)) + call assert_equal(0, empty(-1.0)) + call assert_equal(0, empty(1.0/0.0)) + call assert_equal(0, empty(0.0/0.0)) + + call assert_equal(1, empty([])) + call assert_equal(0, empty(['a'])) + + call assert_equal(1, empty({})) + call assert_equal(0, empty({'a':1})) + + call assert_equal(1, empty(v:null)) + call assert_equal(1, empty(v:none)) + call assert_equal(1, empty(v:false)) + call assert_equal(0, empty(v:true)) + + call assert_equal(0, empty(function('Test_empty'))) +endfunc + +func Test_len() + call assert_equal(1, len(0)) + call assert_equal(2, len(12)) + + call assert_equal(0, len('')) + call assert_equal(2, len('ab')) + + call assert_equal(0, len([])) + call assert_equal(2, len([2, 1])) + + call assert_equal(0, len({})) + call assert_equal(2, len({'a': 1, 'b': 2})) + + call assert_fails('call len(v:none)', 'E701:') + call assert_fails('call len({-> 0})', 'E701:') +endfunc + +func Test_max() + call assert_equal(0, max([])) + call assert_equal(2, max([2])) + call assert_equal(2, max([1, 2])) + call assert_equal(2, max([1, 2, v:null])) + + call assert_equal(0, max({})) + call assert_equal(2, max({'a':1, 'b':2})) + + call assert_fails('call max(1)', 'E712:') + call assert_fails('call max(v:none)', 'E712:') +endfunc + +func Test_min() + call assert_equal(0, min([])) + call assert_equal(2, min([2])) + call assert_equal(1, min([1, 2])) + call assert_equal(0, min([1, 2, v:null])) + + call assert_equal(0, min({})) + call assert_equal(1, min({'a':1, 'b':2})) + + call assert_fails('call min(1)', 'E712:') + call assert_fails('call min(v:none)', 'E712:') +endfunc + func Test_str2nr() call assert_equal(0, str2nr('')) call assert_equal(1, str2nr('1')) @@ -15,6 +88,77 @@ func Test_str2nr() call assert_equal(123456789, str2nr('123456789')) call assert_equal(-123456789, str2nr('-123456789')) + + call assert_equal(5, str2nr('101', 2)) + call assert_equal(5, str2nr('0b101', 2)) + call assert_equal(5, str2nr('0B101', 2)) + call assert_equal(-5, str2nr('-101', 2)) + call assert_equal(-5, str2nr('-0b101', 2)) + call assert_equal(-5, str2nr('-0B101', 2)) + + call assert_equal(65, str2nr('101', 8)) + call assert_equal(65, str2nr('0101', 8)) + call assert_equal(-65, str2nr('-101', 8)) + call assert_equal(-65, str2nr('-0101', 8)) + + call assert_equal(11259375, str2nr('abcdef', 16)) + call assert_equal(11259375, str2nr('ABCDEF', 16)) + call assert_equal(-11259375, str2nr('-ABCDEF', 16)) + call assert_equal(11259375, str2nr('0xabcdef', 16)) + call assert_equal(11259375, str2nr('0Xabcdef', 16)) + call assert_equal(11259375, str2nr('0XABCDEF', 16)) + call assert_equal(-11259375, str2nr('-0xABCDEF', 16)) + + call assert_equal(0, str2nr('0x10')) + call assert_equal(0, str2nr('0b10')) + call assert_equal(1, str2nr('12', 2)) + call assert_equal(1, str2nr('18', 8)) + call assert_equal(1, str2nr('1g', 16)) + + call assert_equal(0, str2nr(v:null)) + call assert_equal(0, str2nr(v:none)) + + call assert_fails('call str2nr([])', 'E730:') + call assert_fails('call str2nr({->2})', 'E729:') + call assert_fails('call str2nr(1.2)', 'E806:') + call assert_fails('call str2nr(10, [])', 'E474:') +endfunc + +func Test_strftime() + if !exists('*strftime') + return + endif + " Format of strftime() depends on system. We assume + " that basic formats tested here are available and + " identical on all systems which support strftime(). + " + " The 2nd parameter of strftime() is a local time, so the output day + " of strftime() can be 17 or 18, depending on timezone. + call assert_match('^2017-01-1[78]$', strftime('%Y-%m-%d', 1484695512)) + " + call assert_match('^\d\d\d\d-\(0\d\|1[012]\)-\([012]\d\|3[01]\) \([01]\d\|2[0-3]\):[0-5]\d:\([0-5]\d\|60\)$', strftime('%Y-%m-%d %H:%M:%S')) + + call assert_fails('call strftime([])', 'E730:') + call assert_fails('call strftime("%Y", [])', 'E745:') +endfunc + +func Test_simplify() + call assert_equal('', simplify('')) + call assert_equal('/', simplify('/')) + call assert_equal('/', simplify('/.')) + call assert_equal('/', simplify('/..')) + call assert_equal('/...', simplify('/...')) + call assert_equal('./dir/file', simplify('./dir/file')) + call assert_equal('./dir/file', simplify('.///dir//file')) + call assert_equal('./dir/file', simplify('./dir/./file')) + call assert_equal('./file', simplify('./dir/../file')) + call assert_equal('../dir/file', simplify('dir/../../dir/file')) + call assert_equal('./file', simplify('dir/.././file')) + + call assert_fails('call simplify({->0})', 'E729:') + call assert_fails('call simplify([])', 'E730:') + call assert_fails('call simplify({})', 'E731:') + call assert_fails('call simplify(1.2)', 'E806:') endfunc func Test_setbufvar_options() @@ -188,7 +332,7 @@ func Test_toupper() call assert_equal("YÝŶŸẎỲỶỸ", toupper("YÝŶŸẎỲỶỸ")) call assert_equal("ZŹŻŽƵẐẔ", toupper("ZŹŻŽƵẐẔ")) - call assert_equal("ⱥ ⱦ", tolower("Ⱥ Ⱦ")) + call assert_equal("Ⱥ Ⱦ", toupper("ⱥ ⱦ")) endfunc " Tests for the mode() function -- cgit From 1ef585d6dc530dfc9058ac49c980439d3a2c6a19 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 2 Jun 2018 12:10:22 -0400 Subject: vim-patch:8.0.0435: some functions are not tested Problem: Some functions are not tested. Solution: Add more tests for functions. (Dominique Pelle, closes vim/vim#1541) https://github.com/vim/vim/commit/41042f3cfdb91f946e553456278a995e61dd8578 --- src/nvim/testdir/test_functions.vim | 248 ++++++++++++++++++++++++++++++++++++ 1 file changed, 248 insertions(+) (limited to 'src') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 9323a7969f..d34d4596d2 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -27,6 +27,13 @@ func Test_empty() call assert_equal(1, empty(v:false)) call assert_equal(0, empty(v:true)) + if has('channel') + call assert_equal(1, empty(test_null_channel())) + endif + if has('job') + call assert_equal(1, empty(test_null_job())) + endif + call assert_equal(0, empty(function('Test_empty'))) endfunc @@ -497,3 +504,244 @@ func Test_getbufvar() set fileformats& endfunc + +func Test_bufexists() + call assert_equal(0, bufexists('does_not_exist')) + call assert_equal(1, bufexists(bufnr('%'))) + call assert_equal(0, bufexists(0)) + new Xfoo + let bn = bufnr('%') + call assert_equal(1, bufexists(bn)) + call assert_equal(1, bufexists('Xfoo')) + call assert_equal(1, bufexists(getcwd() . '/Xfoo')) + call assert_equal(1, bufexists(0)) + bw + call assert_equal(0, bufexists(bn)) + call assert_equal(0, bufexists('Xfoo')) +endfunc + +func Test_last_buffer_nr() + call assert_equal(bufnr('$'), last_buffer_nr()) +endfunc + +func Test_stridx() + call assert_equal(-1, stridx('', 'l')) + call assert_equal(0, stridx('', '')) + call assert_equal(0, stridx('hello', '')) + call assert_equal(-1, stridx('hello', 'L')) + call assert_equal(2, stridx('hello', 'l', -1)) + call assert_equal(2, stridx('hello', 'l', 0)) + call assert_equal(2, stridx('hello', 'l', 1)) + call assert_equal(3, stridx('hello', 'l', 3)) + call assert_equal(-1, stridx('hello', 'l', 4)) + call assert_equal(-1, stridx('hello', 'l', 10)) + call assert_equal(2, stridx('hello', 'll')) + call assert_equal(-1, stridx('hello', 'hello world')) +endfunc + +func Test_strridx() + call assert_equal(-1, strridx('', 'l')) + call assert_equal(0, strridx('', '')) + call assert_equal(5, strridx('hello', '')) + call assert_equal(-1, strridx('hello', 'L')) + call assert_equal(3, strridx('hello', 'l')) + call assert_equal(3, strridx('hello', 'l', 10)) + call assert_equal(3, strridx('hello', 'l', 3)) + call assert_equal(2, strridx('hello', 'l', 2)) + call assert_equal(-1, strridx('hello', 'l', 1)) + call assert_equal(-1, strridx('hello', 'l', 0)) + call assert_equal(-1, strridx('hello', 'l', -1)) + call assert_equal(2, strridx('hello', 'll')) + call assert_equal(-1, strridx('hello', 'hello world')) +endfunc + +func Test_matchend() + call assert_equal(7, matchend('testing', 'ing')) + call assert_equal(7, matchend('testing', 'ing', 2)) + call assert_equal(-1, matchend('testing', 'ing', 5)) +endfunc + +func Test_nextnonblank_prevnonblank() + new +insert +This + + +is + +a +Test +. + call assert_equal(0, nextnonblank(-1)) + call assert_equal(0, nextnonblank(0)) + call assert_equal(1, nextnonblank(1)) + call assert_equal(4, nextnonblank(2)) + call assert_equal(4, nextnonblank(3)) + call assert_equal(4, nextnonblank(4)) + call assert_equal(6, nextnonblank(5)) + call assert_equal(6, nextnonblank(6)) + call assert_equal(7, nextnonblank(7)) + call assert_equal(0, nextnonblank(8)) + + call assert_equal(0, prevnonblank(-1)) + call assert_equal(0, prevnonblank(0)) + call assert_equal(1, prevnonblank(1)) + call assert_equal(1, prevnonblank(2)) + call assert_equal(1, prevnonblank(3)) + call assert_equal(4, prevnonblank(4)) + call assert_equal(4, prevnonblank(5)) + call assert_equal(6, prevnonblank(6)) + call assert_equal(7, prevnonblank(7)) + call assert_equal(0, prevnonblank(8)) + bw! +endfunc + +func Test_byte2line_line2byte() + new + call setline(1, ['a', 'bc', 'd']) + + set fileformat=unix + call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1], + \ map(range(-1, 8), 'byte2line(v:val)')) + call assert_equal([-1, -1, 1, 3, 6, 8, -1], + \ map(range(-1, 5), 'line2byte(v:val)')) + + set fileformat=mac + call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1], + \ map(range(-1, 8), 'byte2line(v:val)')) + call assert_equal([-1, -1, 1, 3, 6, 8, -1], + \ map(range(-1, 5), 'line2byte(v:val)')) + + set fileformat=dos + call assert_equal([-1, -1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, -1], + \ map(range(-1, 11), 'byte2line(v:val)')) + call assert_equal([-1, -1, 1, 4, 8, 11, -1], + \ map(range(-1, 5), 'line2byte(v:val)')) + + set fileformat& + bw! +endfunc + +func Test_count() + let l = ['a', 'a', 'A', 'b'] + call assert_equal(2, count(l, 'a')) + call assert_equal(1, count(l, 'A')) + call assert_equal(1, count(l, 'b')) + call assert_equal(0, count(l, 'B')) + + call assert_equal(2, count(l, 'a', 0)) + call assert_equal(1, count(l, 'A', 0)) + call assert_equal(1, count(l, 'b', 0)) + call assert_equal(0, count(l, 'B', 0)) + + call assert_equal(3, count(l, 'a', 1)) + call assert_equal(3, count(l, 'A', 1)) + call assert_equal(1, count(l, 'b', 1)) + call assert_equal(1, count(l, 'B', 1)) + call assert_equal(0, count(l, 'c', 1)) + + call assert_equal(1, count(l, 'a', 0, 1)) + call assert_equal(2, count(l, 'a', 1, 1)) + call assert_fails('call count(l, "a", 0, 10)', 'E684:') + + let d = {1: 'a', 2: 'a', 3: 'A', 4: 'b'} + call assert_equal(2, count(d, 'a')) + call assert_equal(1, count(d, 'A')) + call assert_equal(1, count(d, 'b')) + call assert_equal(0, count(d, 'B')) + + call assert_equal(2, count(d, 'a', 0)) + call assert_equal(1, count(d, 'A', 0)) + call assert_equal(1, count(d, 'b', 0)) + call assert_equal(0, count(d, 'B', 0)) + + call assert_equal(3, count(d, 'a', 1)) + call assert_equal(3, count(d, 'A', 1)) + call assert_equal(1, count(d, 'b', 1)) + call assert_equal(1, count(d, 'B', 1)) + call assert_equal(0, count(d, 'c', 1)) + + call assert_fails('call count(d, "a", 0, 1)', 'E474:') + call assert_fails('call count("a", "a")', 'E712:') +endfunc + +func Test_changenr() + new Xchangenr + call assert_equal(0, changenr()) + norm ifoo + call assert_equal(1, changenr()) + set undolevels=10 + norm Sbar + call assert_equal(2, changenr()) + undo + call assert_equal(1, changenr()) + redo + call assert_equal(2, changenr()) + bw! + set undolevels& +endfunc + +func Test_filewritable() + new Xfilewritable + write! + call assert_equal(1, filewritable('Xfilewritable')) + + call assert_notequal(0, setfperm('Xfilewritable', 'r--r-----')) + call assert_equal(0, filewritable('Xfilewritable')) + + call assert_notequal(0, setfperm('Xfilewritable', 'rw-r-----')) + call assert_equal(1, filewritable('Xfilewritable')) + + call assert_equal(0, filewritable('doesnotexist')) + + call delete('Xfilewritable') + bw! +endfunc + +func Test_hostname() + let hostname_vim = hostname() + if has('unix') + let hostname_system = systemlist('uname -n')[0] + call assert_equal(hostname_vim, hostname_system) + endif +endfunc + +func Test_getpid() + " getpid() always returns the same value within a vim instance. + call assert_equal(getpid(), getpid()) + if has('unix') + call assert_equal(systemlist('echo $PPID')[0], string(getpid())) + endif +endfunc + +func Test_hlexists() + call assert_equal(0, hlexists('does_not_exist')) + call assert_equal(0, hlexists('Number')) + call assert_equal(0, highlight_exists('does_not_exist')) + call assert_equal(0, highlight_exists('Number')) + syntax on + call assert_equal(0, hlexists('does_not_exist')) + call assert_equal(1, hlexists('Number')) + call assert_equal(0, highlight_exists('does_not_exist')) + call assert_equal(1, highlight_exists('Number')) + syntax off +endfunc + +func Test_col() + new + call setline(1, 'abcdef') + norm gg4|mx6|mY2| + call assert_equal(2, col('.')) + call assert_equal(7, col('$')) + call assert_equal(4, col("'x")) + call assert_equal(6, col("'Y")) + call assert_equal(2, col([1, 2])) + call assert_equal(7, col([1, '$'])) + + call assert_equal(0, col('')) + call assert_equal(0, col('x')) + call assert_equal(0, col([2, '$'])) + call assert_equal(0, col([1, 100])) + call assert_equal(0, col([1])) + bw! +endfunc -- cgit From 7b53b5380a911dd48af10ff06a4005476d728b0a Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 2 Jun 2018 12:18:44 -0400 Subject: vim-patch:8.0.1311: no test for strpart() Problem: No test for strpart(). Solution: Add a test. (Dominique Pelle, closes vim/vim#2347) https://github.com/vim/vim/commit/c7d16dce2f180c8ebfc8105ad090b0ea2deedcdc --- src/nvim/testdir/test_functions.vim | 44 ++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index d34d4596d2..a2cdf71aa1 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1,5 +1,21 @@ " Tests for various functions. +" Must be done first, since the alternate buffer must be unset. +func Test_00_bufexists() + call assert_equal(0, bufexists('does_not_exist')) + call assert_equal(1, bufexists(bufnr('%'))) + call assert_equal(0, bufexists(0)) + new Xfoo + let bn = bufnr('%') + call assert_equal(1, bufexists(bn)) + call assert_equal(1, bufexists('Xfoo')) + call assert_equal(1, bufexists(getcwd() . '/Xfoo')) + call assert_equal(1, bufexists(0)) + bw + call assert_equal(0, bufexists(bn)) + call assert_equal(0, bufexists('Xfoo')) +endfunc + func Test_empty() call assert_equal(1, empty('')) call assert_equal(0, empty('a')) @@ -199,6 +215,19 @@ func Test_setbufvar_options() bwipe! endfunc +func Test_strpart() + call assert_equal('de', strpart('abcdefg', 3, 2)) + call assert_equal('ab', strpart('abcdefg', -2, 4)) + call assert_equal('abcdefg', strpart('abcdefg', -2)) + call assert_equal('fg', strpart('abcdefg', 5, 4)) + call assert_equal('defg', strpart('abcdefg', 3)) + + if has('multi_byte') + call assert_equal('lép', strpart('éléphant', 2, 4)) + call assert_equal('léphant', strpart('éléphant', 2)) + endif +endfunc + func Test_tolower() call assert_equal("", tolower("")) @@ -505,21 +534,6 @@ func Test_getbufvar() set fileformats& endfunc -func Test_bufexists() - call assert_equal(0, bufexists('does_not_exist')) - call assert_equal(1, bufexists(bufnr('%'))) - call assert_equal(0, bufexists(0)) - new Xfoo - let bn = bufnr('%') - call assert_equal(1, bufexists(bn)) - call assert_equal(1, bufexists('Xfoo')) - call assert_equal(1, bufexists(getcwd() . '/Xfoo')) - call assert_equal(1, bufexists(0)) - bw - call assert_equal(0, bufexists(bn)) - call assert_equal(0, bufexists('Xfoo')) -endfunc - func Test_last_buffer_nr() call assert_equal(bufnr('$'), last_buffer_nr()) endfunc -- cgit From 3818a472117b97a997fd932a1cd6cfdab47e033f Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 3 Jun 2018 10:40:41 -0400 Subject: oldtests: comment out v:none assertions nvim does not support v:none for json_encode() and json_decode(). --- src/nvim/testdir/test_functions.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index a2cdf71aa1..c5f4e1add9 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -39,7 +39,7 @@ func Test_empty() call assert_equal(0, empty({'a':1})) call assert_equal(1, empty(v:null)) - call assert_equal(1, empty(v:none)) + " call assert_equal(1, empty(v:none)) call assert_equal(1, empty(v:false)) call assert_equal(0, empty(v:true)) @@ -66,7 +66,7 @@ func Test_len() call assert_equal(0, len({})) call assert_equal(2, len({'a': 1, 'b': 2})) - call assert_fails('call len(v:none)', 'E701:') + " call assert_fails('call len(v:none)', 'E701:') call assert_fails('call len({-> 0})', 'E701:') endfunc @@ -80,7 +80,7 @@ func Test_max() call assert_equal(2, max({'a':1, 'b':2})) call assert_fails('call max(1)', 'E712:') - call assert_fails('call max(v:none)', 'E712:') + " call assert_fails('call max(v:none)', 'E712:') endfunc func Test_min() @@ -93,7 +93,7 @@ func Test_min() call assert_equal(1, min({'a':1, 'b':2})) call assert_fails('call min(1)', 'E712:') - call assert_fails('call min(v:none)', 'E712:') + " call assert_fails('call min(v:none)', 'E712:') endfunc func Test_str2nr() @@ -139,7 +139,7 @@ func Test_str2nr() call assert_equal(1, str2nr('1g', 16)) call assert_equal(0, str2nr(v:null)) - call assert_equal(0, str2nr(v:none)) + " call assert_equal(0, str2nr(v:none)) call assert_fails('call str2nr([])', 'E730:') call assert_fails('call str2nr({->2})', 'E729:') -- cgit From 513804ed9160cccc0e0f044a8904f8576fc9da08 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 3 Jun 2018 10:47:38 -0400 Subject: oldtests: comment out highlight group assertions nvim always defines default highlight groups so hlexists() returns 1. This happens even with `-u NONE --cmd`. --- src/nvim/testdir/test_functions.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index c5f4e1add9..4c31bb5732 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -730,14 +730,14 @@ endfunc func Test_hlexists() call assert_equal(0, hlexists('does_not_exist')) - call assert_equal(0, hlexists('Number')) + " call assert_equal(0, hlexists('Number')) call assert_equal(0, highlight_exists('does_not_exist')) - call assert_equal(0, highlight_exists('Number')) + " call assert_equal(0, highlight_exists('Number')) syntax on call assert_equal(0, hlexists('does_not_exist')) - call assert_equal(1, hlexists('Number')) + " call assert_equal(1, hlexists('Number')) call assert_equal(0, highlight_exists('does_not_exist')) - call assert_equal(1, highlight_exists('Number')) + " call assert_equal(1, highlight_exists('Number')) syntax off endfunc -- cgit