From 7bd97127b4e45dcef1159603834b04ef0dcadfd7 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sat, 29 Apr 2017 07:58:49 -0400 Subject: vim-patch:7.4.2244 Problem: Adding pattern to ":oldfiles" is not a generic solution. Solution: Add the ":filter /pat/ cmd" command modifier. Only works for some commands right now. https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928 --- src/nvim/testdir/test_alot.vim | 1 + src/nvim/testdir/test_filter_cmd.vim | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/nvim/testdir/test_filter_cmd.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim index 99d9835996..5da9a8b0f4 100644 --- a/src/nvim/testdir/test_alot.vim +++ b/src/nvim/testdir/test_alot.vim @@ -8,6 +8,7 @@ source test_ex_undo.vim source test_expr.vim source test_expr_utf8.vim source test_feedkeys.vim +source test_filter_cmd.vim source test_filter_map.vim source test_goto.vim source test_jumps.vim diff --git a/src/nvim/testdir/test_filter_cmd.vim b/src/nvim/testdir/test_filter_cmd.vim new file mode 100644 index 0000000000..f85a11ce45 --- /dev/null +++ b/src/nvim/testdir/test_filter_cmd.vim @@ -0,0 +1,15 @@ +" Test the :filter command modifier + +func Test_filter() + edit Xdoesnotmatch + edit Xwillmatch + call assert_equal('"Xwillmatch"', substitute(execute('filter willma ls'), '[^"]*\(".*"\)[^"]*', '\1', '')) +endfunc + +func Test_filter_fails() + call assert_fails('filter', 'E471:') + call assert_fails('filter pat', 'E476:') + call assert_fails('filter /pat', 'E476:') + call assert_fails('filter /pat/', 'E476:') + call assert_fails('filter /pat/ asdf', 'E492:') +endfunc -- cgit From f219657453271f19519148d76536879bec044534 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sat, 29 Apr 2017 21:29:44 -0400 Subject: vim-patch:7.4.2263 Problem: :filter does not work for many commands. Can only get matching messages. Solution: Make :filter work for :command, :map, :list, :number and :print. Make ":filter!" show non-matching lines. https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70 --- src/nvim/testdir/runtest.vim | 1 + src/nvim/testdir/test_filter_cmd.vim | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index 1cf7ab475c..140b67a1a5 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -72,6 +72,7 @@ let v:testing = 1 set directory^=. set backspace= set nohidden smarttab noautoindent noautoread complete-=i noruler noshowcmd +set listchars=eol:$ " Prevent Nvim log from writing to stderr. let $NVIM_LOG_FILE='Xnvim.log' diff --git a/src/nvim/testdir/test_filter_cmd.vim b/src/nvim/testdir/test_filter_cmd.vim index f85a11ce45..0bbd905c85 100644 --- a/src/nvim/testdir/test_filter_cmd.vim +++ b/src/nvim/testdir/test_filter_cmd.vim @@ -4,6 +4,39 @@ func Test_filter() edit Xdoesnotmatch edit Xwillmatch call assert_equal('"Xwillmatch"', substitute(execute('filter willma ls'), '[^"]*\(".*"\)[^"]*', '\1', '')) + bwipe Xdoesnotmatch + bwipe Xwillmatch + + new + call setline(1, ['foo1', 'foo2', 'foo3', 'foo4', 'foo5']) + call assert_equal("\nfoo2\nfoo4", execute('filter /foo[24]/ 1,$print')) + call assert_equal("\n 2 foo2\n 4 foo4", execute('filter /foo[24]/ 1,$number')) + call assert_equal("\nfoo2$\nfoo4$", execute('filter /foo[24]/ 1,$list')) + + call assert_equal("\nfoo1$\nfoo3$\nfoo5$", execute('filter! /foo[24]/ 1,$list')) + bwipe! + + command XTryThis echo 'this' + command XTryThat echo 'that' + command XDoThat echo 'that' + let lines = split(execute('filter XTry command'), "\n") + call assert_equal(3, len(lines)) + call assert_match("XTryThat", lines[1]) + call assert_match("XTryThis", lines[2]) + delcommand XTryThis + delcommand XTryThat + delcommand XDoThat + + map f1 the first key + map f2 the second key + map f3 not a key + let lines = split(execute('filter the map f'), "\n") + call assert_equal(2, len(lines)) + call assert_match("f2", lines[0]) + call assert_match("f1", lines[1]) + unmap f1 + unmap f2 + unmap f3 endfunc func Test_filter_fails() @@ -12,4 +45,10 @@ func Test_filter_fails() call assert_fails('filter /pat', 'E476:') call assert_fails('filter /pat/', 'E476:') call assert_fails('filter /pat/ asdf', 'E492:') + + call assert_fails('filter!', 'E471:') + call assert_fails('filter! pat', 'E476:') + call assert_fails('filter! /pat', 'E476:') + call assert_fails('filter! /pat/', 'E476:') + call assert_fails('filter! /pat/ asdf', 'E492:') endfunc -- cgit From b6e36558d1e119a4382e96495b0e1faf402197f3 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sat, 29 Apr 2017 21:49:19 -0400 Subject: vim-patch:8.0.0150 Problem: When the pattern of :filter does not have a separator then completion of the command fails. Solution: Skip over the pattern. (Ozaki Kiichi, clodes vim/vim#1299) https://github.com/vim/vim/commit/7069bf18e1b1b7bc7640335e07d1022b5acc9048 --- src/nvim/testdir/test_filter_cmd.vim | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filter_cmd.vim b/src/nvim/testdir/test_filter_cmd.vim index 0bbd905c85..5aa5fa64df 100644 --- a/src/nvim/testdir/test_filter_cmd.vim +++ b/src/nvim/testdir/test_filter_cmd.vim @@ -52,3 +52,25 @@ func Test_filter_fails() call assert_fails('filter! /pat/', 'E476:') call assert_fails('filter! /pat/ asdf', 'E492:') endfunc + +function s:complete_filter_cmd(filtcmd) + let keystroke = "\\=execute('let cmdline = getcmdline()')\\" + let cmdline = '' + call feedkeys(':' . a:filtcmd . keystroke, 'ntx') + return cmdline +endfunction + +func Test_filter_cmd_completion() + " Do not complete pattern + call assert_equal("filter \t", s:complete_filter_cmd('filter ')) + call assert_equal("filter pat\t", s:complete_filter_cmd('filter pat')) + call assert_equal("filter /pat\t", s:complete_filter_cmd('filter /pat')) + call assert_equal("filter /pat/\t", s:complete_filter_cmd('filter /pat/')) + + " Complete after string pattern + call assert_equal('filter pat print', s:complete_filter_cmd('filter pat pri')) + + " Complete after regexp pattern + call assert_equal('filter /pat/ print', s:complete_filter_cmd('filter /pat/ pri')) + call assert_equal('filter #pat# print', s:complete_filter_cmd('filter #pat# pri')) +endfunc -- cgit From 5fd1d09aa5ad5b12220a1b4e86c080a7378e1a68 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 3 May 2017 18:19:34 +0200 Subject: test/legacy: Add Test_with_partial_callback to s:flaky. (#6666) --- src/nvim/testdir/runtest.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index 140b67a1a5..64ad0f0103 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -134,7 +134,7 @@ else endif " Names of flaky tests. -let s:flaky = [] +let s:flaky = ['Test_with_partial_callback'] " Locate Test_ functions and execute them. set nomore -- cgit From f3a508b4a3c13cc755b355976c6e0f2fae7e1645 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Fri, 12 May 2017 17:32:26 -0400 Subject: oldtests: Fix spelling of testname in s:flaky --- src/nvim/testdir/runtest.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index 64ad0f0103..6832622cdf 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -134,7 +134,7 @@ else endif " Names of flaky tests. -let s:flaky = ['Test_with_partial_callback'] +let s:flaky = ['Test_with_partial_callback()'] " Locate Test_ functions and execute them. set nomore -- cgit From 4a083200078f76f29a84e4788108000009a54020 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Tue, 16 May 2017 15:26:54 -0400 Subject: oldtests: Mark test_timer's Test_oneshot as flaky --- src/nvim/testdir/runtest.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index 6832622cdf..a754e5fdfb 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -134,7 +134,10 @@ else endif " Names of flaky tests. -let s:flaky = ['Test_with_partial_callback()'] +let s:flaky = [ + \ 'Test_with_partial_callback()', + \ 'Test_oneshot()' + \ ] " Locate Test_ functions and execute them. set nomore -- cgit From 41fd2783178d727976b0cd83e5e5eab3dd72feb7 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 23 May 2017 00:44:21 +0200 Subject: oldtests: Mark Test_lambda_with_timer as flaky --- src/nvim/testdir/runtest.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index a754e5fdfb..732b0aaf74 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -137,6 +137,7 @@ endif let s:flaky = [ \ 'Test_with_partial_callback()', \ 'Test_oneshot()' + \ 'Test_lambda_with_timer()' \ ] " Locate Test_ functions and execute them. -- cgit From 018383096c40aca83a76e1ae2a3ba8c5aac9b9af Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 4 Jun 2017 22:09:19 -0400 Subject: oldtests: Fix syntax of s:flaky --- src/nvim/testdir/runtest.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index 732b0aaf74..d87c12147e 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -136,8 +136,8 @@ endif " Names of flaky tests. let s:flaky = [ \ 'Test_with_partial_callback()', - \ 'Test_oneshot()' - \ 'Test_lambda_with_timer()' + \ 'Test_oneshot()', + \ 'Test_lambda_with_timer()', \ ] " Locate Test_ functions and execute them. -- cgit From 953f26bace041f481e79b67b64401aa07259055c Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 16 Nov 2016 09:24:10 -0500 Subject: vim-patch:7.4.1975 Problem: On MS-Windows large files (> 2Gbyte) cause problems. Solution: Use "off_T" instead of "off_t". Use "stat_T" instead of "struct stat". Use 64 bit system functions if available. (Ken Takata) https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe Only the off_T changes are relevant, since all the "struct stat" usage is abstracted by libuv. --- src/nvim/testdir/Makefile | 1 + src/nvim/testdir/test_largefile.vim | 30 +++++++++++++++++ src/nvim/testdir/test_stat.vim | 64 +++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 src/nvim/testdir/test_largefile.vim create mode 100644 src/nvim/testdir/test_stat.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 70a9f2b8c4..77118c34bb 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -60,6 +60,7 @@ NEW_TESTS ?= \ test_quickfix.res \ test_signs.res \ test_smartindent.res \ + test_stat.res \ test_substitute.res \ test_syntax.res \ test_tabpage.res \ diff --git a/src/nvim/testdir/test_largefile.vim b/src/nvim/testdir/test_largefile.vim new file mode 100644 index 0000000000..ea2b8ff62d --- /dev/null +++ b/src/nvim/testdir/test_largefile.vim @@ -0,0 +1,30 @@ +" Tests for large files +" This is only executed manually: "make test_largefile". +" This is not run as part of "make test". + +func Test_largefile() + let fname = 'Xlarge.txt' + + call delete(fname) + exe "e" fname + " Make sure that a line break is 1 byte (LF). + set ff=unix + set undolevels=-1 + " Input 99 'A's. The line becomes 100 bytes including a line break. + exe "normal 99iA\" + yank + " Put 39,999,999 times. The file becomes 4,000,000,000 bytes. + normal 39999999p + " Moving around in the file randomly. + normal G + normal 10% + normal 90% + normal 50% + normal gg + w + " Check if the file size is larger than 2^31 - 1 bytes. + " Note that getfsize() returns -2 if a Number is 32 bits. + let fsize=getfsize(fname) + call assert_true(fsize > 2147483647 || fsize == -2) + "call delete(fname) +endfunc diff --git a/src/nvim/testdir/test_stat.vim b/src/nvim/testdir/test_stat.vim new file mode 100644 index 0000000000..89ca9ef379 --- /dev/null +++ b/src/nvim/testdir/test_stat.vim @@ -0,0 +1,64 @@ +" Tests for stat functions and checktime + +func Test_existent_file() + let fname='Xtest.tmp' + + let ts=localtime() + sleep 1 + let fl=['Hello World!'] + call writefile(fl, fname) + let tf=getftime(fname) + sleep 1 + let te=localtime() + + call assert_true(ts <= tf && tf <= te) + call assert_equal(strlen(fl[0] . "\n"), getfsize(fname)) + call assert_equal('file', getftype(fname)) + call assert_equal('rw-', getfperm(fname)[0:2]) +endfunc + +func Test_existent_directory() + let dname='.' + + call assert_equal(0, getfsize(dname)) + call assert_equal('dir', getftype(dname)) + call assert_equal('rwx', getfperm(dname)[0:2]) +endfunc + +func Test_checktime() + let fname='Xtest.tmp' + + let fl=['Hello World!'] + call writefile(fl, fname) + set autoread + exec 'e' fname + sleep 2 + let fl=readfile(fname) + let fl[0] .= ' - checktime' + call writefile(fl, fname) + checktime + call assert_equal(fl[0], getline(1)) +endfunc + +func Test_nonexistent_file() + let fname='Xtest.tmp' + + call delete(fname) + call assert_equal(-1, getftime(fname)) + call assert_equal(-1, getfsize(fname)) + call assert_equal('', getftype(fname)) + call assert_equal('', getfperm(fname)) +endfunc + +func Test_win32_symlink_dir() + " On Windows, non-admin users cannot create symlinks. + " So we use an existing symlink for this test. + if has('win32') + " Check if 'C:\Users\All Users' is a symlink to a directory. + let res=system('dir C:\Users /a') + if match(res, '\C *All Users') >= 0 + " Get the filetype of the symlink. + call assert_equal('dir', getftype('C:\Users\All Users')) + endif + endif +endfunc -- cgit From 81be7358be00d3d75453659bcdc7efc69207ca8e Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 16 Nov 2016 11:09:04 -0500 Subject: vim-patch:7.4.1976 Problem: Number variables are not 64 bits while they could be. Solution: Add the num64 feature. (Ken Takata) https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12 --- src/nvim/testdir/test_viml.vim | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_viml.vim b/src/nvim/testdir/test_viml.vim index a2997b6d4d..55d0dc21a3 100644 --- a/src/nvim/testdir/test_viml.vim +++ b/src/nvim/testdir/test_viml.vim @@ -1062,6 +1062,32 @@ func Test_echo_and_string() call assert_equal(["{'a': [], 'b': []}", \ "{'a': [], 'b': []}"], l) +"------------------------------------------------------------------------------- +" Test 94: 64-bit Numbers {{{1 +"------------------------------------------------------------------------------- + +func Test_num64() + if !has('num64') + return + endif + + call assert_notequal( 4294967296, 0) + call assert_notequal(-4294967296, 0) + call assert_equal( 4294967296, 0xFFFFffff + 1) + call assert_equal(-4294967296, -0xFFFFffff - 1) + + call assert_equal( 9223372036854775807, 1 / 0) + call assert_equal(-9223372036854775807, -1 / 0) + call assert_equal(-9223372036854775808, 0 / 0) + + call assert_equal( 0x7FFFffffFFFFffff, float2nr( 1.0e150)) + call assert_equal(-0x7FFFffffFFFFffff, float2nr(-1.0e150)) + + let rng = range(0xFFFFffff, 0x100000001) + call assert_equal([0xFFFFffff, 0x100000000, 0x100000001], rng) + call assert_equal(0x100000001, max(rng)) + call assert_equal(0xFFFFffff, min(rng)) + call assert_equal(rng, sort(range(0x100000001, 0xFFFFffff, -1), 'N')) endfunc "------------------------------------------------------------------------------- -- cgit From 0164a5fea3a240efc631bc10ebf1b547c2149971 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 16 Nov 2016 14:11:15 -0500 Subject: vim-patch:7.4.1978 Problem: Large file test does not delete its output. Solution: Delete the output. Check size properly when possible. (Ken Takata) https://github.com/vim/vim/commit/c5af40ae646ceda817eff93b4f9ba274f031bea6 --- src/nvim/testdir/test_largefile.vim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_largefile.vim b/src/nvim/testdir/test_largefile.vim index ea2b8ff62d..1b3e02a0c8 100644 --- a/src/nvim/testdir/test_largefile.vim +++ b/src/nvim/testdir/test_largefile.vim @@ -22,9 +22,13 @@ func Test_largefile() normal 50% normal gg w - " Check if the file size is larger than 2^31 - 1 bytes. - " Note that getfsize() returns -2 if a Number is 32 bits. + " Check if the file size is 4,000,000,000 bytes. let fsize=getfsize(fname) - call assert_true(fsize > 2147483647 || fsize == -2) - "call delete(fname) + if has('num64') + call assert_true(fsize == 4000000000) + else + " getfsize() returns -2 if a Number is 32 bits. + call assert_true(fsize == -2) + endif + call delete(fname) endfunc -- cgit From 03f5f78792c578520139a785c0d3d34e284c372d Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 16 Nov 2016 14:12:13 -0500 Subject: vim-patch:7.4.1979 Problem: Getting value of binary option is wrong. (Kent Sibilev) Solution: Fix type cast. Add a test. https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b --- src/nvim/testdir/test_expr.vim | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 03a9155512..25cbd60114 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -98,6 +98,29 @@ func Test_special_char() call assert_fails('echo "\') endfunc +func Test_option_value() + " boolean + set bri + call assert_equal(1, &bri) + set nobri + call assert_equal(0, &bri) + + " number + set ts=1 + call assert_equal(1, &ts) + set ts=8 + call assert_equal(8, &ts) + + " string + exe "set cedit=\" + call assert_equal("\", &cedit) + set cpo= + call assert_equal("", &cpo) + set cpo=abcdefi + call assert_equal("abcdefi", &cpo) + set cpo&vim +endfunc + func Test_setmatches() hi def link 1 Comment hi def link 2 PreProc -- cgit From c3efb2804a6bcf3b61695cd2b0c60bb16f1ec0a9 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 16 Nov 2016 14:30:20 -0500 Subject: vim-patch:7.4.2029 Problem: printf() does not work with 64 bit numbers. Solution: use the "L" length modifier. (Ken Takata) https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57 --- src/nvim/testdir/test_expr.vim | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 25cbd60114..04979b867f 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -121,6 +121,12 @@ func Test_option_value() set cpo&vim endfunc +function Test_printf_64bit() + if has('num64') + call assert_equal("123456789012345", printf('%d', 123456789012345)) + endif +endfunc + func Test_setmatches() hi def link 1 Comment hi def link 2 PreProc -- cgit From 2fb0a62553480406a1b8ea314a528f00692c365a Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 23 Jan 2017 12:55:27 -0500 Subject: vim-patch:8.0.0219 Problem: Ubsan reports errors for integer overflow. Solution: Define macros for minimum and maximum values. Select an expression based on the value. (Mike Williams) https://github.com/vim/vim/commit/7a40ea2138102545848ea86a361f1b8dec7552b5 --- src/nvim/testdir/test_viml.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_viml.vim b/src/nvim/testdir/test_viml.vim index 55d0dc21a3..9c1bc802a0 100644 --- a/src/nvim/testdir/test_viml.vim +++ b/src/nvim/testdir/test_viml.vim @@ -1078,7 +1078,7 @@ func Test_num64() call assert_equal( 9223372036854775807, 1 / 0) call assert_equal(-9223372036854775807, -1 / 0) - call assert_equal(-9223372036854775808, 0 / 0) + call assert_equal(-9223372036854775807 - 1, 0 / 0) call assert_equal( 0x7FFFffffFFFFffff, float2nr( 1.0e150)) call assert_equal(-0x7FFFffffFFFFffff, float2nr(-1.0e150)) -- cgit From 09eefbe92ce83e81b6e9c80681152a41ed011d56 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 4 Jun 2017 22:19:43 -0400 Subject: vim-patch:8.0.0156 Problem: Several float functions are not covered by tests. Solution: Add float tests. (Dominique Pelle) https://github.com/vim/vim/commit/453b576ee5d32e9b8e6876712748ae01f9be68dd --- src/nvim/testdir/test_alot.vim | 1 + src/nvim/testdir/test_float_func.vim | 228 +++++++++++++++++++++++++++++++++++ 2 files changed, 229 insertions(+) create mode 100644 src/nvim/testdir/test_float_func.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim index 5da9a8b0f4..a250ba7493 100644 --- a/src/nvim/testdir/test_alot.vim +++ b/src/nvim/testdir/test_alot.vim @@ -10,6 +10,7 @@ source test_expr_utf8.vim source test_feedkeys.vim source test_filter_cmd.vim source test_filter_map.vim +source test_float_func.vim source test_goto.vim source test_jumps.vim source test_lambda.vim diff --git a/src/nvim/testdir/test_float_func.vim b/src/nvim/testdir/test_float_func.vim new file mode 100644 index 0000000000..57ab9bac99 --- /dev/null +++ b/src/nvim/testdir/test_float_func.vim @@ -0,0 +1,228 @@ +" test float functions + +if !has('float') + finish +end + +func Test_abs() + call assert_equal(string(abs(1.23)), '1.23') + call assert_equal(string(abs(-1.23)), '1.23') + call assert_equal(string(abs(0.0)), '0.0') + call assert_equal(string(abs(1.0/(1.0/0.0))), '0.0') + call assert_equal(string(abs(-1.0/(1.0/0.0))), '0.0') + call assert_equal(string(abs(1.0/0.0)), "str2float('inf')") + call assert_equal(string(abs(-1.0/0.0)), "str2float('inf')") + call assert_equal(string(abs(0.0/0.0)), "str2float('nan')") +endfunc + +func Test_sqrt() + call assert_equal(string(sqrt(0.0)), '0.0') + call assert_equal(string(sqrt(2.0)), '1.414214') + call assert_equal(string(sqrt(1.0/0.0)), "str2float('inf')") + call assert_equal(string(sqrt(-1.0)), "str2float('nan')") + call assert_equal(string(sqrt(0.0/0.0)), "str2float('nan')") +endfunc + +func Test_log() + call assert_equal(string(log(1.0)), '0.0') + call assert_equal(string(log(0.5)), '-0.693147') + call assert_equal(string(log(0.0)), "-str2float('inf')") + call assert_equal(string(log(-1.0)), "str2float('nan')") + call assert_equal(string(log(1.0/0.0)), "str2float('inf')") + call assert_equal(string(log(0.0/0.0)), "str2float('nan')") +endfunc + +func Test_log10() + call assert_equal(string(log10(1.0)), '0.0') + call assert_equal(string(log10(100.0)), '2.0') + call assert_equal(string(log10(120.0)), '2.079181') + call assert_equal(string(log10(0.0)), "-str2float('inf')") + call assert_equal(string(log10(-1.0)), "str2float('nan')") + call assert_equal(string(log10(1.0/0.0)), "str2float('inf')") + call assert_equal(string(log10(0.0/0.0)), "str2float('nan')") +endfunc + +func Test_exp() + call assert_equal(string(exp(0.0)), '1.0') + call assert_equal(string(exp(2.0)), '7.389056') + call assert_equal(string(exp(-1.0)),'0.367879') + call assert_equal(string(exp(1.0/0.0)), "str2float('inf')") + call assert_equal(string(exp(-1.0/0.0)), '0.0') + call assert_equal(string(exp(0.0/0.0)), "str2float('nan')") +endfunc + +func Test_sin() + call assert_equal(string(sin(0.0)), '0.0') + call assert_equal(string(sin(1.0)), '0.841471') + call assert_equal(string(sin(-0.5)), '-0.479426') + call assert_equal(string(sin(0.0/0.0)), "str2float('nan')") + call assert_equal(string(sin(1.0/0.0)), "str2float('nan')") + call assert_equal(string(sin(1.0/(1.0/0.0))), '0.0') + call assert_equal(string(sin(-1.0/(1.0/0.0))), '-0.0') +endfunc + +func Test_asin() + call assert_equal(string(asin(0.0)), '0.0') + call assert_equal(string(asin(1.0)), '1.570796') + call assert_equal(string(asin(-0.5)), '-0.523599') + call assert_equal(string(asin(1.1)), "str2float('nan')") + call assert_equal(string(asin(1.0/0.0)), "str2float('nan')") + call assert_equal(string(asin(0.0/0.0)), "str2float('nan')") +endfunc + +func Test_sinh() + call assert_equal(string(sinh(0.0)), '0.0') + call assert_equal(string(sinh(0.5)), '0.521095') + call assert_equal(string(sinh(-0.9)), '-1.026517') + call assert_equal(string(sinh(1.0/0.0)), "str2float('inf')") + call assert_equal(string(sinh(-1.0/0.0)), "-str2float('inf')") + call assert_equal(string(sinh(0.0/0.0)), "str2float('nan')") +endfunc + +func Test_cos() + call assert_equal(string(cos(0.0)), '1.0') + call assert_equal(string(cos(1.0)), '0.540302') + call assert_equal(string(cos(-0.5)), '0.877583') + call assert_equal(string(cos(0.0/0.0)), "str2float('nan')") + call assert_equal(string(cos(1.0/0.0)), "str2float('nan')") +endfunc + +func Test_acos() + call assert_equal(string(acos(0.0)), '1.570796') + call assert_equal(string(acos(1.0)), '0.0') + call assert_equal(string(acos(-1.0)), '3.141593') + call assert_equal(string(acos(-0.5)), '2.094395') + call assert_equal(string(acos(1.1)), "str2float('nan')") + call assert_equal(string(acos(1.0/0.0)), "str2float('nan')") + call assert_equal(string(acos(0.0/0.0)), "str2float('nan')") +endfunc + +func Test_cosh() + call assert_equal(string(cosh(0.0)), '1.0') + call assert_equal(string(cosh(0.5)), '1.127626') + call assert_equal(string(cosh(1.0/0.0)), "str2float('inf')") + call assert_equal(string(cosh(-1.0/0.0)), "str2float('inf')") + call assert_equal(string(cosh(0.0/0.0)), "str2float('nan')") +endfunc + +func Test_tan() + call assert_equal(string(tan(0.0)), '0.0') + call assert_equal(string(tan(0.5)), '0.546302') + call assert_equal(string(tan(-0.5)), '-0.546302') + call assert_equal(string(tan(1.0/0.0)), "str2float('nan')") + call assert_equal(string(cos(0.0/0.0)), "str2float('nan')") + call assert_equal(string(tan(1.0/(1.0/0.0))), '0.0') + call assert_equal(string(tan(-1.0/(1.0/0.0))), '-0.0') +endfunc + +func Test_atan() + call assert_equal(string(atan(0.0)), '0.0') + call assert_equal(string(atan(0.5)), '0.463648') + call assert_equal(string(atan(-1.0)), '-0.785398') + call assert_equal(string(atan(1.0/0.0)), '1.570796') + call assert_equal(string(atan(-1.0/0.0)), '-1.570796') + call assert_equal(string(atan(0.0/0.0)), "str2float('nan')") +endfunc + +func Test_atan2() + call assert_equal(string(atan2(-1, -1)), '-2.356194') + call assert_equal(string(atan2(1, -1)), '2.356194') + call assert_equal(string(atan2(1.0, 1.0/0.0)), '0.0') + call assert_equal(string(atan2(1.0/0.0, 1.0)), '1.570796') + call assert_equal(string(atan2(0.0/0.0, 1.0)), "str2float('nan')") +endfunc + +func Test_tanh() + call assert_equal(string(tanh(0.0)), '0.0') + call assert_equal(string(tanh(0.5)), '0.462117') + call assert_equal(string(tanh(-1.0)), '-0.761594') + call assert_equal(string(tanh(1.0/0.0)), '1.0') + call assert_equal(string(tanh(-1.0/0.0)), '-1.0') + call assert_equal(string(tanh(0.0/0.0)), "str2float('nan')") +endfunc + +func Test_fmod() + call assert_equal(string(fmod(12.33, 1.22)), '0.13') + call assert_equal(string(fmod(-12.33, 1.22)), '-0.13') + call assert_equal(string(fmod(1.0/0.0, 1.0)), "str2float('nan')") + call assert_equal(string(fmod(1.0, 1.0/0.0)), '1.0') + call assert_equal(string(fmod(1.0, 0.0)), "str2float('nan')") +endfunc + +func Test_pow() + call assert_equal(string(pow(0.0, 0.0)), '1.0') + call assert_equal(string(pow(2.0, 3.0)), '8.0') + call assert_equal(string(pow(2.0, 0.0/0.0)), "str2float('nan')") + call assert_equal(string(pow(0.0/0.0, 3.0)), "str2float('nan')") + call assert_equal(string(pow(0.0/0.0, 3.0)), "str2float('nan')") + call assert_equal(string(pow(2.0, 1.0/0.0)), "str2float('inf')") + call assert_equal(string(pow(1.0/0.0, 3.0)), "str2float('inf')") +endfunc + +func Test_str2float() + call assert_equal(string(str2float('1')), '1.0') + call assert_equal(string(str2float('1.23')), '1.23') + call assert_equal(string(str2float('1.23abc')), '1.23') + call assert_equal(string(str2float('1e40')), '1.0e40') + call assert_equal(string(str2float('1e1000')), "str2float('inf')") + call assert_equal(string(str2float('inf')), "str2float('inf')") + call assert_equal(string(str2float('-inf')), "-str2float('inf')") + call assert_equal(string(str2float('Inf')), "str2float('inf')") + call assert_equal(string(str2float('nan')), "str2float('nan')") + call assert_equal(string(str2float('NaN')), "str2float('nan')") +endfunc + +func Test_floor() + call assert_equal(string(floor(2.0)), '2.0') + call assert_equal(string(floor(2.11)), '2.0') + call assert_equal(string(floor(2.99)), '2.0') + call assert_equal(string(floor(-2.11)), '-3.0') + call assert_equal(string(floor(-2.99)), '-3.0') + call assert_equal(string(floor(0.0/0.0)), "str2float('nan')") + call assert_equal(string(floor(1.0/0.0)), "str2float('inf')") + call assert_equal(string(floor(-1.0/0.0)), "-str2float('inf')") +endfunc + +func Test_ceil() + call assert_equal(string(ceil(2.0)), '2.0') + call assert_equal(string(ceil(2.11)), '3.0') + call assert_equal(string(ceil(2.99)), '3.0') + call assert_equal(string(ceil(-2.11)), '-2.0') + call assert_equal(string(ceil(-2.99)), '-2.0') + call assert_equal(string(ceil(0.0/0.0)), "str2float('nan')") + call assert_equal(string(ceil(1.0/0.0)), "str2float('inf')") + call assert_equal(string(ceil(-1.0/0.0)), "-str2float('inf')") +endfunc + +func Test_round() + call assert_equal(string(round(2.1)), '2.0') + call assert_equal(string(round(2.5)), '3.0') + call assert_equal(string(round(2.9)), '3.0') + call assert_equal(string(round(-2.1)), '-2.0') + call assert_equal(string(round(-2.5)), '-3.0') + call assert_equal(string(round(-2.9)), '-3.0') + call assert_equal(string(round(0.0/0.0)), "str2float('nan')") + call assert_equal(string(round(1.0/0.0)), "str2float('inf')") + call assert_equal(string(round(-1.0/0.0)), "-str2float('inf')") +endfunc + +func Test_trunc() + call assert_equal(string(trunc(2.1)), '2.0') + call assert_equal(string(trunc(2.5)), '2.0') + call assert_equal(string(trunc(2.9)), '2.0') + call assert_equal(string(trunc(-2.1)), '-2.0') + call assert_equal(string(trunc(-2.5)), '-2.0') + call assert_equal(string(trunc(-2.9)), '-2.0') + call assert_equal(string(trunc(0.0/0.0)), "str2float('nan')") + call assert_equal(string(trunc(1.0/0.0)), "str2float('inf')") + call assert_equal(string(trunc(-1.0/0.0)), "-str2float('inf')") +endfunc + +func Test_isnan() + throw 'skipped: Nvim does not support isnan()' + call assert_equal(isnan(1.0), 0) + call assert_equal(isnan(0.0/0.0), 1) + call assert_equal(isnan(1.0/0.0), 0) + call assert_equal(isnan('a'), 0) + call assert_equal(isnan([]), 0) +endfunc -- cgit From b1d4ef2b420b1fa9826a9e79344adaf71ad27e18 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 5 Jun 2017 21:58:33 -0400 Subject: vim-patch:8.0.0158 Problem: On MS-Windows some float functions return a different value when passed unusual values. strtod() doesn't work for "inf" and "nan". Solution: Accept both results. Fix str2float() for MS-Windows. Also reorder assert function arguments. https://github.com/vim/vim/commit/6247361101dcccc0c877e90ad67cd0cc83df7c68 --- src/nvim/testdir/test_float_func.vim | 310 ++++++++++++++++++----------------- 1 file changed, 157 insertions(+), 153 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_float_func.vim b/src/nvim/testdir/test_float_func.vim index 57ab9bac99..8600ce5b60 100644 --- a/src/nvim/testdir/test_float_func.vim +++ b/src/nvim/testdir/test_float_func.vim @@ -5,224 +5,228 @@ if !has('float') end func Test_abs() - call assert_equal(string(abs(1.23)), '1.23') - call assert_equal(string(abs(-1.23)), '1.23') - call assert_equal(string(abs(0.0)), '0.0') - call assert_equal(string(abs(1.0/(1.0/0.0))), '0.0') - call assert_equal(string(abs(-1.0/(1.0/0.0))), '0.0') - call assert_equal(string(abs(1.0/0.0)), "str2float('inf')") - call assert_equal(string(abs(-1.0/0.0)), "str2float('inf')") - call assert_equal(string(abs(0.0/0.0)), "str2float('nan')") + call assert_equal('1.23', string(abs(1.23))) + call assert_equal('1.23', string(abs(-1.23))) + call assert_equal('0.0', string(abs(0.0))) + call assert_equal('0.0', string(abs(1.0/(1.0/0.0)))) + call assert_equal('0.0', string(abs(-1.0/(1.0/0.0)))) + call assert_equal("str2float('inf')", string(abs(1.0/0.0))) + call assert_equal("str2float('inf')", string(abs(-1.0/0.0))) + call assert_equal("str2float('nan')", string(abs(0.0/0.0))) endfunc func Test_sqrt() - call assert_equal(string(sqrt(0.0)), '0.0') - call assert_equal(string(sqrt(2.0)), '1.414214') - call assert_equal(string(sqrt(1.0/0.0)), "str2float('inf')") - call assert_equal(string(sqrt(-1.0)), "str2float('nan')") - call assert_equal(string(sqrt(0.0/0.0)), "str2float('nan')") + call assert_equal('0.0', string(sqrt(0.0))) + call assert_equal('1.414214', string(sqrt(2.0))) + call assert_equal("str2float('inf')", string(sqrt(1.0/0.0))) + call assert_equal("str2float('nan')", string(sqrt(-1.0))) + call assert_equal("str2float('nan')", string(sqrt(0.0/0.0))) endfunc func Test_log() - call assert_equal(string(log(1.0)), '0.0') - call assert_equal(string(log(0.5)), '-0.693147') - call assert_equal(string(log(0.0)), "-str2float('inf')") - call assert_equal(string(log(-1.0)), "str2float('nan')") - call assert_equal(string(log(1.0/0.0)), "str2float('inf')") - call assert_equal(string(log(0.0/0.0)), "str2float('nan')") + call assert_equal('0.0', string(log(1.0))) + call assert_equal('-0.693147', string(log(0.5))) + call assert_equal("-str2float('inf')", string(log(0.0))) + call assert_equal("str2float('nan')", string(log(-1.0))) + call assert_equal("str2float('inf')", string(log(1.0/0.0))) + call assert_equal("str2float('nan')", string(log(0.0/0.0))) endfunc func Test_log10() - call assert_equal(string(log10(1.0)), '0.0') - call assert_equal(string(log10(100.0)), '2.0') - call assert_equal(string(log10(120.0)), '2.079181') - call assert_equal(string(log10(0.0)), "-str2float('inf')") - call assert_equal(string(log10(-1.0)), "str2float('nan')") - call assert_equal(string(log10(1.0/0.0)), "str2float('inf')") - call assert_equal(string(log10(0.0/0.0)), "str2float('nan')") + call assert_equal('0.0', string(log10(1.0))) + call assert_equal('2.0', string(log10(100.0))) + call assert_equal('2.079181', string(log10(120.0))) + call assert_equal("-str2float('inf')", string(log10(0.0))) + call assert_equal("str2float('nan')", string(log10(-1.0))) + call assert_equal("str2float('inf')", string(log10(1.0/0.0))) + call assert_equal("str2float('nan')", string(log10(0.0/0.0))) endfunc func Test_exp() - call assert_equal(string(exp(0.0)), '1.0') - call assert_equal(string(exp(2.0)), '7.389056') - call assert_equal(string(exp(-1.0)),'0.367879') - call assert_equal(string(exp(1.0/0.0)), "str2float('inf')") - call assert_equal(string(exp(-1.0/0.0)), '0.0') - call assert_equal(string(exp(0.0/0.0)), "str2float('nan')") + call assert_equal('1.0', string(exp(0.0))) + call assert_equal('7.389056', string(exp(2.0))) + call assert_equal('0.367879', string(exp(-1.0))) + call assert_equal("str2float('inf')", string(exp(1.0/0.0))) + call assert_equal('0.0', string(exp(-1.0/0.0))) + call assert_equal("str2float('nan')", string(exp(0.0/0.0))) endfunc func Test_sin() - call assert_equal(string(sin(0.0)), '0.0') - call assert_equal(string(sin(1.0)), '0.841471') - call assert_equal(string(sin(-0.5)), '-0.479426') - call assert_equal(string(sin(0.0/0.0)), "str2float('nan')") - call assert_equal(string(sin(1.0/0.0)), "str2float('nan')") - call assert_equal(string(sin(1.0/(1.0/0.0))), '0.0') - call assert_equal(string(sin(-1.0/(1.0/0.0))), '-0.0') + call assert_equal('0.0', string(sin(0.0))) + call assert_equal('0.841471', string(sin(1.0))) + call assert_equal('-0.479426', string(sin(-0.5))) + call assert_equal("str2float('nan')", string(sin(0.0/0.0))) + call assert_equal("str2float('nan')", string(sin(1.0/0.0))) + call assert_equal('0.0', string(sin(1.0/(1.0/0.0)))) + call assert_equal('-0.0', string(sin(-1.0/(1.0/0.0)))) endfunc func Test_asin() - call assert_equal(string(asin(0.0)), '0.0') - call assert_equal(string(asin(1.0)), '1.570796') - call assert_equal(string(asin(-0.5)), '-0.523599') - call assert_equal(string(asin(1.1)), "str2float('nan')") - call assert_equal(string(asin(1.0/0.0)), "str2float('nan')") - call assert_equal(string(asin(0.0/0.0)), "str2float('nan')") + call assert_equal('0.0', string(asin(0.0))) + call assert_equal('1.570796', string(asin(1.0))) + call assert_equal('-0.523599', string(asin(-0.5))) + call assert_equal("str2float('nan')", string(asin(1.1))) + call assert_equal("str2float('nan')", string(asin(1.0/0.0))) + call assert_equal("str2float('nan')", string(asin(0.0/0.0))) endfunc func Test_sinh() - call assert_equal(string(sinh(0.0)), '0.0') - call assert_equal(string(sinh(0.5)), '0.521095') - call assert_equal(string(sinh(-0.9)), '-1.026517') - call assert_equal(string(sinh(1.0/0.0)), "str2float('inf')") - call assert_equal(string(sinh(-1.0/0.0)), "-str2float('inf')") - call assert_equal(string(sinh(0.0/0.0)), "str2float('nan')") + call assert_equal('0.0', string(sinh(0.0))) + call assert_equal('0.521095', string(sinh(0.5))) + call assert_equal('-1.026517', string(sinh(-0.9))) + call assert_equal("str2float('inf')", string(sinh(1.0/0.0))) + call assert_equal("-str2float('inf')", string(sinh(-1.0/0.0))) + call assert_equal("str2float('nan')", string(sinh(0.0/0.0))) endfunc func Test_cos() - call assert_equal(string(cos(0.0)), '1.0') - call assert_equal(string(cos(1.0)), '0.540302') - call assert_equal(string(cos(-0.5)), '0.877583') - call assert_equal(string(cos(0.0/0.0)), "str2float('nan')") - call assert_equal(string(cos(1.0/0.0)), "str2float('nan')") + call assert_equal('1.0', string(cos(0.0))) + call assert_equal('0.540302', string(cos(1.0))) + call assert_equal('0.877583', string(cos(-0.5))) + call assert_equal("str2float('nan')", string(cos(0.0/0.0))) + call assert_equal("str2float('nan')", string(cos(1.0/0.0))) endfunc func Test_acos() - call assert_equal(string(acos(0.0)), '1.570796') - call assert_equal(string(acos(1.0)), '0.0') - call assert_equal(string(acos(-1.0)), '3.141593') - call assert_equal(string(acos(-0.5)), '2.094395') - call assert_equal(string(acos(1.1)), "str2float('nan')") - call assert_equal(string(acos(1.0/0.0)), "str2float('nan')") - call assert_equal(string(acos(0.0/0.0)), "str2float('nan')") + call assert_equal('1.570796', string(acos(0.0))) + call assert_equal('0.0', string(acos(1.0))) + call assert_equal('3.141593', string(acos(-1.0))) + call assert_equal('2.094395', string(acos(-0.5))) + call assert_equal("str2float('nan')", string(acos(1.1))) + call assert_equal("str2float('nan')", string(acos(1.0/0.0))) + call assert_equal("str2float('nan')", string(acos(0.0/0.0))) endfunc func Test_cosh() - call assert_equal(string(cosh(0.0)), '1.0') - call assert_equal(string(cosh(0.5)), '1.127626') - call assert_equal(string(cosh(1.0/0.0)), "str2float('inf')") - call assert_equal(string(cosh(-1.0/0.0)), "str2float('inf')") - call assert_equal(string(cosh(0.0/0.0)), "str2float('nan')") + call assert_equal('1.0', string(cosh(0.0))) + call assert_equal('1.127626', string(cosh(0.5))) + call assert_equal("str2float('inf')", string(cosh(1.0/0.0))) + call assert_equal("str2float('inf')", string(cosh(-1.0/0.0))) + call assert_equal("str2float('nan')", string(cosh(0.0/0.0))) endfunc func Test_tan() - call assert_equal(string(tan(0.0)), '0.0') - call assert_equal(string(tan(0.5)), '0.546302') - call assert_equal(string(tan(-0.5)), '-0.546302') - call assert_equal(string(tan(1.0/0.0)), "str2float('nan')") - call assert_equal(string(cos(0.0/0.0)), "str2float('nan')") - call assert_equal(string(tan(1.0/(1.0/0.0))), '0.0') - call assert_equal(string(tan(-1.0/(1.0/0.0))), '-0.0') + call assert_equal('0.0', string(tan(0.0))) + call assert_equal('0.546302', string(tan(0.5))) + call assert_equal('-0.546302', string(tan(-0.5))) + call assert_equal("str2float('nan')", string(tan(1.0/0.0))) + call assert_equal("str2float('nan')", string(cos(0.0/0.0))) + call assert_equal('0.0', string(tan(1.0/(1.0/0.0)))) + call assert_equal('-0.0', string(tan(-1.0/(1.0/0.0)))) endfunc func Test_atan() - call assert_equal(string(atan(0.0)), '0.0') - call assert_equal(string(atan(0.5)), '0.463648') - call assert_equal(string(atan(-1.0)), '-0.785398') - call assert_equal(string(atan(1.0/0.0)), '1.570796') - call assert_equal(string(atan(-1.0/0.0)), '-1.570796') - call assert_equal(string(atan(0.0/0.0)), "str2float('nan')") + call assert_equal('0.0', string(atan(0.0))) + call assert_equal('0.463648', string(atan(0.5))) + call assert_equal('-0.785398', string(atan(-1.0))) + call assert_equal('1.570796', string(atan(1.0/0.0))) + call assert_equal('-1.570796', string(atan(-1.0/0.0))) + call assert_equal("str2float('nan')", string(atan(0.0/0.0))) endfunc func Test_atan2() - call assert_equal(string(atan2(-1, -1)), '-2.356194') - call assert_equal(string(atan2(1, -1)), '2.356194') - call assert_equal(string(atan2(1.0, 1.0/0.0)), '0.0') - call assert_equal(string(atan2(1.0/0.0, 1.0)), '1.570796') - call assert_equal(string(atan2(0.0/0.0, 1.0)), "str2float('nan')") + call assert_equal('-2.356194', string(atan2(-1, -1))) + call assert_equal('2.356194', string(atan2(1, -1))) + call assert_equal('0.0', string(atan2(1.0, 1.0/0.0))) + call assert_equal('1.570796', string(atan2(1.0/0.0, 1.0))) + call assert_equal("str2float('nan')", string(atan2(0.0/0.0, 1.0))) endfunc func Test_tanh() - call assert_equal(string(tanh(0.0)), '0.0') - call assert_equal(string(tanh(0.5)), '0.462117') - call assert_equal(string(tanh(-1.0)), '-0.761594') - call assert_equal(string(tanh(1.0/0.0)), '1.0') - call assert_equal(string(tanh(-1.0/0.0)), '-1.0') - call assert_equal(string(tanh(0.0/0.0)), "str2float('nan')") + call assert_equal('0.0', string(tanh(0.0))) + call assert_equal('0.462117', string(tanh(0.5))) + call assert_equal('-0.761594', string(tanh(-1.0))) + call assert_equal('1.0', string(tanh(1.0/0.0))) + call assert_equal('-1.0', string(tanh(-1.0/0.0))) + call assert_equal("str2float('nan')", string(tanh(0.0/0.0))) endfunc func Test_fmod() - call assert_equal(string(fmod(12.33, 1.22)), '0.13') - call assert_equal(string(fmod(-12.33, 1.22)), '-0.13') - call assert_equal(string(fmod(1.0/0.0, 1.0)), "str2float('nan')") - call assert_equal(string(fmod(1.0, 1.0/0.0)), '1.0') - call assert_equal(string(fmod(1.0, 0.0)), "str2float('nan')") + call assert_equal('0.13', string(fmod(12.33, 1.22))) + call assert_equal('-0.13', string(fmod(-12.33, 1.22))) + call assert_equal("str2float('nan')", string(fmod(1.0/0.0, 1.0))) + " On Windows we get "nan" instead of 1.0, accept both. + let res = string(fmod(1.0, 1.0/0.0)) + if res != "str2float('nan')" + call assert_equal('1.0', res) + endif + call assert_equal("str2float('nan')", string(fmod(1.0, 0.0))) endfunc func Test_pow() - call assert_equal(string(pow(0.0, 0.0)), '1.0') - call assert_equal(string(pow(2.0, 3.0)), '8.0') - call assert_equal(string(pow(2.0, 0.0/0.0)), "str2float('nan')") - call assert_equal(string(pow(0.0/0.0, 3.0)), "str2float('nan')") - call assert_equal(string(pow(0.0/0.0, 3.0)), "str2float('nan')") - call assert_equal(string(pow(2.0, 1.0/0.0)), "str2float('inf')") - call assert_equal(string(pow(1.0/0.0, 3.0)), "str2float('inf')") + call assert_equal('1.0', string(pow(0.0, 0.0))) + call assert_equal('8.0', string(pow(2.0, 3.0))) + call assert_equal("str2float('nan')", string(pow(2.0, 0.0/0.0))) + call assert_equal("str2float('nan')", string(pow(0.0/0.0, 3.0))) + call assert_equal("str2float('nan')", string(pow(0.0/0.0, 3.0))) + call assert_equal("str2float('inf')", string(pow(2.0, 1.0/0.0))) + call assert_equal("str2float('inf')", string(pow(1.0/0.0, 3.0))) endfunc func Test_str2float() - call assert_equal(string(str2float('1')), '1.0') - call assert_equal(string(str2float('1.23')), '1.23') - call assert_equal(string(str2float('1.23abc')), '1.23') - call assert_equal(string(str2float('1e40')), '1.0e40') - call assert_equal(string(str2float('1e1000')), "str2float('inf')") - call assert_equal(string(str2float('inf')), "str2float('inf')") - call assert_equal(string(str2float('-inf')), "-str2float('inf')") - call assert_equal(string(str2float('Inf')), "str2float('inf')") - call assert_equal(string(str2float('nan')), "str2float('nan')") - call assert_equal(string(str2float('NaN')), "str2float('nan')") + call assert_equal('1.0', string(str2float('1'))) + call assert_equal('1.23', string(str2float('1.23'))) + call assert_equal('1.23', string(str2float('1.23abc'))) + call assert_equal('1.0e40', string(str2float('1e40'))) + call assert_equal("str2float('inf')", string(str2float('1e1000'))) + call assert_equal("str2float('inf')", string(str2float('inf'))) + call assert_equal("-str2float('inf')", string(str2float('-inf'))) + call assert_equal("str2float('inf')", string(str2float('Inf'))) + call assert_equal("str2float('nan')", string(str2float('nan'))) + call assert_equal("str2float('nan')", string(str2float('NaN'))) endfunc func Test_floor() - call assert_equal(string(floor(2.0)), '2.0') - call assert_equal(string(floor(2.11)), '2.0') - call assert_equal(string(floor(2.99)), '2.0') - call assert_equal(string(floor(-2.11)), '-3.0') - call assert_equal(string(floor(-2.99)), '-3.0') - call assert_equal(string(floor(0.0/0.0)), "str2float('nan')") - call assert_equal(string(floor(1.0/0.0)), "str2float('inf')") - call assert_equal(string(floor(-1.0/0.0)), "-str2float('inf')") + call assert_equal('2.0', string(floor(2.0))) + call assert_equal('2.0', string(floor(2.11))) + call assert_equal('2.0', string(floor(2.99))) + call assert_equal('-3.0', string(floor(-2.11))) + call assert_equal('-3.0', string(floor(-2.99))) + call assert_equal("str2float('nan')", string(floor(0.0/0.0))) + call assert_equal("str2float('inf')", string(floor(1.0/0.0))) + call assert_equal("-str2float('inf')", string(floor(-1.0/0.0))) endfunc func Test_ceil() - call assert_equal(string(ceil(2.0)), '2.0') - call assert_equal(string(ceil(2.11)), '3.0') - call assert_equal(string(ceil(2.99)), '3.0') - call assert_equal(string(ceil(-2.11)), '-2.0') - call assert_equal(string(ceil(-2.99)), '-2.0') - call assert_equal(string(ceil(0.0/0.0)), "str2float('nan')") - call assert_equal(string(ceil(1.0/0.0)), "str2float('inf')") - call assert_equal(string(ceil(-1.0/0.0)), "-str2float('inf')") + call assert_equal('2.0', string(ceil(2.0))) + call assert_equal('3.0', string(ceil(2.11))) + call assert_equal('3.0', string(ceil(2.99))) + call assert_equal('-2.0', string(ceil(-2.11))) + call assert_equal('-2.0', string(ceil(-2.99))) + call assert_equal("str2float('nan')", string(ceil(0.0/0.0))) + call assert_equal("str2float('inf')", string(ceil(1.0/0.0))) + call assert_equal("-str2float('inf')", string(ceil(-1.0/0.0))) endfunc func Test_round() - call assert_equal(string(round(2.1)), '2.0') - call assert_equal(string(round(2.5)), '3.0') - call assert_equal(string(round(2.9)), '3.0') - call assert_equal(string(round(-2.1)), '-2.0') - call assert_equal(string(round(-2.5)), '-3.0') - call assert_equal(string(round(-2.9)), '-3.0') - call assert_equal(string(round(0.0/0.0)), "str2float('nan')") - call assert_equal(string(round(1.0/0.0)), "str2float('inf')") - call assert_equal(string(round(-1.0/0.0)), "-str2float('inf')") + call assert_equal('2.0', string(round(2.1))) + call assert_equal('3.0', string(round(2.5))) + call assert_equal('3.0', string(round(2.9))) + call assert_equal('-2.0', string(round(-2.1))) + call assert_equal('-3.0', string(round(-2.5))) + call assert_equal('-3.0', string(round(-2.9))) + call assert_equal("str2float('nan')", string(round(0.0/0.0))) + call assert_equal("str2float('inf')", string(round(1.0/0.0))) + call assert_equal("-str2float('inf')", string(round(-1.0/0.0))) endfunc func Test_trunc() - call assert_equal(string(trunc(2.1)), '2.0') - call assert_equal(string(trunc(2.5)), '2.0') - call assert_equal(string(trunc(2.9)), '2.0') - call assert_equal(string(trunc(-2.1)), '-2.0') - call assert_equal(string(trunc(-2.5)), '-2.0') - call assert_equal(string(trunc(-2.9)), '-2.0') - call assert_equal(string(trunc(0.0/0.0)), "str2float('nan')") - call assert_equal(string(trunc(1.0/0.0)), "str2float('inf')") - call assert_equal(string(trunc(-1.0/0.0)), "-str2float('inf')") + call assert_equal('2.0', string(trunc(2.1))) + call assert_equal('2.0', string(trunc(2.5))) + call assert_equal('2.0', string(trunc(2.9))) + call assert_equal('-2.0', string(trunc(-2.1))) + call assert_equal('-2.0', string(trunc(-2.5))) + call assert_equal('-2.0', string(trunc(-2.9))) + call assert_equal("str2float('nan')", string(trunc(0.0/0.0))) + call assert_equal("str2float('inf')", string(trunc(1.0/0.0))) + call assert_equal("-str2float('inf')", string(trunc(-1.0/0.0))) endfunc func Test_isnan() throw 'skipped: Nvim does not support isnan()' - call assert_equal(isnan(1.0), 0) - call assert_equal(isnan(0.0/0.0), 1) - call assert_equal(isnan(1.0/0.0), 0) - call assert_equal(isnan('a'), 0) - call assert_equal(isnan([]), 0) + call assert_equal(0, isnan(1.0)) + call assert_equal(1, isnan(0.0/0.0)) + call assert_equal(0, isnan(1.0/0.0)) + call assert_equal(0, isnan('a')) + call assert_equal(0, isnan([])) endfunc -- cgit From 17d616037d9312be6fb99ab559861175a1bc35e6 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 5 Jun 2017 22:39:09 -0400 Subject: vim-patch:8.0.0167 Problem: str2nr() and str2float() do not always work with negative values. Solution: Be more flexible about handling signs. (LemonBoy, closes vim/vim#1332) Add more tests. https://github.com/vim/vim/commit/08243d26d22ad44a857d02c90071578577b8a55d --- src/nvim/testdir/test_alot.vim | 1 + src/nvim/testdir/test_float_func.vim | 13 +++++++++++++ src/nvim/testdir/test_functions.vim | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim index a250ba7493..1103778107 100644 --- a/src/nvim/testdir/test_alot.vim +++ b/src/nvim/testdir/test_alot.vim @@ -11,6 +11,7 @@ source test_feedkeys.vim source test_filter_cmd.vim source test_filter_map.vim source test_float_func.vim +source test_functions.vim source test_goto.vim source test_jumps.vim source test_lambda.vim diff --git a/src/nvim/testdir/test_float_func.vim b/src/nvim/testdir/test_float_func.vim index 8600ce5b60..21a156e3d8 100644 --- a/src/nvim/testdir/test_float_func.vim +++ b/src/nvim/testdir/test_float_func.vim @@ -165,9 +165,22 @@ endfunc func Test_str2float() call assert_equal('1.0', string(str2float('1'))) + call assert_equal('1.0', string(str2float(' 1 '))) + call assert_equal('1.0', string(str2float(' 1.0 '))) call assert_equal('1.23', string(str2float('1.23'))) call assert_equal('1.23', string(str2float('1.23abc'))) call assert_equal('1.0e40', string(str2float('1e40'))) + + call assert_equal('1.0', string(str2float('+1'))) + call assert_equal('1.0', string(str2float('+1'))) + call assert_equal('1.0', string(str2float(' +1 '))) + call assert_equal('1.0', string(str2float(' + 1 '))) + + call assert_equal('-1.0', string(str2float('-1'))) + call assert_equal('-1.0', string(str2float('-1'))) + call assert_equal('-1.0', string(str2float(' -1 '))) + call assert_equal('-1.0', string(str2float(' - 1 '))) + call assert_equal("str2float('inf')", string(str2float('1e1000'))) call assert_equal("str2float('inf')", string(str2float('inf'))) call assert_equal("-str2float('inf')", string(str2float('-inf'))) diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 3c258299c1..237a2dc820 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1,3 +1,22 @@ +" Tests for various functions. + +func Test_str2nr() + call assert_equal(0, str2nr('')) + call assert_equal(1, str2nr('1')) + call assert_equal(1, str2nr(' 1 ')) + + call assert_equal(1, str2nr('+1')) + call assert_equal(1, str2nr('+ 1')) + call assert_equal(1, str2nr(' + 1 ')) + + call assert_equal(-1, str2nr('-1')) + call assert_equal(-1, str2nr('- 1')) + call assert_equal(-1, str2nr(' - 1 ')) + + call assert_equal(123456789, str2nr('123456789')) + call assert_equal(-123456789, str2nr('-123456789')) +endfunc + func Test_setbufvar_options() " This tests that aucmd_prepbuf() and aucmd_restbuf() properly restore the " window layout. -- cgit From 0088ed0f1a73dcf85ce35733f2f6b2c1e84dcfef Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 5 Jun 2017 22:53:20 -0400 Subject: vim-patch:8.0.0168 Problem: Still some float functionality is not covered by tests. Solution: Add more tests. (Dominique Pelle, closes vim/vim#1364) https://github.com/vim/vim/commit/872004132f25cabe59352912889e042d6c7e6b4e --- src/nvim/testdir/test_float_func.vim | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_float_func.vim b/src/nvim/testdir/test_float_func.vim index 21a156e3d8..07ffe96129 100644 --- a/src/nvim/testdir/test_float_func.vim +++ b/src/nvim/testdir/test_float_func.vim @@ -13,6 +13,10 @@ func Test_abs() call assert_equal("str2float('inf')", string(abs(1.0/0.0))) call assert_equal("str2float('inf')", string(abs(-1.0/0.0))) call assert_equal("str2float('nan')", string(abs(0.0/0.0))) + call assert_equal('12', string(abs('-12abc'))) + call assert_fails("call abs([])", 'E745:') + call assert_fails("call abs({})", 'E728:') + call assert_fails("call abs(function('string'))", 'E703:') endfunc func Test_sqrt() @@ -21,6 +25,7 @@ func Test_sqrt() call assert_equal("str2float('inf')", string(sqrt(1.0/0.0))) call assert_equal("str2float('nan')", string(sqrt(-1.0))) call assert_equal("str2float('nan')", string(sqrt(0.0/0.0))) + call assert_fails('call sqrt("")', 'E808:') endfunc func Test_log() @@ -30,6 +35,7 @@ func Test_log() call assert_equal("str2float('nan')", string(log(-1.0))) call assert_equal("str2float('inf')", string(log(1.0/0.0))) call assert_equal("str2float('nan')", string(log(0.0/0.0))) + call assert_fails('call log("")', 'E808:') endfunc func Test_log10() @@ -40,6 +46,7 @@ func Test_log10() call assert_equal("str2float('nan')", string(log10(-1.0))) call assert_equal("str2float('inf')", string(log10(1.0/0.0))) call assert_equal("str2float('nan')", string(log10(0.0/0.0))) + call assert_fails('call log10("")', 'E808:') endfunc func Test_exp() @@ -49,6 +56,7 @@ func Test_exp() call assert_equal("str2float('inf')", string(exp(1.0/0.0))) call assert_equal('0.0', string(exp(-1.0/0.0))) call assert_equal("str2float('nan')", string(exp(0.0/0.0))) + call assert_fails('call exp("")', 'E808:') endfunc func Test_sin() @@ -59,6 +67,7 @@ func Test_sin() call assert_equal("str2float('nan')", string(sin(1.0/0.0))) call assert_equal('0.0', string(sin(1.0/(1.0/0.0)))) call assert_equal('-0.0', string(sin(-1.0/(1.0/0.0)))) + call assert_fails('call sin("")', 'E808:') endfunc func Test_asin() @@ -68,6 +77,7 @@ func Test_asin() call assert_equal("str2float('nan')", string(asin(1.1))) call assert_equal("str2float('nan')", string(asin(1.0/0.0))) call assert_equal("str2float('nan')", string(asin(0.0/0.0))) + call assert_fails('call asin("")', 'E808:') endfunc func Test_sinh() @@ -77,6 +87,7 @@ func Test_sinh() call assert_equal("str2float('inf')", string(sinh(1.0/0.0))) call assert_equal("-str2float('inf')", string(sinh(-1.0/0.0))) call assert_equal("str2float('nan')", string(sinh(0.0/0.0))) + call assert_fails('call sinh("")', 'E808:') endfunc func Test_cos() @@ -85,6 +96,7 @@ func Test_cos() call assert_equal('0.877583', string(cos(-0.5))) call assert_equal("str2float('nan')", string(cos(0.0/0.0))) call assert_equal("str2float('nan')", string(cos(1.0/0.0))) + call assert_fails('call cos("")', 'E808:') endfunc func Test_acos() @@ -95,6 +107,7 @@ func Test_acos() call assert_equal("str2float('nan')", string(acos(1.1))) call assert_equal("str2float('nan')", string(acos(1.0/0.0))) call assert_equal("str2float('nan')", string(acos(0.0/0.0))) + call assert_fails('call acos("")', 'E808:') endfunc func Test_cosh() @@ -103,6 +116,7 @@ func Test_cosh() call assert_equal("str2float('inf')", string(cosh(1.0/0.0))) call assert_equal("str2float('inf')", string(cosh(-1.0/0.0))) call assert_equal("str2float('nan')", string(cosh(0.0/0.0))) + call assert_fails('call cosh("")', 'E808:') endfunc func Test_tan() @@ -113,6 +127,7 @@ func Test_tan() call assert_equal("str2float('nan')", string(cos(0.0/0.0))) call assert_equal('0.0', string(tan(1.0/(1.0/0.0)))) call assert_equal('-0.0', string(tan(-1.0/(1.0/0.0)))) + call assert_fails('call tan("")', 'E808:') endfunc func Test_atan() @@ -122,6 +137,7 @@ func Test_atan() call assert_equal('1.570796', string(atan(1.0/0.0))) call assert_equal('-1.570796', string(atan(-1.0/0.0))) call assert_equal("str2float('nan')", string(atan(0.0/0.0))) + call assert_fails('call atan("")', 'E808:') endfunc func Test_atan2() @@ -130,6 +146,8 @@ func Test_atan2() call assert_equal('0.0', string(atan2(1.0, 1.0/0.0))) call assert_equal('1.570796', string(atan2(1.0/0.0, 1.0))) call assert_equal("str2float('nan')", string(atan2(0.0/0.0, 1.0))) + call assert_fails('call atan2("", -1)', 'E808:') + call assert_fails('call atan2(-1, "")', 'E808:') endfunc func Test_tanh() @@ -139,6 +157,7 @@ func Test_tanh() call assert_equal('1.0', string(tanh(1.0/0.0))) call assert_equal('-1.0', string(tanh(-1.0/0.0))) call assert_equal("str2float('nan')", string(tanh(0.0/0.0))) + call assert_fails('call tanh("")', 'E808:') endfunc func Test_fmod() @@ -151,6 +170,8 @@ func Test_fmod() call assert_equal('1.0', res) endif call assert_equal("str2float('nan')", string(fmod(1.0, 0.0))) + call assert_fails("call fmod('', 1.22)", 'E808:') + call assert_fails("call fmod(12.33, '')", 'E808:') endfunc func Test_pow() @@ -161,6 +182,8 @@ func Test_pow() call assert_equal("str2float('nan')", string(pow(0.0/0.0, 3.0))) call assert_equal("str2float('inf')", string(pow(2.0, 1.0/0.0))) call assert_equal("str2float('inf')", string(pow(1.0/0.0, 3.0))) + call assert_fails("call pow('', 2.0)", 'E808:') + call assert_fails("call pow(2.0, '')", 'E808:') endfunc func Test_str2float() @@ -170,6 +193,8 @@ func Test_str2float() call assert_equal('1.23', string(str2float('1.23'))) call assert_equal('1.23', string(str2float('1.23abc'))) call assert_equal('1.0e40', string(str2float('1e40'))) + call assert_equal('-1.23', string(str2float('-1.23'))) + call assert_equal('1.23', string(str2float(' + 1.23 '))) call assert_equal('1.0', string(str2float('+1'))) call assert_equal('1.0', string(str2float('+1'))) @@ -181,12 +206,22 @@ func Test_str2float() call assert_equal('-1.0', string(str2float(' -1 '))) call assert_equal('-1.0', string(str2float(' - 1 '))) + call assert_equal('0.0', string(str2float('+0.0'))) + call assert_equal('-0.0', string(str2float('-0.0'))) call assert_equal("str2float('inf')", string(str2float('1e1000'))) call assert_equal("str2float('inf')", string(str2float('inf'))) call assert_equal("-str2float('inf')", string(str2float('-inf'))) + call assert_equal("str2float('inf')", string(str2float('+inf'))) call assert_equal("str2float('inf')", string(str2float('Inf'))) + call assert_equal("str2float('inf')", string(str2float(' +inf '))) call assert_equal("str2float('nan')", string(str2float('nan'))) call assert_equal("str2float('nan')", string(str2float('NaN'))) + call assert_equal("str2float('nan')", string(str2float(' nan '))) + + call assert_fails("call str2float(1.2)", 'E806:') + call assert_fails("call str2float([])", 'E730:') + call assert_fails("call str2float({})", 'E731:') + call assert_fails("call str2float(function('string'))", 'E729:') endfunc func Test_floor() @@ -198,6 +233,7 @@ func Test_floor() call assert_equal("str2float('nan')", string(floor(0.0/0.0))) call assert_equal("str2float('inf')", string(floor(1.0/0.0))) call assert_equal("-str2float('inf')", string(floor(-1.0/0.0))) + call assert_fails("call floor('')", 'E808:') endfunc func Test_ceil() @@ -209,6 +245,7 @@ func Test_ceil() call assert_equal("str2float('nan')", string(ceil(0.0/0.0))) call assert_equal("str2float('inf')", string(ceil(1.0/0.0))) call assert_equal("-str2float('inf')", string(ceil(-1.0/0.0))) + call assert_fails("call ceil('')", 'E808:') endfunc func Test_round() @@ -221,6 +258,7 @@ func Test_round() call assert_equal("str2float('nan')", string(round(0.0/0.0))) call assert_equal("str2float('inf')", string(round(1.0/0.0))) call assert_equal("-str2float('inf')", string(round(-1.0/0.0))) + call assert_fails("call round('')", 'E808:') endfunc func Test_trunc() @@ -233,6 +271,7 @@ func Test_trunc() call assert_equal("str2float('nan')", string(trunc(0.0/0.0))) call assert_equal("str2float('inf')", string(trunc(1.0/0.0))) call assert_equal("-str2float('inf')", string(trunc(-1.0/0.0))) + call assert_fails("call trunc('')", 'E808:') endfunc func Test_isnan() @@ -242,4 +281,5 @@ func Test_isnan() call assert_equal(0, isnan(1.0/0.0)) call assert_equal(0, isnan('a')) call assert_equal(0, isnan([])) + call assert_equal(0, isnan({})) endfunc -- cgit From cb8efa4fefd845e6cf42c9d14384bd291327cfe8 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 5 Jun 2017 23:05:28 -0400 Subject: vim-patch:8.0.0360 Problem: Sometimes VimL is used, which is confusing. Solution: Consistently use "Vim script". (Hirohito Higashi) https://github.com/vim/vim/commit/b544f3c81f1e6a50322855681ac266ffaa8e313c --- src/nvim/testdir/Makefile | 2 +- src/nvim/testdir/runtest.vim | 2 +- src/nvim/testdir/test49.vim | 2 +- src/nvim/testdir/test_viml.vim | 1071 ----------------------------------- src/nvim/testdir/test_vimscript.vim | 1071 +++++++++++++++++++++++++++++++++++ 5 files changed, 1074 insertions(+), 1074 deletions(-) delete mode 100644 src/nvim/testdir/test_viml.vim create mode 100644 src/nvim/testdir/test_vimscript.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 70a9f2b8c4..5b0d826c75 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -67,7 +67,7 @@ NEW_TESTS ?= \ test_timers.res \ test_undo.res \ test_usercommands.res \ - test_viml.res \ + test_vimscript.res \ test_visual.res \ test_window_id.res \ test_writefile.res \ diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index d87c12147e..9ae53c500f 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -121,7 +121,7 @@ let s:fail = 0 let s:errors = [] let s:messages = [] let s:skipped = [] -if expand('%') =~ 'test_viml.vim' +if expand('%') =~ 'test_vimscript.vim' " this test has intentional s:errors, don't use try/catch. source % else diff --git a/src/nvim/testdir/test49.vim b/src/nvim/testdir/test49.vim index adbabd61b9..467abcd9b9 100644 --- a/src/nvim/testdir/test49.vim +++ b/src/nvim/testdir/test49.vim @@ -608,7 +608,7 @@ com! -nargs=1 -bar ExecAsScript call ExecAsScript() " END_OF_TEST_ENVIRONMENT - do not change or remove this line. -" Tests 1 to 15 were moved to test_viml.vim +" Tests 1 to 15 were moved to test_vimscript.vim let Xtest = 16 "------------------------------------------------------------------------------- diff --git a/src/nvim/testdir/test_viml.vim b/src/nvim/testdir/test_viml.vim deleted file mode 100644 index a2997b6d4d..0000000000 --- a/src/nvim/testdir/test_viml.vim +++ /dev/null @@ -1,1071 +0,0 @@ -" Test various aspects of the Vim language. -" Most of this was formerly in test49. - -"------------------------------------------------------------------------------- -" Test environment {{{1 -"------------------------------------------------------------------------------- - -com! XpathINIT let g:Xpath = '' -com! -nargs=1 -bar Xpath let g:Xpath = g:Xpath . - -" Append a message to the "messages" file -func! Xout(text) - split messages - $put =a:text - wq -endfunc - -com! -nargs=1 Xout call Xout() - -" MakeScript() - Make a script file from a function. {{{2 -" -" Create a script that consists of the body of the function a:funcname. -" Replace any ":return" by a ":finish", any argument variable by a global -" variable, and and every ":call" by a ":source" for the next following argument -" in the variable argument list. This function is useful if similar tests are -" to be made for a ":return" from a function call or a ":finish" in a script -" file. -function! MakeScript(funcname, ...) - let script = tempname() - execute "redir! >" . script - execute "function" a:funcname - redir END - execute "edit" script - " Delete the "function" and the "endfunction" lines. Do not include the - " word "function" in the pattern since it might be translated if LANG is - " set. When MakeScript() is being debugged, this deletes also the debugging - " output of its line 3 and 4. - exec '1,/.*' . a:funcname . '(.*)/d' - /^\d*\s*endfunction\>/,$d - %s/^\d*//e - %s/return/finish/e - %s/\ 0 - let cnt = cnt + 1 - s/\) - - -"------------------------------------------------------------------------------- -" Test 1: :endwhile in function {{{1 -" -" Detect if a broken loop is (incorrectly) reactivated by the -" :endwhile. Use a :return to prevent an endless loop, and make -" this test first to get a meaningful result on an error before other -" tests will hang. -"------------------------------------------------------------------------------- - -function! T1_F() - Xpath 'a' - let first = 1 - while 1 - Xpath 'b' - if first - Xpath 'c' - let first = 0 - break - else - Xpath 'd' - return - endif - endwhile -endfunction - -function! T1_G() - Xpath 'h' - let first = 1 - while 1 - Xpath 'i' - if first - Xpath 'j' - let first = 0 - break - else - Xpath 'k' - return - endif - if 1 " unmatched :if - endwhile -endfunction - -func Test_endwhile_function() - XpathINIT - call T1_F() - Xpath 'F' - - try - call T1_G() - catch - " Catch missing :endif - call assert_true(v:exception =~ 'E171') - Xpath 'x' - endtry - Xpath 'G' - - call assert_equal('abcFhijxG', g:Xpath) -endfunc - -"------------------------------------------------------------------------------- -" Test 2: :endwhile in script {{{1 -" -" Detect if a broken loop is (incorrectly) reactivated by the -" :endwhile. Use a :finish to prevent an endless loop, and place -" this test before others that might hang to get a meaningful result -" on an error. -" -" This test executes the bodies of the functions T1_F and T1_G from -" the previous test as script files (:return replaced by :finish). -"------------------------------------------------------------------------------- - -func Test_endwhile_script() - XpathINIT - ExecAsScript T1_F - Xpath 'F' - call DeleteTheScript() - - try - ExecAsScript T1_G - catch - " Catch missing :endif - call assert_true(v:exception =~ 'E171') - Xpath 'x' - endtry - Xpath 'G' - call DeleteTheScript() - - call assert_equal('abcFhijxG', g:Xpath) -endfunc - -"------------------------------------------------------------------------------- -" Test 3: :if, :elseif, :while, :continue, :break {{{1 -"------------------------------------------------------------------------------- - -function Test_if_while() - XpathINIT - if 1 - Xpath 'a' - let loops = 3 - while loops > -1 " main loop: loops == 3, 2, 1 (which breaks) - if loops <= 0 - let break_err = 1 - let loops = -1 - else - Xpath 'b' . loops - endif - if (loops == 2) - while loops == 2 " dummy loop - Xpath 'c' . loops - let loops = loops - 1 - continue " stop dummy loop - Xpath 'd' . loops - endwhile - continue " continue main loop - Xpath 'e' . loops - elseif (loops == 1) - let p = 1 - while p " dummy loop - Xpath 'f' . loops - let p = 0 - break " break dummy loop - Xpath 'g' . loops - endwhile - Xpath 'h' . loops - unlet p - break " break main loop - Xpath 'i' . loops - endif - if (loops > 0) - Xpath 'j' . loops - endif - while loops == 3 " dummy loop - let loops = loops - 1 - endwhile " end dummy loop - endwhile " end main loop - Xpath 'k' - else - Xpath 'l' - endif - Xpath 'm' - if exists("break_err") - Xpath 'm' - unlet break_err - endif - - unlet loops - - call assert_equal('ab3j3b2c2b1f1h1km', g:Xpath) -endfunc - -"------------------------------------------------------------------------------- -" Test 4: :return {{{1 -"------------------------------------------------------------------------------- - -function! T4_F() - if 1 - Xpath 'a' - let loops = 3 - while loops > 0 " 3: 2: 1: - Xpath 'b' . loops - if (loops == 2) - Xpath 'c' . loops - return - Xpath 'd' . loops - endif - Xpath 'e' . loops - let loops = loops - 1 - endwhile - Xpath 'f' - else - Xpath 'g' - endif -endfunction - -function Test_return() - XpathINIT - call T4_F() - Xpath '4' - - call assert_equal('ab3e3b2c24', g:Xpath) -endfunction - - -"------------------------------------------------------------------------------- -" Test 5: :finish {{{1 -" -" This test executes the body of the function T4_F from the previous -" test as a script file (:return replaced by :finish). -"------------------------------------------------------------------------------- - -function Test_finish() - XpathINIT - ExecAsScript T4_F - Xpath '5' - call DeleteTheScript() - - call assert_equal('ab3e3b2c25', g:Xpath) -endfunction - - - -"------------------------------------------------------------------------------- -" Test 6: Defining functions in :while loops {{{1 -" -" Functions can be defined inside other functions. An inner function -" gets defined when the outer function is executed. Functions may -" also be defined inside while loops. Expressions in braces for -" defining the function name are allowed. -" -" The functions are defined when sourcing the script, only the -" resulting path is checked in the test function. -"------------------------------------------------------------------------------- - -XpathINIT - -" The command CALL collects the argument of all its invocations in "calls" -" when used from a function (that is, when the global variable "calls" needs -" the "g:" prefix). This is to check that the function code is skipped when -" the function is defined. For inner functions, do so only if the outer -" function is not being executed. -" -let calls = "" -com! -nargs=1 CALL - \ if !exists("calls") && !exists("outer") | - \ let g:calls = g:calls . | - \ endif - -let i = 0 -while i < 3 - let i = i + 1 - if i == 1 - Xpath 'a' - function! F1(arg) - CALL a:arg - let outer = 1 - - let j = 0 - while j < 1 - Xpath 'b' - let j = j + 1 - function! G1(arg) - CALL a:arg - endfunction - Xpath 'c' - endwhile - endfunction - Xpath 'd' - - continue - endif - - Xpath 'e' . i - function! F{i}(i, arg) - CALL a:arg - let outer = 1 - - if a:i == 3 - Xpath 'f' - endif - let k = 0 - while k < 3 - Xpath 'g' . k - let k = k + 1 - function! G{a:i}{k}(arg) - CALL a:arg - endfunction - Xpath 'h' . k - endwhile - endfunction - Xpath 'i' - -endwhile - -if exists("*G1") - Xpath 'j' -endif -if exists("*F1") - call F1("F1") - if exists("*G1") - call G1("G1") - endif -endif - -if exists("G21") || exists("G22") || exists("G23") - Xpath 'k' -endif -if exists("*F2") - call F2(2, "F2") - if exists("*G21") - call G21("G21") - endif - if exists("*G22") - call G22("G22") - endif - if exists("*G23") - call G23("G23") - endif -endif - -if exists("G31") || exists("G32") || exists("G33") - Xpath 'l' -endif -if exists("*F3") - call F3(3, "F3") - if exists("*G31") - call G31("G31") - endif - if exists("*G32") - call G32("G32") - endif - if exists("*G33") - call G33("G33") - endif -endif - -Xpath 'm' - -let g:test6_result = g:Xpath -let g:test6_calls = calls - -unlet calls -delfunction F1 -delfunction G1 -delfunction F2 -delfunction G21 -delfunction G22 -delfunction G23 -delfunction G31 -delfunction G32 -delfunction G33 - -function Test_defining_functions() - call assert_equal('ade2ie3ibcg0h1g1h2g2h3fg0h1g1h2g2h3m', g:test6_result) - call assert_equal('F1G1F2G21G22G23F3G31G32G33', g:test6_calls) -endfunc - -"------------------------------------------------------------------------------- -" Test 7: Continuing on errors outside functions {{{1 -" -" On an error outside a function, the script processing continues -" at the line following the outermost :endif or :endwhile. When not -" inside an :if or :while, the script processing continues at the next -" line. -"------------------------------------------------------------------------------- - -XpathINIT - -if 1 - Xpath 'a' - while 1 - Xpath 'b' - asdf - Xpath 'c' - break - endwhile | Xpath 'd' - Xpath 'e' -endif | Xpath 'f' -Xpath 'g' - -while 1 - Xpath 'h' - if 1 - Xpath 'i' - asdf - Xpath 'j' - endif | Xpath 'k' - Xpath 'l' - break -endwhile | Xpath 'm' -Xpath 'n' - -asdf -Xpath 'o' - -asdf | Xpath 'p' -Xpath 'q' - -let g:test7_result = g:Xpath - -func Test_error_in_script() - call assert_equal('abghinoq', g:test7_result) -endfunc - -"------------------------------------------------------------------------------- -" Test 8: Aborting and continuing on errors inside functions {{{1 -" -" On an error inside a function without the "abort" attribute, the -" script processing continues at the next line (unless the error was -" in a :return command). On an error inside a function with the -" "abort" attribute, the function is aborted and the script processing -" continues after the function call; the value -1 is returned then. -"------------------------------------------------------------------------------- - -XpathINIT - -function! T8_F() - if 1 - Xpath 'a' - while 1 - Xpath 'b' - asdf - Xpath 'c' - asdf | Xpath 'd' - Xpath 'e' - break - endwhile - Xpath 'f' - endif | Xpath 'g' - Xpath 'h' - - while 1 - Xpath 'i' - if 1 - Xpath 'j' - asdf - Xpath 'k' - asdf | Xpath 'l' - Xpath 'm' - endif - Xpath 'n' - break - endwhile | Xpath 'o' - Xpath 'p' - - return novar " returns (default return value 0) - Xpath 'q' - return 1 " not reached -endfunction - -function! T8_G() abort - if 1 - Xpath 'r' - while 1 - Xpath 's' - asdf " returns -1 - Xpath 't' - break - endwhile - Xpath 'v' - endif | Xpath 'w' - Xpath 'x' - - return -4 " not reached -endfunction - -function! T8_H() abort - while 1 - Xpath 'A' - if 1 - Xpath 'B' - asdf " returns -1 - Xpath 'C' - endif - Xpath 'D' - break - endwhile | Xpath 'E' - Xpath 'F' - - return -4 " not reached -endfunction - -" Aborted functions (T8_G and T8_H) return -1. -let g:test8_sum = (T8_F() + 1) - 4 * T8_G() - 8 * T8_H() -Xpath 'X' -let g:test8_result = g:Xpath - -func Test_error_in_function() - call assert_equal(13, g:test8_sum) - call assert_equal('abcefghijkmnoprsABX', g:test8_result) - - delfunction T8_F - delfunction T8_G - delfunction T8_H -endfunc - - -"------------------------------------------------------------------------------- -" Test 9: Continuing after aborted functions {{{1 -" -" When a function with the "abort" attribute is aborted due to an -" error, the next function back in the call hierarchy without an -" "abort" attribute continues; the value -1 is returned then. -"------------------------------------------------------------------------------- - -XpathINIT - -function! F() abort - Xpath 'a' - let result = G() " not aborted - Xpath 'b' - if result != 2 - Xpath 'c' - endif - return 1 -endfunction - -function! G() " no abort attribute - Xpath 'd' - if H() != -1 " aborted - Xpath 'e' - endif - Xpath 'f' - return 2 -endfunction - -function! H() abort - Xpath 'g' - call I() " aborted - Xpath 'h' - return 4 -endfunction - -function! I() abort - Xpath 'i' - asdf " error - Xpath 'j' - return 8 -endfunction - -if F() != 1 - Xpath 'k' -endif - -let g:test9_result = g:Xpath - -delfunction F -delfunction G -delfunction H -delfunction I - -func Test_func_abort() - call assert_equal('adgifb', g:test9_result) -endfunc - - -"------------------------------------------------------------------------------- -" Test 10: :if, :elseif, :while argument parsing {{{1 -" -" A '"' or '|' in an argument expression must not be mixed up with -" a comment or a next command after a bar. Parsing errors should -" be recognized. -"------------------------------------------------------------------------------- - -XpathINIT - -function! MSG(enr, emsg) - let english = v:lang == "C" || v:lang =~ '^[Ee]n' - if a:enr == "" - Xout "TODO: Add message number for:" a:emsg - let v:errmsg = ":" . v:errmsg - endif - let match = 1 - if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) - let match = 0 - if v:errmsg == "" - Xout "Message missing." - else - let v:errmsg = escape(v:errmsg, '"') - Xout "Unexpected message:" v:errmsg - endif - endif - return match -endfunction - -if 1 || strlen("\"") | Xpath 'a' - Xpath 'b' -endif -Xpath 'c' - -if 0 -elseif 1 || strlen("\"") | Xpath 'd' - Xpath 'e' -endif -Xpath 'f' - -while 1 || strlen("\"") | Xpath 'g' - Xpath 'h' - break -endwhile -Xpath 'i' - -let v:errmsg = "" -if 1 ||| strlen("\"") | Xpath 'j' - Xpath 'k' -endif -Xpath 'l' -if !MSG('E15', "Invalid expression") - Xpath 'm' -endif - -let v:errmsg = "" -if 0 -elseif 1 ||| strlen("\"") | Xpath 'n' - Xpath 'o' -endif -Xpath 'p' -if !MSG('E15', "Invalid expression") - Xpath 'q' -endif - -let v:errmsg = "" -while 1 ||| strlen("\"") | Xpath 'r' - Xpath 's' - break -endwhile -Xpath 't' -if !MSG('E15', "Invalid expression") - Xpath 'u' -endif - -let g:test10_result = g:Xpath -delfunction MSG - -func Test_expr_parsing() - call assert_equal('abcdefghilpt', g:test10_result) -endfunc - - -"------------------------------------------------------------------------------- -" Test 11: :if, :elseif, :while argument evaluation after abort {{{1 -" -" When code is skipped over due to an error, the boolean argument to -" an :if, :elseif, or :while must not be evaluated. -"------------------------------------------------------------------------------- - -XpathINIT - -let calls = 0 - -function! P(num) - let g:calls = g:calls + a:num " side effect on call - return 0 -endfunction - -if 1 - Xpath 'a' - asdf " error - Xpath 'b' - if P(1) " should not be called - Xpath 'c' - elseif !P(2) " should not be called - Xpath 'd' - else - Xpath 'e' - endif - Xpath 'f' - while P(4) " should not be called - Xpath 'g' - endwhile - Xpath 'h' -endif -Xpath 'x' - -let g:test11_calls = calls -let g:test11_result = g:Xpath - -unlet calls -delfunction P - -func Test_arg_abort() - call assert_equal(0, g:test11_calls) - call assert_equal('ax', g:test11_result) -endfunc - - -"------------------------------------------------------------------------------- -" Test 12: Expressions in braces in skipped code {{{1 -" -" In code skipped over due to an error or inactive conditional, -" an expression in braces as part of a variable or function name -" should not be evaluated. -"------------------------------------------------------------------------------- - -XpathINIT - -function! NULL() - Xpath 'a' - return 0 -endfunction - -function! ZERO() - Xpath 'b' - return 0 -endfunction - -function! F0() - Xpath 'c' -endfunction - -function! F1(arg) - Xpath 'e' -endfunction - -let V0 = 1 - -Xpath 'f' -echo 0 ? F{NULL() + V{ZERO()}}() : 1 - -Xpath 'g' -if 0 - Xpath 'h' - call F{NULL() + V{ZERO()}}() -endif - -Xpath 'i' -if 1 - asdf " error - Xpath 'j' - call F1(F{NULL() + V{ZERO()}}()) -endif - -Xpath 'k' -if 1 - asdf " error - Xpath 'l' - call F{NULL() + V{ZERO()}}() -endif - -let g:test12_result = g:Xpath - -func Test_braces_skipped() - call assert_equal('fgik', g:test12_result) -endfunc - - -"------------------------------------------------------------------------------- -" Test 13: Failure in argument evaluation for :while {{{1 -" -" A failure in the expression evaluation for the condition of a :while -" causes the whole :while loop until the matching :endwhile being -" ignored. Continuation is at the next following line. -"------------------------------------------------------------------------------- - -XpathINIT - -Xpath 'a' -while asdf - Xpath 'b' - while 1 - Xpath 'c' - break - endwhile - Xpath 'd' - break -endwhile -Xpath 'e' - -while asdf | Xpath 'f' | endwhile | Xpath 'g' -Xpath 'h' -let g:test13_result = g:Xpath - -func Test_while_fail() - call assert_equal('aeh', g:test13_result) -endfunc - - -"------------------------------------------------------------------------------- -" Test 14: Failure in argument evaluation for :if {{{1 -" -" A failure in the expression evaluation for the condition of an :if -" does not cause the corresponding :else or :endif being matched to -" a previous :if/:elseif. Neither of both branches of the failed :if -" are executed. -"------------------------------------------------------------------------------- - -XpathINIT - -function! F() - Xpath 'a' - let x = 0 - if x " false - Xpath 'b' - elseif !x " always true - Xpath 'c' - let x = 1 - if g:boolvar " possibly undefined - Xpath 'd' - else - Xpath 'e' - endif - Xpath 'f' - elseif x " never executed - Xpath 'g' - endif - Xpath 'h' -endfunction - -let boolvar = 1 -call F() -Xpath '-' - -unlet boolvar -call F() -let g:test14_result = g:Xpath - -delfunction F - -func Test_if_fail() - call assert_equal('acdfh-acfh', g:test14_result) -endfunc - - -"------------------------------------------------------------------------------- -" Test 15: Failure in argument evaluation for :if (bar) {{{1 -" -" Like previous test, except that the failing :if ... | ... | :endif -" is in a single line. -"------------------------------------------------------------------------------- - -XpathINIT - -function! F() - Xpath 'a' - let x = 0 - if x " false - Xpath 'b' - elseif !x " always true - Xpath 'c' - let x = 1 - if g:boolvar | Xpath 'd' | else | Xpath 'e' | endif - Xpath 'f' - elseif x " never executed - Xpath 'g' - endif - Xpath 'h' -endfunction - -let boolvar = 1 -call F() -Xpath '-' - -unlet boolvar -call F() -let g:test15_result = g:Xpath - -delfunction F - -func Test_if_bar_fail() - call assert_equal('acdfh-acfh', g:test15_result) -endfunc - - -"------------------------------------------------------------------------------- -" Test 16: Recognizing {} in variable name. {{{1 -"------------------------------------------------------------------------------- - -func Test_curlies() - let s:var = 66 - let ns = 's' - call assert_equal(66, {ns}:var) - - let g:a = {} - let g:b = 't' - let g:a[g:b] = 77 - call assert_equal(77, g:a['t']) -endfunc - -"------------------------------------------------------------------------------- -" Test 91: using type(). {{{1 -"------------------------------------------------------------------------------- - -func Test_type() - call assert_equal(0, type(0)) - call assert_equal(1, type("")) - call assert_equal(2, type(function("tr"))) - call assert_equal(2, type(function("tr", [8]))) - call assert_equal(3, type([])) - call assert_equal(4, type({})) - call assert_equal(5, type(0.0)) - call assert_equal(6, type(v:false)) - call assert_equal(6, type(v:true)) - call assert_equal(7, type(v:null)) - call assert_equal(v:t_number, type(0)) - call assert_equal(v:t_string, type("")) - call assert_equal(v:t_func, type(function("tr"))) - call assert_equal(v:t_list, type([])) - call assert_equal(v:t_dict, type({})) - call assert_equal(v:t_float, type(0.0)) - call assert_equal(v:t_bool, type(v:false)) - call assert_equal(v:t_bool, type(v:true)) -endfunc - -"------------------------------------------------------------------------------- -" Test 92: skipping code {{{1 -"------------------------------------------------------------------------------- - -func Test_skip() - let Fn = function('Test_type') - call assert_false(0 && Fn[1]) - call assert_false(0 && string(Fn)) - call assert_false(0 && len(Fn)) - let l = [] - call assert_false(0 && l[1]) - call assert_false(0 && string(l)) - call assert_false(0 && len(l)) - let f = 1.0 - call assert_false(0 && f[1]) - call assert_false(0 && string(f)) - call assert_false(0 && len(f)) - let sp = v:null - call assert_false(0 && sp[1]) - call assert_false(0 && string(sp)) - call assert_false(0 && len(sp)) - -endfunc - -"------------------------------------------------------------------------------- -" Test 93: :echo and string() {{{1 -"------------------------------------------------------------------------------- - -func Test_echo_and_string() - " String - let a = 'foo bar' - redir => result - echo a - echo string(a) - redir END - let l = split(result, "\n") - call assert_equal(["foo bar", - \ "'foo bar'"], l) - - " Float - if has('float') - let a = -1.2e0 - redir => result - echo a - echo string(a) - redir END - let l = split(result, "\n") - call assert_equal(["-1.2", - \ "-1.2"], l) - endif - - " Funcref - redir => result - echo function('string') - echo string(function('string')) - redir END - let l = split(result, "\n") - call assert_equal(["string", - \ "function('string')"], l) - - " Empty dictionaries in a list - let a = {} - redir => result - echo [a, a, a] - echo string([a, a, a]) - redir END - let l = split(result, "\n") - call assert_equal(["[{}, {}, {}]", - \ "[{}, {}, {}]"], l) - - " Empty dictionaries in a dictionary - let a = {} - let b = {"a": a, "b": a} - redir => result - echo b - echo string(b) - redir END - let l = split(result, "\n") - call assert_equal(["{'a': {}, 'b': {}}", - \ "{'a': {}, 'b': {}}"], l) - - " Empty lists in a list - let a = [] - redir => result - echo [a, a, a] - echo string([a, a, a]) - redir END - let l = split(result, "\n") - call assert_equal(["[[], [], []]", - \ "[[], [], []]"], l) - - " Empty lists in a dictionary - let a = [] - let b = {"a": a, "b": a} - redir => result - echo b - echo string(b) - redir END - let l = split(result, "\n") - call assert_equal(["{'a': [], 'b': []}", - \ "{'a': [], 'b': []}"], l) - -endfunc - -"------------------------------------------------------------------------------- -" Modelines {{{1 -" vim: ts=8 sw=4 tw=80 fdm=marker -" vim: fdt=substitute(substitute(foldtext(),\ '\\%(^+--\\)\\@<=\\(\\s*\\)\\(.\\{-}\\)\:\ \\%(\"\ \\)\\=\\(Test\ \\d*\\)\:\\s*',\ '\\3\ (\\2)\:\ \\1',\ \"\"),\ '\\(Test\\s*\\)\\(\\d\\)\\D\\@=',\ '\\1\ \\2',\ "") -"------------------------------------------------------------------------------- diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim new file mode 100644 index 0000000000..a2997b6d4d --- /dev/null +++ b/src/nvim/testdir/test_vimscript.vim @@ -0,0 +1,1071 @@ +" Test various aspects of the Vim language. +" Most of this was formerly in test49. + +"------------------------------------------------------------------------------- +" Test environment {{{1 +"------------------------------------------------------------------------------- + +com! XpathINIT let g:Xpath = '' +com! -nargs=1 -bar Xpath let g:Xpath = g:Xpath . + +" Append a message to the "messages" file +func! Xout(text) + split messages + $put =a:text + wq +endfunc + +com! -nargs=1 Xout call Xout() + +" MakeScript() - Make a script file from a function. {{{2 +" +" Create a script that consists of the body of the function a:funcname. +" Replace any ":return" by a ":finish", any argument variable by a global +" variable, and and every ":call" by a ":source" for the next following argument +" in the variable argument list. This function is useful if similar tests are +" to be made for a ":return" from a function call or a ":finish" in a script +" file. +function! MakeScript(funcname, ...) + let script = tempname() + execute "redir! >" . script + execute "function" a:funcname + redir END + execute "edit" script + " Delete the "function" and the "endfunction" lines. Do not include the + " word "function" in the pattern since it might be translated if LANG is + " set. When MakeScript() is being debugged, this deletes also the debugging + " output of its line 3 and 4. + exec '1,/.*' . a:funcname . '(.*)/d' + /^\d*\s*endfunction\>/,$d + %s/^\d*//e + %s/return/finish/e + %s/\ 0 + let cnt = cnt + 1 + s/\) + + +"------------------------------------------------------------------------------- +" Test 1: :endwhile in function {{{1 +" +" Detect if a broken loop is (incorrectly) reactivated by the +" :endwhile. Use a :return to prevent an endless loop, and make +" this test first to get a meaningful result on an error before other +" tests will hang. +"------------------------------------------------------------------------------- + +function! T1_F() + Xpath 'a' + let first = 1 + while 1 + Xpath 'b' + if first + Xpath 'c' + let first = 0 + break + else + Xpath 'd' + return + endif + endwhile +endfunction + +function! T1_G() + Xpath 'h' + let first = 1 + while 1 + Xpath 'i' + if first + Xpath 'j' + let first = 0 + break + else + Xpath 'k' + return + endif + if 1 " unmatched :if + endwhile +endfunction + +func Test_endwhile_function() + XpathINIT + call T1_F() + Xpath 'F' + + try + call T1_G() + catch + " Catch missing :endif + call assert_true(v:exception =~ 'E171') + Xpath 'x' + endtry + Xpath 'G' + + call assert_equal('abcFhijxG', g:Xpath) +endfunc + +"------------------------------------------------------------------------------- +" Test 2: :endwhile in script {{{1 +" +" Detect if a broken loop is (incorrectly) reactivated by the +" :endwhile. Use a :finish to prevent an endless loop, and place +" this test before others that might hang to get a meaningful result +" on an error. +" +" This test executes the bodies of the functions T1_F and T1_G from +" the previous test as script files (:return replaced by :finish). +"------------------------------------------------------------------------------- + +func Test_endwhile_script() + XpathINIT + ExecAsScript T1_F + Xpath 'F' + call DeleteTheScript() + + try + ExecAsScript T1_G + catch + " Catch missing :endif + call assert_true(v:exception =~ 'E171') + Xpath 'x' + endtry + Xpath 'G' + call DeleteTheScript() + + call assert_equal('abcFhijxG', g:Xpath) +endfunc + +"------------------------------------------------------------------------------- +" Test 3: :if, :elseif, :while, :continue, :break {{{1 +"------------------------------------------------------------------------------- + +function Test_if_while() + XpathINIT + if 1 + Xpath 'a' + let loops = 3 + while loops > -1 " main loop: loops == 3, 2, 1 (which breaks) + if loops <= 0 + let break_err = 1 + let loops = -1 + else + Xpath 'b' . loops + endif + if (loops == 2) + while loops == 2 " dummy loop + Xpath 'c' . loops + let loops = loops - 1 + continue " stop dummy loop + Xpath 'd' . loops + endwhile + continue " continue main loop + Xpath 'e' . loops + elseif (loops == 1) + let p = 1 + while p " dummy loop + Xpath 'f' . loops + let p = 0 + break " break dummy loop + Xpath 'g' . loops + endwhile + Xpath 'h' . loops + unlet p + break " break main loop + Xpath 'i' . loops + endif + if (loops > 0) + Xpath 'j' . loops + endif + while loops == 3 " dummy loop + let loops = loops - 1 + endwhile " end dummy loop + endwhile " end main loop + Xpath 'k' + else + Xpath 'l' + endif + Xpath 'm' + if exists("break_err") + Xpath 'm' + unlet break_err + endif + + unlet loops + + call assert_equal('ab3j3b2c2b1f1h1km', g:Xpath) +endfunc + +"------------------------------------------------------------------------------- +" Test 4: :return {{{1 +"------------------------------------------------------------------------------- + +function! T4_F() + if 1 + Xpath 'a' + let loops = 3 + while loops > 0 " 3: 2: 1: + Xpath 'b' . loops + if (loops == 2) + Xpath 'c' . loops + return + Xpath 'd' . loops + endif + Xpath 'e' . loops + let loops = loops - 1 + endwhile + Xpath 'f' + else + Xpath 'g' + endif +endfunction + +function Test_return() + XpathINIT + call T4_F() + Xpath '4' + + call assert_equal('ab3e3b2c24', g:Xpath) +endfunction + + +"------------------------------------------------------------------------------- +" Test 5: :finish {{{1 +" +" This test executes the body of the function T4_F from the previous +" test as a script file (:return replaced by :finish). +"------------------------------------------------------------------------------- + +function Test_finish() + XpathINIT + ExecAsScript T4_F + Xpath '5' + call DeleteTheScript() + + call assert_equal('ab3e3b2c25', g:Xpath) +endfunction + + + +"------------------------------------------------------------------------------- +" Test 6: Defining functions in :while loops {{{1 +" +" Functions can be defined inside other functions. An inner function +" gets defined when the outer function is executed. Functions may +" also be defined inside while loops. Expressions in braces for +" defining the function name are allowed. +" +" The functions are defined when sourcing the script, only the +" resulting path is checked in the test function. +"------------------------------------------------------------------------------- + +XpathINIT + +" The command CALL collects the argument of all its invocations in "calls" +" when used from a function (that is, when the global variable "calls" needs +" the "g:" prefix). This is to check that the function code is skipped when +" the function is defined. For inner functions, do so only if the outer +" function is not being executed. +" +let calls = "" +com! -nargs=1 CALL + \ if !exists("calls") && !exists("outer") | + \ let g:calls = g:calls . | + \ endif + +let i = 0 +while i < 3 + let i = i + 1 + if i == 1 + Xpath 'a' + function! F1(arg) + CALL a:arg + let outer = 1 + + let j = 0 + while j < 1 + Xpath 'b' + let j = j + 1 + function! G1(arg) + CALL a:arg + endfunction + Xpath 'c' + endwhile + endfunction + Xpath 'd' + + continue + endif + + Xpath 'e' . i + function! F{i}(i, arg) + CALL a:arg + let outer = 1 + + if a:i == 3 + Xpath 'f' + endif + let k = 0 + while k < 3 + Xpath 'g' . k + let k = k + 1 + function! G{a:i}{k}(arg) + CALL a:arg + endfunction + Xpath 'h' . k + endwhile + endfunction + Xpath 'i' + +endwhile + +if exists("*G1") + Xpath 'j' +endif +if exists("*F1") + call F1("F1") + if exists("*G1") + call G1("G1") + endif +endif + +if exists("G21") || exists("G22") || exists("G23") + Xpath 'k' +endif +if exists("*F2") + call F2(2, "F2") + if exists("*G21") + call G21("G21") + endif + if exists("*G22") + call G22("G22") + endif + if exists("*G23") + call G23("G23") + endif +endif + +if exists("G31") || exists("G32") || exists("G33") + Xpath 'l' +endif +if exists("*F3") + call F3(3, "F3") + if exists("*G31") + call G31("G31") + endif + if exists("*G32") + call G32("G32") + endif + if exists("*G33") + call G33("G33") + endif +endif + +Xpath 'm' + +let g:test6_result = g:Xpath +let g:test6_calls = calls + +unlet calls +delfunction F1 +delfunction G1 +delfunction F2 +delfunction G21 +delfunction G22 +delfunction G23 +delfunction G31 +delfunction G32 +delfunction G33 + +function Test_defining_functions() + call assert_equal('ade2ie3ibcg0h1g1h2g2h3fg0h1g1h2g2h3m', g:test6_result) + call assert_equal('F1G1F2G21G22G23F3G31G32G33', g:test6_calls) +endfunc + +"------------------------------------------------------------------------------- +" Test 7: Continuing on errors outside functions {{{1 +" +" On an error outside a function, the script processing continues +" at the line following the outermost :endif or :endwhile. When not +" inside an :if or :while, the script processing continues at the next +" line. +"------------------------------------------------------------------------------- + +XpathINIT + +if 1 + Xpath 'a' + while 1 + Xpath 'b' + asdf + Xpath 'c' + break + endwhile | Xpath 'd' + Xpath 'e' +endif | Xpath 'f' +Xpath 'g' + +while 1 + Xpath 'h' + if 1 + Xpath 'i' + asdf + Xpath 'j' + endif | Xpath 'k' + Xpath 'l' + break +endwhile | Xpath 'm' +Xpath 'n' + +asdf +Xpath 'o' + +asdf | Xpath 'p' +Xpath 'q' + +let g:test7_result = g:Xpath + +func Test_error_in_script() + call assert_equal('abghinoq', g:test7_result) +endfunc + +"------------------------------------------------------------------------------- +" Test 8: Aborting and continuing on errors inside functions {{{1 +" +" On an error inside a function without the "abort" attribute, the +" script processing continues at the next line (unless the error was +" in a :return command). On an error inside a function with the +" "abort" attribute, the function is aborted and the script processing +" continues after the function call; the value -1 is returned then. +"------------------------------------------------------------------------------- + +XpathINIT + +function! T8_F() + if 1 + Xpath 'a' + while 1 + Xpath 'b' + asdf + Xpath 'c' + asdf | Xpath 'd' + Xpath 'e' + break + endwhile + Xpath 'f' + endif | Xpath 'g' + Xpath 'h' + + while 1 + Xpath 'i' + if 1 + Xpath 'j' + asdf + Xpath 'k' + asdf | Xpath 'l' + Xpath 'm' + endif + Xpath 'n' + break + endwhile | Xpath 'o' + Xpath 'p' + + return novar " returns (default return value 0) + Xpath 'q' + return 1 " not reached +endfunction + +function! T8_G() abort + if 1 + Xpath 'r' + while 1 + Xpath 's' + asdf " returns -1 + Xpath 't' + break + endwhile + Xpath 'v' + endif | Xpath 'w' + Xpath 'x' + + return -4 " not reached +endfunction + +function! T8_H() abort + while 1 + Xpath 'A' + if 1 + Xpath 'B' + asdf " returns -1 + Xpath 'C' + endif + Xpath 'D' + break + endwhile | Xpath 'E' + Xpath 'F' + + return -4 " not reached +endfunction + +" Aborted functions (T8_G and T8_H) return -1. +let g:test8_sum = (T8_F() + 1) - 4 * T8_G() - 8 * T8_H() +Xpath 'X' +let g:test8_result = g:Xpath + +func Test_error_in_function() + call assert_equal(13, g:test8_sum) + call assert_equal('abcefghijkmnoprsABX', g:test8_result) + + delfunction T8_F + delfunction T8_G + delfunction T8_H +endfunc + + +"------------------------------------------------------------------------------- +" Test 9: Continuing after aborted functions {{{1 +" +" When a function with the "abort" attribute is aborted due to an +" error, the next function back in the call hierarchy without an +" "abort" attribute continues; the value -1 is returned then. +"------------------------------------------------------------------------------- + +XpathINIT + +function! F() abort + Xpath 'a' + let result = G() " not aborted + Xpath 'b' + if result != 2 + Xpath 'c' + endif + return 1 +endfunction + +function! G() " no abort attribute + Xpath 'd' + if H() != -1 " aborted + Xpath 'e' + endif + Xpath 'f' + return 2 +endfunction + +function! H() abort + Xpath 'g' + call I() " aborted + Xpath 'h' + return 4 +endfunction + +function! I() abort + Xpath 'i' + asdf " error + Xpath 'j' + return 8 +endfunction + +if F() != 1 + Xpath 'k' +endif + +let g:test9_result = g:Xpath + +delfunction F +delfunction G +delfunction H +delfunction I + +func Test_func_abort() + call assert_equal('adgifb', g:test9_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 10: :if, :elseif, :while argument parsing {{{1 +" +" A '"' or '|' in an argument expression must not be mixed up with +" a comment or a next command after a bar. Parsing errors should +" be recognized. +"------------------------------------------------------------------------------- + +XpathINIT + +function! MSG(enr, emsg) + let english = v:lang == "C" || v:lang =~ '^[Ee]n' + if a:enr == "" + Xout "TODO: Add message number for:" a:emsg + let v:errmsg = ":" . v:errmsg + endif + let match = 1 + if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) + let match = 0 + if v:errmsg == "" + Xout "Message missing." + else + let v:errmsg = escape(v:errmsg, '"') + Xout "Unexpected message:" v:errmsg + endif + endif + return match +endfunction + +if 1 || strlen("\"") | Xpath 'a' + Xpath 'b' +endif +Xpath 'c' + +if 0 +elseif 1 || strlen("\"") | Xpath 'd' + Xpath 'e' +endif +Xpath 'f' + +while 1 || strlen("\"") | Xpath 'g' + Xpath 'h' + break +endwhile +Xpath 'i' + +let v:errmsg = "" +if 1 ||| strlen("\"") | Xpath 'j' + Xpath 'k' +endif +Xpath 'l' +if !MSG('E15', "Invalid expression") + Xpath 'm' +endif + +let v:errmsg = "" +if 0 +elseif 1 ||| strlen("\"") | Xpath 'n' + Xpath 'o' +endif +Xpath 'p' +if !MSG('E15', "Invalid expression") + Xpath 'q' +endif + +let v:errmsg = "" +while 1 ||| strlen("\"") | Xpath 'r' + Xpath 's' + break +endwhile +Xpath 't' +if !MSG('E15', "Invalid expression") + Xpath 'u' +endif + +let g:test10_result = g:Xpath +delfunction MSG + +func Test_expr_parsing() + call assert_equal('abcdefghilpt', g:test10_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 11: :if, :elseif, :while argument evaluation after abort {{{1 +" +" When code is skipped over due to an error, the boolean argument to +" an :if, :elseif, or :while must not be evaluated. +"------------------------------------------------------------------------------- + +XpathINIT + +let calls = 0 + +function! P(num) + let g:calls = g:calls + a:num " side effect on call + return 0 +endfunction + +if 1 + Xpath 'a' + asdf " error + Xpath 'b' + if P(1) " should not be called + Xpath 'c' + elseif !P(2) " should not be called + Xpath 'd' + else + Xpath 'e' + endif + Xpath 'f' + while P(4) " should not be called + Xpath 'g' + endwhile + Xpath 'h' +endif +Xpath 'x' + +let g:test11_calls = calls +let g:test11_result = g:Xpath + +unlet calls +delfunction P + +func Test_arg_abort() + call assert_equal(0, g:test11_calls) + call assert_equal('ax', g:test11_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 12: Expressions in braces in skipped code {{{1 +" +" In code skipped over due to an error or inactive conditional, +" an expression in braces as part of a variable or function name +" should not be evaluated. +"------------------------------------------------------------------------------- + +XpathINIT + +function! NULL() + Xpath 'a' + return 0 +endfunction + +function! ZERO() + Xpath 'b' + return 0 +endfunction + +function! F0() + Xpath 'c' +endfunction + +function! F1(arg) + Xpath 'e' +endfunction + +let V0 = 1 + +Xpath 'f' +echo 0 ? F{NULL() + V{ZERO()}}() : 1 + +Xpath 'g' +if 0 + Xpath 'h' + call F{NULL() + V{ZERO()}}() +endif + +Xpath 'i' +if 1 + asdf " error + Xpath 'j' + call F1(F{NULL() + V{ZERO()}}()) +endif + +Xpath 'k' +if 1 + asdf " error + Xpath 'l' + call F{NULL() + V{ZERO()}}() +endif + +let g:test12_result = g:Xpath + +func Test_braces_skipped() + call assert_equal('fgik', g:test12_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 13: Failure in argument evaluation for :while {{{1 +" +" A failure in the expression evaluation for the condition of a :while +" causes the whole :while loop until the matching :endwhile being +" ignored. Continuation is at the next following line. +"------------------------------------------------------------------------------- + +XpathINIT + +Xpath 'a' +while asdf + Xpath 'b' + while 1 + Xpath 'c' + break + endwhile + Xpath 'd' + break +endwhile +Xpath 'e' + +while asdf | Xpath 'f' | endwhile | Xpath 'g' +Xpath 'h' +let g:test13_result = g:Xpath + +func Test_while_fail() + call assert_equal('aeh', g:test13_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 14: Failure in argument evaluation for :if {{{1 +" +" A failure in the expression evaluation for the condition of an :if +" does not cause the corresponding :else or :endif being matched to +" a previous :if/:elseif. Neither of both branches of the failed :if +" are executed. +"------------------------------------------------------------------------------- + +XpathINIT + +function! F() + Xpath 'a' + let x = 0 + if x " false + Xpath 'b' + elseif !x " always true + Xpath 'c' + let x = 1 + if g:boolvar " possibly undefined + Xpath 'd' + else + Xpath 'e' + endif + Xpath 'f' + elseif x " never executed + Xpath 'g' + endif + Xpath 'h' +endfunction + +let boolvar = 1 +call F() +Xpath '-' + +unlet boolvar +call F() +let g:test14_result = g:Xpath + +delfunction F + +func Test_if_fail() + call assert_equal('acdfh-acfh', g:test14_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 15: Failure in argument evaluation for :if (bar) {{{1 +" +" Like previous test, except that the failing :if ... | ... | :endif +" is in a single line. +"------------------------------------------------------------------------------- + +XpathINIT + +function! F() + Xpath 'a' + let x = 0 + if x " false + Xpath 'b' + elseif !x " always true + Xpath 'c' + let x = 1 + if g:boolvar | Xpath 'd' | else | Xpath 'e' | endif + Xpath 'f' + elseif x " never executed + Xpath 'g' + endif + Xpath 'h' +endfunction + +let boolvar = 1 +call F() +Xpath '-' + +unlet boolvar +call F() +let g:test15_result = g:Xpath + +delfunction F + +func Test_if_bar_fail() + call assert_equal('acdfh-acfh', g:test15_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 16: Recognizing {} in variable name. {{{1 +"------------------------------------------------------------------------------- + +func Test_curlies() + let s:var = 66 + let ns = 's' + call assert_equal(66, {ns}:var) + + let g:a = {} + let g:b = 't' + let g:a[g:b] = 77 + call assert_equal(77, g:a['t']) +endfunc + +"------------------------------------------------------------------------------- +" Test 91: using type(). {{{1 +"------------------------------------------------------------------------------- + +func Test_type() + call assert_equal(0, type(0)) + call assert_equal(1, type("")) + call assert_equal(2, type(function("tr"))) + call assert_equal(2, type(function("tr", [8]))) + call assert_equal(3, type([])) + call assert_equal(4, type({})) + call assert_equal(5, type(0.0)) + call assert_equal(6, type(v:false)) + call assert_equal(6, type(v:true)) + call assert_equal(7, type(v:null)) + call assert_equal(v:t_number, type(0)) + call assert_equal(v:t_string, type("")) + call assert_equal(v:t_func, type(function("tr"))) + call assert_equal(v:t_list, type([])) + call assert_equal(v:t_dict, type({})) + call assert_equal(v:t_float, type(0.0)) + call assert_equal(v:t_bool, type(v:false)) + call assert_equal(v:t_bool, type(v:true)) +endfunc + +"------------------------------------------------------------------------------- +" Test 92: skipping code {{{1 +"------------------------------------------------------------------------------- + +func Test_skip() + let Fn = function('Test_type') + call assert_false(0 && Fn[1]) + call assert_false(0 && string(Fn)) + call assert_false(0 && len(Fn)) + let l = [] + call assert_false(0 && l[1]) + call assert_false(0 && string(l)) + call assert_false(0 && len(l)) + let f = 1.0 + call assert_false(0 && f[1]) + call assert_false(0 && string(f)) + call assert_false(0 && len(f)) + let sp = v:null + call assert_false(0 && sp[1]) + call assert_false(0 && string(sp)) + call assert_false(0 && len(sp)) + +endfunc + +"------------------------------------------------------------------------------- +" Test 93: :echo and string() {{{1 +"------------------------------------------------------------------------------- + +func Test_echo_and_string() + " String + let a = 'foo bar' + redir => result + echo a + echo string(a) + redir END + let l = split(result, "\n") + call assert_equal(["foo bar", + \ "'foo bar'"], l) + + " Float + if has('float') + let a = -1.2e0 + redir => result + echo a + echo string(a) + redir END + let l = split(result, "\n") + call assert_equal(["-1.2", + \ "-1.2"], l) + endif + + " Funcref + redir => result + echo function('string') + echo string(function('string')) + redir END + let l = split(result, "\n") + call assert_equal(["string", + \ "function('string')"], l) + + " Empty dictionaries in a list + let a = {} + redir => result + echo [a, a, a] + echo string([a, a, a]) + redir END + let l = split(result, "\n") + call assert_equal(["[{}, {}, {}]", + \ "[{}, {}, {}]"], l) + + " Empty dictionaries in a dictionary + let a = {} + let b = {"a": a, "b": a} + redir => result + echo b + echo string(b) + redir END + let l = split(result, "\n") + call assert_equal(["{'a': {}, 'b': {}}", + \ "{'a': {}, 'b': {}}"], l) + + " Empty lists in a list + let a = [] + redir => result + echo [a, a, a] + echo string([a, a, a]) + redir END + let l = split(result, "\n") + call assert_equal(["[[], [], []]", + \ "[[], [], []]"], l) + + " Empty lists in a dictionary + let a = [] + let b = {"a": a, "b": a} + redir => result + echo b + echo string(b) + redir END + let l = split(result, "\n") + call assert_equal(["{'a': [], 'b': []}", + \ "{'a': [], 'b': []}"], l) + +endfunc + +"------------------------------------------------------------------------------- +" Modelines {{{1 +" vim: ts=8 sw=4 tw=80 fdm=marker +" vim: fdt=substitute(substitute(foldtext(),\ '\\%(^+--\\)\\@<=\\(\\s*\\)\\(.\\{-}\\)\:\ \\%(\"\ \\)\\=\\(Test\ \\d*\\)\:\\s*',\ '\\3\ (\\2)\:\ \\1',\ \"\"),\ '\\(Test\\s*\\)\\(\\d\\)\\D\\@=',\ '\\1\ \\2',\ "") +"------------------------------------------------------------------------------- -- cgit From dafc14b9691dfa9af143c0372f84b9288163c30a Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 5 Jun 2017 23:17:54 -0400 Subject: vim-patch:8.0.0477 Problem: The client-server test may hang when failing. Solution: Set a timer. Add assert_report() https://github.com/vim/vim/commit/42205551b140bee8b419b24abe210f56bb80b35e --- src/nvim/testdir/runtest.vim | 108 ++++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 48 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index 9ae53c500f..fa3c0a6ad0 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -76,7 +76,7 @@ set listchars=eol:$ " Prevent Nvim log from writing to stderr. let $NVIM_LOG_FILE='Xnvim.log' -function RunTheTest(test) +func RunTheTest(test) echo 'Executing ' . a:test if exists("*SetUp") call SetUp() @@ -113,6 +113,60 @@ function RunTheTest(test) set nomodified endfunc +func AfterTheTest() + if len(v:errors) > 0 + let s:fail += 1 + call add(s:errors, 'Found errors in ' . s:test . ':') + call extend(s:errors, v:errors) + let v:errors = [] + endif +endfunc + +" This function can be called by a test if it wants to abort testing. +func FinishTesting() + call AfterTheTest() + + " Don't write viminfo on exit. + set viminfo= + + if s:fail == 0 + " Success, create the .res file so that make knows it's done. + exe 'split ' . fnamemodify(g:testname, ':r') . '.res' + write + endif + + if len(s:errors) > 0 + " Append errors to test.log + split test.log + call append(line('$'), '') + call append(line('$'), 'From ' . g:testname . ':') + call append(line('$'), s:errors) + write + endif + + let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test') + echo message + call add(s:messages, message) + if s:fail > 0 + let message = s:fail . ' FAILED:' + echo message + call add(s:messages, message) + call extend(s:messages, s:errors) + endif + + " Add SKIPPED messages + call extend(s:messages, s:skipped) + + " Append messages to the file "messages" + split messages + call append(line('$'), '') + call append(line('$'), 'From ' . g:testname . ':') + call append(line('$'), s:messages) + write + + qall! +endfunc + " Source the test script. First grab the file name, in case the script " navigates away. g:testname can be used by the tests. let g:testname = expand('%') @@ -157,56 +211,14 @@ for s:test in sort(s:tests) call RunTheTest(s:test) if len(v:errors) > 0 && index(s:flaky, s:test) >= 0 - call add(s:messages, 'Flaky test failed, running it again') - let v:errors = [] - call RunTheTest(s:test) - endif - - if len(v:errors) > 0 - let s:fail += 1 - call add(s:errors, 'Found errors in ' . s:test . ':') - call extend(s:errors, v:errors) + call add(s:messages, 'Flaky test failed, running it again') let v:errors = [] + call RunTheTest(s:test) endif + call AfterTheTest() endfor -" Don't write viminfo on exit. -set viminfo= - -if s:fail == 0 - " Success, create the .res file so that make knows it's done. - exe 'split ' . fnamemodify(g:testname, ':r') . '.res' - write -endif - -if len(s:errors) > 0 - " Append errors to test.log - split test.log - call append(line('$'), '') - call append(line('$'), 'From ' . g:testname . ':') - call append(line('$'), s:errors) - write -endif - -let message = 'Executed ' . s:done . (s:done > 1 ? ' tests': ' test') -echo message -call add(s:messages, message) -if s:fail > 0 - let message = s:fail . ' FAILED' - echo message - call add(s:messages, message) - call extend(s:messages, s:errors) -endif - -" Add SKIPPED messages -call extend(s:messages, s:skipped) - -" Append messages to the file "messages" -split messages -call append(line('$'), '') -call append(line('$'), 'From ' . g:testname . ':') -call append(line('$'), s:messages) -write +call FinishTesting() -qall! +" vim: shiftwidth=2 sts=2 expandtab -- cgit From d707b2a1711a02307a02684904b12b74cfb2ea32 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 5 Jun 2017 23:41:46 -0400 Subject: vim-patch:8.0.0478 Problem: Tests use assert_true(0) and assert_false(1) to report errors. Solution: Use assert_report(). https://github.com/vim/vim/commit/37175409d766ce67f2548dffa6d73451379b5737 --- src/nvim/testdir/test_cscope.vim | 2 +- src/nvim/testdir/test_cursor_func.vim | 8 +------- src/nvim/testdir/test_expr.vim | 2 +- src/nvim/testdir/test_menu.vim | 2 +- src/nvim/testdir/test_popup.vim | 2 +- 5 files changed, 5 insertions(+), 11 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cscope.vim b/src/nvim/testdir/test_cscope.vim index c8d2ebd7da..01a9a3f9ad 100644 --- a/src/nvim/testdir/test_cscope.vim +++ b/src/nvim/testdir/test_cscope.vim @@ -28,7 +28,7 @@ func Test_cscopeWithCscopeConnections() cscope add Xcscope.out set cscopeverbose catch - call assert_true(0) + call assert_report('exception thrown') endtry call assert_fails('cscope add', 'E560') call assert_fails('cscope add Xcscope.out', 'E568') diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index d819b7b092..e1b9651c84 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -1,13 +1,7 @@ " Tests for cursor(). func Test_wrong_arguments() - try - call cursor(1. 3) - " not reached - call assert_false(1) - catch - call assert_exception('E474:') - endtry + call assert_fails('call cursor(1. 3)', 'E474:') endfunc func Test_move_cursor() diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 03a9155512..ce1523324e 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -78,7 +78,7 @@ endfunc func Test_loop_over_null_list() let null_list = submatch(1, 1) for i in null_list - call assert_true(0, 'should not get here') + call assert_report('should not get here') endfor endfunc diff --git a/src/nvim/testdir/test_menu.vim b/src/nvim/testdir/test_menu.vim index be559467c8..af18760065 100644 --- a/src/nvim/testdir/test_menu.vim +++ b/src/nvim/testdir/test_menu.vim @@ -4,6 +4,6 @@ func Test_load_menu() try source $VIMRUNTIME/menu.vim catch - call assert_false(1, 'error while loading menus: ' . v:exception) + call assert_report('error while loading menus: ' . v:exception) endtry endfunc diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index fd0f3c0d2d..519d855cd8 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -533,7 +533,7 @@ func Test_completion_comment_formatting() %d try call feedkeys("o/*\\\\/\", 'tx') - call assert_false(1, 'completefunc not set, should have failed') + call assert_report('completefunc not set, should have failed') catch call assert_exception('E764:') endtry -- cgit From 5f8411b7bf706210a4ff0960032389d015b88b16 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Tue, 6 Jun 2017 05:19:28 -0400 Subject: vim-patch:8.0.0176 Problem: Using :change in between :function and :endfunction fails. Solution: Recognize :change inside a function. (ichizok, closes vim/vim#1374) https://github.com/vim/vim/commit/70bcd7336f9f19304f32c52a86ed5b4b3de852c2 --- src/nvim/testdir/test_vimscript.vim | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index a2997b6d4d..b7d12d8c93 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1064,6 +1064,77 @@ func Test_echo_and_string() endfunc +"------------------------------------------------------------------------------- +" Test 95: lines of :append, :change, :insert {{{1 +"------------------------------------------------------------------------------- + +function! DefineFunction(name, body) + let func = join(['function! ' . a:name . '()'] + a:body + ['endfunction'], "\n") + exec func +endfunction + +func Test_script_lines() + " :append + try + call DefineFunction('T_Append', [ + \ 'append', + \ 'py < Date: Tue, 6 Jun 2017 05:28:23 -0400 Subject: vim-patch:8.0.0561 Problem: Undefined behavior when using backslash after empty line. Solution: Check for an empty line. (Dominique Pelle, closes vim/vim#1631) https://github.com/vim/vim/commit/478af67dd6a9adc456464c3736bda328ae3a28cb --- src/nvim/testdir/test_vimscript.vim | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index b7d12d8c93..da3adf5e2b 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1135,6 +1135,17 @@ func Test_script_lines() endtry endfunc +"------------------------------------------------------------------------------- +" Test 96: line continuation {{{1 +" +" Undefined behavior was detected by ubsan with line continuation +" after an empty line. +"------------------------------------------------------------------------------- +func Test_script_emty_line_continuation() + + \ +endfunc + "------------------------------------------------------------------------------- " Modelines {{{1 " vim: ts=8 sw=4 tw=80 fdm=marker -- cgit From 6757c503bd6c8715cee38475c329f7daee7a760f Mon Sep 17 00:00:00 2001 From: James McCoy Date: Tue, 6 Jun 2017 07:34:25 -0400 Subject: vim-patch:8.0.0614 Problem: float2nr() is not exactly right. Solution: Make float2nr() more accurate. Turn test64 into a new style test. (Hirohito Higashi, closes vim/vim#1688) https://github.com/vim/vim/commit/863e80b4451b5102b41bebf9ddca3a420de746fa --- src/nvim/testdir/test_float_func.vim | 47 ++++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_vimscript.vim | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_float_func.vim b/src/nvim/testdir/test_float_func.vim index 07ffe96129..5ea5192994 100644 --- a/src/nvim/testdir/test_float_func.vim +++ b/src/nvim/testdir/test_float_func.vim @@ -224,6 +224,20 @@ func Test_str2float() call assert_fails("call str2float(function('string'))", 'E729:') endfunc +func Test_float2nr() + call assert_equal(1, float2nr(1.234)) + call assert_equal(123, float2nr(1.234e2)) + call assert_equal(12, float2nr(123.4e-1)) + let max_number = 1/0 + let min_number = -max_number + call assert_equal(max_number/2+1, float2nr(pow(2, 62))) + call assert_equal(max_number, float2nr(pow(2, 63))) + call assert_equal(max_number, float2nr(pow(2, 64))) + call assert_equal(min_number/2-1, float2nr(-pow(2, 62))) + call assert_equal(min_number, float2nr(-pow(2, 63))) + call assert_equal(min_number, float2nr(-pow(2, 64))) +endfunc + func Test_floor() call assert_equal('2.0', string(floor(2.0))) call assert_equal('2.0', string(floor(2.11))) @@ -283,3 +297,36 @@ func Test_isnan() call assert_equal(0, isnan([])) call assert_equal(0, isnan({})) endfunc + +" This was converted from test65 +func Test_float_misc() + call assert_equal('123.456000', printf('%f', 123.456)) + call assert_equal('1.234560e+02', printf('%e', 123.456)) + call assert_equal('123.456', printf('%g', 123.456)) + " += + let v = 1.234 + let v += 6.543 + call assert_equal('7.777', printf('%g', v)) + let v = 1.234 + let v += 5 + call assert_equal('6.234', printf('%g', v)) + let v = 5 + let v += 3.333 + call assert_equal('8.333', string(v)) + " == + let v = 1.234 + call assert_true(v == 1.234) + call assert_false(v == 1.2341) + " add-subtract + call assert_equal('5.234', printf('%g', 4 + 1.234)) + call assert_equal('-6.766', printf('%g', 1.234 - 8)) + " mult-div + call assert_equal('4.936', printf('%g', 4 * 1.234)) + call assert_equal('0.003241', printf('%g', 4.0 / 1234)) + " dict + call assert_equal("{'x': 1.234, 'y': -2.0e20}", string({'x': 1.234, 'y': -2.0e20})) + " list + call assert_equal('[-123.4, 2.0e-20]', string([-123.4, 2.0e-20])) +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index 13e4793b26..4e0f1bbd2f 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1172,6 +1172,49 @@ func Test_script_emty_line_continuation() \ endfunc +"------------------------------------------------------------------------------- +" Test 97: bitwise functions {{{1 +"------------------------------------------------------------------------------- +func Test_bitwise_functions() + " and + call assert_equal(127, and(127, 127)) + call assert_equal(16, and(127, 16)) + call assert_equal(0, and(127, 128)) + call assert_fails("call and(1.0, 1)", 'E805:') + call assert_fails("call and([], 1)", 'E745:') + call assert_fails("call and({}, 1)", 'E728:') + call assert_fails("call and(1, 1.0)", 'E805:') + call assert_fails("call and(1, [])", 'E745:') + call assert_fails("call and(1, {})", 'E728:') + " or + call assert_equal(23, or(16, 7)) + call assert_equal(15, or(8, 7)) + call assert_equal(123, or(0, 123)) + call assert_fails("call or(1.0, 1)", 'E805:') + call assert_fails("call or([], 1)", 'E745:') + call assert_fails("call or({}, 1)", 'E728:') + call assert_fails("call or(1, 1.0)", 'E805:') + call assert_fails("call or(1, [])", 'E745:') + call assert_fails("call or(1, {})", 'E728:') + " xor + call assert_equal(0, xor(127, 127)) + call assert_equal(111, xor(127, 16)) + call assert_equal(255, xor(127, 128)) + call assert_fails("call xor(1.0, 1)", 'E805:') + call assert_fails("call xor([], 1)", 'E745:') + call assert_fails("call xor({}, 1)", 'E728:') + call assert_fails("call xor(1, 1.0)", 'E805:') + call assert_fails("call xor(1, [])", 'E745:') + call assert_fails("call xor(1, {})", 'E728:') + " invert + call assert_equal(65408, and(invert(127), 65535)) + call assert_equal(65519, and(invert(16), 65535)) + call assert_equal(65407, and(invert(128), 65535)) + call assert_fails("call invert(1.0)", 'E805:') + call assert_fails("call invert([])", 'E745:') + call assert_fails("call invert({})", 'E728:') +endfunc + "------------------------------------------------------------------------------- " Modelines {{{1 " vim: ts=8 sw=4 tw=80 fdm=marker -- cgit From eb6dd3e42dc38460e8624dc5faef894e21c6aa26 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 30 May 2017 14:54:09 +0200 Subject: ci: Dump $NVIM_LOG_FILE contents --- src/nvim/testdir/runtest.vim | 2 +- src/nvim/testdir/shared.vim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index fa3c0a6ad0..117ba52eb6 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -74,7 +74,7 @@ set backspace= set nohidden smarttab noautoindent noautoread complete-=i noruler noshowcmd set listchars=eol:$ " Prevent Nvim log from writing to stderr. -let $NVIM_LOG_FILE='Xnvim.log' +let $NVIM_LOG_FILE = exists($NVIM_LOG_FILE) ? $NVIM_LOG_FILE : 'Xnvim.log' func RunTheTest(test) echo 'Executing ' . a:test diff --git a/src/nvim/testdir/shared.vim b/src/nvim/testdir/shared.vim index 784e4a0a02..72cfea96c6 100644 --- a/src/nvim/testdir/shared.vim +++ b/src/nvim/testdir/shared.vim @@ -187,7 +187,7 @@ func RunVim(before, after, arguments) endfunc func RunVimPiped(before, after, arguments, pipecmd) - let $NVIM_LOG_FILE='Xnvim.log' + let $NVIM_LOG_FILE = exists($NVIM_LOG_FILE) ? $NVIM_LOG_FILE : 'Xnvim.log' let cmd = GetVimCommand() if cmd == '' return 0 -- cgit From 6650588c4a89616249e964631dad17a66e1c6592 Mon Sep 17 00:00:00 2001 From: Shougo Date: Mon, 12 Jun 2017 07:44:21 +0900 Subject: vim-patch:7.4.2190 (#6882) Problem: When startup test fails it's not easy to find out why. GUI test fails with Gnome. Solution: Add the help entry matches to a list an assert that. Set $HOME for Gnome to create .gnome2 directory. https://github.com/vim/vim/commit/50fa8dd00c241fa0786fe92ecc02fee4e5d28e06 --- src/nvim/testdir/test_startup.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index f78d92f3ff..5996b2cd4a 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -83,7 +83,7 @@ func Test_help_arg() call add(found, "--version") endif endfor - call assert_equal(['--version'], found) + call assert_equal(['Readonly mode', '--version'], found) endif call delete('Xtestout') endfunc -- cgit From 694eb18e03a6a73321aafc19aa2f28104bdf3b8b Mon Sep 17 00:00:00 2001 From: Shougo Date: Mon, 19 Jun 2017 08:13:32 +0900 Subject: vim-patch:7.4.2356 (#6880) Problem: Reading past end of line when using previous substitute pattern. (Dominique Pelle) Solution: Don't set "pat" only set "searchstr". https://github.com/vim/vim/commit/ea683da58cf9ecf3afab9d650d3d2da76e5298d3 --- src/nvim/testdir/Makefile | 1 + src/nvim/testdir/test_search.vim | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/nvim/testdir/test_search.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 3482001f63..7e55fffa06 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -58,6 +58,7 @@ NEW_TESTS ?= \ test_nested_function.res \ test_normal.res \ test_quickfix.res \ + test_search.res \ test_signs.res \ test_smartindent.res \ test_stat.res \ diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim new file mode 100644 index 0000000000..e85525e663 --- /dev/null +++ b/src/nvim/testdir/test_search.vim @@ -0,0 +1,12 @@ +" Test for the search command + +func Test_use_sub_pat() + split + let @/ = '' + func X() + s/^/a/ + / + endfunc + call X() + bwipe! +endfunc -- cgit From 7955cf35158f56a207ece32127adece23fd0fba1 Mon Sep 17 00:00:00 2001 From: raichoo Date: Sat, 25 Mar 2017 14:09:31 +0100 Subject: vim-patch:7.4.2259 Problem: With 'incsearch' can only see the next match. Solution: Make CTRL-N/CTRL-P move to the previous/next match. (Christian Brabandt) https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7 --- src/nvim/testdir/test_search.vim | 243 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index e85525e663..9c29236ac9 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -1,5 +1,248 @@ " Test for the search command +func Test_search_cmdline() + throw 'skipped: Nvim does not support test_disable_char_avail()' + if !exists('+incsearch') + return + endif + " need to disable char_avail, + " so that expansion of commandline works + call test_disable_char_avail(1) + new + call setline(1, [' 1', ' 2 these', ' 3 the', ' 4 their', ' 5 there', ' 6 their', ' 7 the', ' 8 them', ' 9 these', ' 10 foobar']) + " Test 1 + " CTRL-N / CTRL-P skips through the previous search history + set noincsearch + :1 + call feedkeys("/foobar\", 'tx') + call feedkeys("/the\",'tx') + call assert_equal('the', @/) + call feedkeys("/thes\\\",'tx') + call assert_equal('foobar', @/) + + " Test 2 + " Ctrl-N goes from one match to the next + " until the end of the buffer + set incsearch nowrapscan + :1 + " first match + call feedkeys("/the\", 'tx') + call assert_equal(' 2 these', getline('.')) + :1 + " second match + call feedkeys("/the\\", 'tx') + call assert_equal(' 3 the', getline('.')) + :1 + " third match + call feedkeys("/the".repeat("\", 2)."\", 'tx') + call assert_equal(' 4 their', getline('.')) + :1 + " fourth match + call feedkeys("/the".repeat("\", 3)."\", 'tx') + call assert_equal(' 5 there', getline('.')) + :1 + " fifth match + call feedkeys("/the".repeat("\", 4)."\", 'tx') + call assert_equal(' 6 their', getline('.')) + :1 + " sixth match + call feedkeys("/the".repeat("\", 5)."\", 'tx') + call assert_equal(' 7 the', getline('.')) + :1 + " seventh match + call feedkeys("/the".repeat("\", 6)."\", 'tx') + call assert_equal(' 8 them', getline('.')) + :1 + " eigth match + call feedkeys("/the".repeat("\", 7)."\", 'tx') + call assert_equal(' 9 these', getline('.')) + :1 + " no further match + call feedkeys("/the".repeat("\", 8)."\", 'tx') + call assert_equal(' 9 these', getline('.')) + + " Test 3 + " Ctrl-N goes from one match to the next + " and continues back at the top + set incsearch wrapscan + :1 + " first match + call feedkeys("/the\", 'tx') + call assert_equal(' 2 these', getline('.')) + :1 + " second match + call feedkeys("/the\\", 'tx') + call assert_equal(' 3 the', getline('.')) + :1 + " third match + call feedkeys("/the".repeat("\", 2)."\", 'tx') + call assert_equal(' 4 their', getline('.')) + :1 + " fourth match + call feedkeys("/the".repeat("\", 3)."\", 'tx') + call assert_equal(' 5 there', getline('.')) + :1 + " fifth match + call feedkeys("/the".repeat("\", 4)."\", 'tx') + call assert_equal(' 6 their', getline('.')) + :1 + " sixth match + call feedkeys("/the".repeat("\", 5)."\", 'tx') + call assert_equal(' 7 the', getline('.')) + :1 + " seventh match + call feedkeys("/the".repeat("\", 6)."\", 'tx') + call assert_equal(' 8 them', getline('.')) + :1 + " eigth match + call feedkeys("/the".repeat("\", 7)."\", 'tx') + call assert_equal(' 9 these', getline('.')) + :1 + " back at first match + call feedkeys("/the".repeat("\", 8)."\", 'tx') + call assert_equal(' 2 these', getline('.')) + + " Test 4 + " CTRL-P goes to the previous match + set incsearch nowrapscan + $ + " first match + call feedkeys("?the\", 'tx') + call assert_equal(' 9 these', getline('.')) + $ + " first match + call feedkeys("?the\\", 'tx') + call assert_equal(' 9 these', getline('.')) + $ + " second match + call feedkeys("?the".repeat("\", 1)."\", 'tx') + call assert_equal(' 8 them', getline('.')) + $ + " last match + call feedkeys("?the".repeat("\", 7)."\", 'tx') + call assert_equal(' 2 these', getline('.')) + $ + " last match + call feedkeys("?the".repeat("\", 8)."\", 'tx') + call assert_equal(' 2 these', getline('.')) + + " Test 5 + " CTRL-P goes to the previous match + set incsearch wrapscan + $ + " first match + call feedkeys("?the\", 'tx') + call assert_equal(' 9 these', getline('.')) + $ + " first match at the top + call feedkeys("?the\\", 'tx') + call assert_equal(' 2 these', getline('.')) + $ + " second match + call feedkeys("?the".repeat("\", 1)."\", 'tx') + call assert_equal(' 8 them', getline('.')) + $ + " last match + call feedkeys("?the".repeat("\", 7)."\", 'tx') + call assert_equal(' 2 these', getline('.')) + $ + " back at the bottom of the buffer + call feedkeys("?the".repeat("\", 8)."\", 'tx') + call assert_equal(' 9 these', getline('.')) + + " Test 6 + " CTRL-L adds to the search pattern + set incsearch wrapscan + 1 + " first match + call feedkeys("/the\\", 'tx') + call assert_equal(' 2 these', getline('.')) + 1 + " go to next match of 'thes' + call feedkeys("/the\\\", 'tx') + call assert_equal(' 9 these', getline('.')) + 1 + " wrap around + call feedkeys("/the\\\\", 'tx') + call assert_equal(' 2 these', getline('.')) + 1 + " wrap around + set nowrapscan + call feedkeys("/the\\\\", 'tx') + call assert_equal(' 9 these', getline('.')) + + " Test 7 + " remove from match, but stay at current match + set incsearch wrapscan + 1 + " first match + call feedkeys("/thei\", 'tx') + call assert_equal(' 4 their', getline('.')) + 1 + " delete one char, add another + call feedkeys("/thei\s\", 'tx') + call assert_equal(' 9 these', getline('.')) + 1 + " delete one char, add another, go to previous match, add one char + call feedkeys("/thei\s\\\\", 'tx') + call assert_equal(' 8 them', getline('.')) + 1 + " delete all chars, start from the beginning again + call feedkeys("/them". repeat("\",4).'the\>'."\", 'tx') + call assert_equal(' 3 the', getline('.')) + + " clean up + call test_disable_char_avail(0) + bw! +endfunc + +func Test_search_cmdline2() + throw 'skipped: Nvim does not support test_disable_char_avail()' + if !exists('+incsearch') + return + endif + " need to disable char_avail, + " so that expansion of commandline works + call test_disable_char_avail(1) + new + call setline(1, [' 1', ' 2 these', ' 3 the theother']) + " Test 1 + " Ctrl-P goes correctly back and forth + set incsearch + 1 + " first match + call feedkeys("/the\", 'tx') + call assert_equal(' 2 these', getline('.')) + 1 + " go to next match (on next line) + call feedkeys("/the\\", 'tx') + call assert_equal(' 3 the theother', getline('.')) + 1 + " go to next match (still on line 3) + call feedkeys("/the\\\", 'tx') + call assert_equal(' 3 the theother', getline('.')) + 1 + " go to next match (still on line 3) + call feedkeys("/the\\\\", 'tx') + call assert_equal(' 3 the theother', getline('.')) + 1 + " go to previous match (on line 3) + call feedkeys("/the\\\\\", 'tx') + call assert_equal(' 3 the theother', getline('.')) + 1 + " go to previous match (on line 3) + call feedkeys("/the\\\\\\", 'tx') + call assert_equal(' 3 the theother', getline('.')) + 1 + " go to previous match (on line 2) + call feedkeys("/the\\\\\\\", 'tx') + call assert_equal(' 2 these', getline('.')) + + " clean up + call test_disable_char_avail(0) + bw! +endfunc + func Test_use_sub_pat() split let @/ = '' -- cgit From 518b42db916ccbb9057ca9361b48e83ea65bc3b9 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 14 Jun 2017 22:51:50 -0400 Subject: functests/legacy: Add lua version of test_search.vim --- src/nvim/testdir/test_search.vim | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 9c29236ac9..1398cc4d4e 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -1,6 +1,7 @@ " Test for the search command func Test_search_cmdline() + " See test/functional/legacy/search_spec.lua throw 'skipped: Nvim does not support test_disable_char_avail()' if !exists('+incsearch') return @@ -197,6 +198,7 @@ func Test_search_cmdline() endfunc func Test_search_cmdline2() + " See test/functional/legacy/search_spec.lua throw 'skipped: Nvim does not support test_disable_char_avail()' if !exists('+incsearch') return -- cgit From 0dd64556590633b2cab7cd846b28bbf5f7ef35d4 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 25 Jun 2017 11:01:16 -0400 Subject: vim-patch:7.4.2268 Problem: Using CTRL-N and CTRL-P for incsearch shadows completion keys. Solution: Use CTRL-T and CTRL-G instead. https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8 --- src/nvim/testdir/test_search.vim | 80 ++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 1398cc4d4e..28e504a883 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -18,11 +18,11 @@ func Test_search_cmdline() call feedkeys("/foobar\", 'tx') call feedkeys("/the\",'tx') call assert_equal('the', @/) - call feedkeys("/thes\\\",'tx') + call feedkeys("/thes\\\",'tx') call assert_equal('foobar', @/) " Test 2 - " Ctrl-N goes from one match to the next + " Ctrl-G goes from one match to the next " until the end of the buffer set incsearch nowrapscan :1 @@ -31,39 +31,39 @@ func Test_search_cmdline() call assert_equal(' 2 these', getline('.')) :1 " second match - call feedkeys("/the\\", 'tx') + call feedkeys("/the\\", 'tx') call assert_equal(' 3 the', getline('.')) :1 " third match - call feedkeys("/the".repeat("\", 2)."\", 'tx') + call feedkeys("/the".repeat("\", 2)."\", 'tx') call assert_equal(' 4 their', getline('.')) :1 " fourth match - call feedkeys("/the".repeat("\", 3)."\", 'tx') + call feedkeys("/the".repeat("\", 3)."\", 'tx') call assert_equal(' 5 there', getline('.')) :1 " fifth match - call feedkeys("/the".repeat("\", 4)."\", 'tx') + call feedkeys("/the".repeat("\", 4)."\", 'tx') call assert_equal(' 6 their', getline('.')) :1 " sixth match - call feedkeys("/the".repeat("\", 5)."\", 'tx') + call feedkeys("/the".repeat("\", 5)."\", 'tx') call assert_equal(' 7 the', getline('.')) :1 " seventh match - call feedkeys("/the".repeat("\", 6)."\", 'tx') + call feedkeys("/the".repeat("\", 6)."\", 'tx') call assert_equal(' 8 them', getline('.')) :1 " eigth match - call feedkeys("/the".repeat("\", 7)."\", 'tx') + call feedkeys("/the".repeat("\", 7)."\", 'tx') call assert_equal(' 9 these', getline('.')) :1 " no further match - call feedkeys("/the".repeat("\", 8)."\", 'tx') + call feedkeys("/the".repeat("\", 8)."\", 'tx') call assert_equal(' 9 these', getline('.')) " Test 3 - " Ctrl-N goes from one match to the next + " Ctrl-G goes from one match to the next " and continues back at the top set incsearch wrapscan :1 @@ -72,39 +72,39 @@ func Test_search_cmdline() call assert_equal(' 2 these', getline('.')) :1 " second match - call feedkeys("/the\\", 'tx') + call feedkeys("/the\\", 'tx') call assert_equal(' 3 the', getline('.')) :1 " third match - call feedkeys("/the".repeat("\", 2)."\", 'tx') + call feedkeys("/the".repeat("\", 2)."\", 'tx') call assert_equal(' 4 their', getline('.')) :1 " fourth match - call feedkeys("/the".repeat("\", 3)."\", 'tx') + call feedkeys("/the".repeat("\", 3)."\", 'tx') call assert_equal(' 5 there', getline('.')) :1 " fifth match - call feedkeys("/the".repeat("\", 4)."\", 'tx') + call feedkeys("/the".repeat("\", 4)."\", 'tx') call assert_equal(' 6 their', getline('.')) :1 " sixth match - call feedkeys("/the".repeat("\", 5)."\", 'tx') + call feedkeys("/the".repeat("\", 5)."\", 'tx') call assert_equal(' 7 the', getline('.')) :1 " seventh match - call feedkeys("/the".repeat("\", 6)."\", 'tx') + call feedkeys("/the".repeat("\", 6)."\", 'tx') call assert_equal(' 8 them', getline('.')) :1 " eigth match - call feedkeys("/the".repeat("\", 7)."\", 'tx') + call feedkeys("/the".repeat("\", 7)."\", 'tx') call assert_equal(' 9 these', getline('.')) :1 " back at first match - call feedkeys("/the".repeat("\", 8)."\", 'tx') + call feedkeys("/the".repeat("\", 8)."\", 'tx') call assert_equal(' 2 these', getline('.')) " Test 4 - " CTRL-P goes to the previous match + " CTRL-T goes to the previous match set incsearch nowrapscan $ " first match @@ -112,23 +112,23 @@ func Test_search_cmdline() call assert_equal(' 9 these', getline('.')) $ " first match - call feedkeys("?the\\", 'tx') + call feedkeys("?the\\", 'tx') call assert_equal(' 9 these', getline('.')) $ " second match - call feedkeys("?the".repeat("\", 1)."\", 'tx') + call feedkeys("?the".repeat("\", 1)."\", 'tx') call assert_equal(' 8 them', getline('.')) $ " last match - call feedkeys("?the".repeat("\", 7)."\", 'tx') + call feedkeys("?the".repeat("\", 7)."\", 'tx') call assert_equal(' 2 these', getline('.')) $ " last match - call feedkeys("?the".repeat("\", 8)."\", 'tx') + call feedkeys("?the".repeat("\", 8)."\", 'tx') call assert_equal(' 2 these', getline('.')) " Test 5 - " CTRL-P goes to the previous match + " CTRL-T goes to the previous match set incsearch wrapscan $ " first match @@ -136,19 +136,19 @@ func Test_search_cmdline() call assert_equal(' 9 these', getline('.')) $ " first match at the top - call feedkeys("?the\\", 'tx') + call feedkeys("?the\\", 'tx') call assert_equal(' 2 these', getline('.')) $ " second match - call feedkeys("?the".repeat("\", 1)."\", 'tx') + call feedkeys("?the".repeat("\", 1)."\", 'tx') call assert_equal(' 8 them', getline('.')) $ " last match - call feedkeys("?the".repeat("\", 7)."\", 'tx') + call feedkeys("?the".repeat("\", 7)."\", 'tx') call assert_equal(' 2 these', getline('.')) $ " back at the bottom of the buffer - call feedkeys("?the".repeat("\", 8)."\", 'tx') + call feedkeys("?the".repeat("\", 8)."\", 'tx') call assert_equal(' 9 these', getline('.')) " Test 6 @@ -160,16 +160,16 @@ func Test_search_cmdline() call assert_equal(' 2 these', getline('.')) 1 " go to next match of 'thes' - call feedkeys("/the\\\", 'tx') + call feedkeys("/the\\\", 'tx') call assert_equal(' 9 these', getline('.')) 1 " wrap around - call feedkeys("/the\\\\", 'tx') + call feedkeys("/the\\\\", 'tx') call assert_equal(' 2 these', getline('.')) 1 " wrap around set nowrapscan - call feedkeys("/the\\\\", 'tx') + call feedkeys("/the\\\\", 'tx') call assert_equal(' 9 these', getline('.')) " Test 7 @@ -185,7 +185,7 @@ func Test_search_cmdline() call assert_equal(' 9 these', getline('.')) 1 " delete one char, add another, go to previous match, add one char - call feedkeys("/thei\s\\\\", 'tx') + call feedkeys("/thei\s\\\\", 'tx') call assert_equal(' 8 them', getline('.')) 1 " delete all chars, start from the beginning again @@ -209,7 +209,7 @@ func Test_search_cmdline2() new call setline(1, [' 1', ' 2 these', ' 3 the theother']) " Test 1 - " Ctrl-P goes correctly back and forth + " Ctrl-T goes correctly back and forth set incsearch 1 " first match @@ -217,27 +217,27 @@ func Test_search_cmdline2() call assert_equal(' 2 these', getline('.')) 1 " go to next match (on next line) - call feedkeys("/the\\", 'tx') + call feedkeys("/the\\", 'tx') call assert_equal(' 3 the theother', getline('.')) 1 " go to next match (still on line 3) - call feedkeys("/the\\\", 'tx') + call feedkeys("/the\\\", 'tx') call assert_equal(' 3 the theother', getline('.')) 1 " go to next match (still on line 3) - call feedkeys("/the\\\\", 'tx') + call feedkeys("/the\\\\", 'tx') call assert_equal(' 3 the theother', getline('.')) 1 " go to previous match (on line 3) - call feedkeys("/the\\\\\", 'tx') + call feedkeys("/the\\\\\", 'tx') call assert_equal(' 3 the theother', getline('.')) 1 " go to previous match (on line 3) - call feedkeys("/the\\\\\\", 'tx') + call feedkeys("/the\\\\\\", 'tx') call assert_equal(' 3 the theother', getline('.')) 1 " go to previous match (on line 2) - call feedkeys("/the\\\\\\\", 'tx') + call feedkeys("/the\\\\\\\", 'tx') call assert_equal(' 2 these', getline('.')) " clean up -- cgit From 54d5e90a2b87736a3248300ed423374e88ce8e79 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 25 Jun 2017 12:15:58 -0400 Subject: vim-patch:7.4.2320 Problem: Redraw problem when using 'incsearch'. Solution: Save the current view when deleting characters. (Christian Brabandt) Fix that the '" mark is set in the wrong position. Don't change the search start when using BS. https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b --- src/nvim/testdir/test_search.vim | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 28e504a883..2106fc2dec 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -33,6 +33,7 @@ func Test_search_cmdline() " second match call feedkeys("/the\\", 'tx') call assert_equal(' 3 the', getline('.')) + call assert_equal([0, 0, 0, 0], getpos('"')) :1 " third match call feedkeys("/the".repeat("\", 2)."\", 'tx') @@ -61,6 +62,7 @@ func Test_search_cmdline() " no further match call feedkeys("/the".repeat("\", 8)."\", 'tx') call assert_equal(' 9 these', getline('.')) + call assert_equal([0, 0, 0, 0], getpos('"')) " Test 3 " Ctrl-G goes from one match to the next @@ -182,11 +184,11 @@ func Test_search_cmdline() 1 " delete one char, add another call feedkeys("/thei\s\", 'tx') - call assert_equal(' 9 these', getline('.')) + call assert_equal(' 2 these', getline('.')) 1 " delete one char, add another, go to previous match, add one char call feedkeys("/thei\s\\\\", 'tx') - call assert_equal(' 8 them', getline('.')) + call assert_equal(' 9 these', getline('.')) 1 " delete all chars, start from the beginning again call feedkeys("/them". repeat("\",4).'the\>'."\", 'tx') @@ -240,7 +242,33 @@ func Test_search_cmdline2() call feedkeys("/the\\\\\\\", 'tx') call assert_equal(' 2 these', getline('.')) + " Test 2: keep the view, + " after deleting a character from the search cmd + call setline(1, [' 1', ' 2 these', ' 3 the', ' 4 their', ' 5 there', ' 6 their', ' 7 the', ' 8 them', ' 9 these', ' 10 foobar']) + resize 5 + 1 + call feedkeys("/foo\\", 'tx') + redraw + call assert_equal({'lnum': 10, 'leftcol': 0, 'col': 4, 'topfill': 0, 'topline': 6, 'coladd': 0, 'skipcol': 0, 'curswant': 4}, winsaveview()) + + " remove all history entries + for i in range(10) + call histdel('/') + endfor + + " Test 3: reset the view, + " after deleting all characters from the search cmd + norm! 1gg0 + " unfortunately, neither "/foo\\", nor "/foo\\\\", + " nor "/foo\\" works to delete the commandline. + " In that case Vim should return "E35 no previous regular expression", + " but it looks like Vim still sees /foo and therefore the test fails. + " Therefore, disableing this test + "call assert_fails(feedkeys("/foo\\", 'tx'), 'E35') + "call assert_equal({'lnum': 1, 'leftcol': 0, 'col': 0, 'topfill': 0, 'topline': 1, 'coladd': 0, 'skipcol': 0, 'curswant': 0}, winsaveview()) + " clean up + set noincsearch call test_disable_char_avail(0) bw! endfunc -- cgit