comparison src/testdir/test_ins_complete.vim @ 27457:4c16acb2525f v8.2.4257

patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent Commit: https://github.com/vim/vim/commit/62aec93bfdb9e1b40d03a6d2e8e9511f8b1bdb2d Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 29 21:45:34 2022 +0000 patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent Problem: Vim9: finding global function without g: prefix but not finding global variable is inconsistent. Solution: Require using g: for a global function. Change the vim9.vim script into a Vim9 script with exports. Fix that import in legacy script does not work.
author Bram Moolenaar <Bram@vim.org>
date Sat, 29 Jan 2022 23:00:05 +0100
parents 1d9a7aa42744
children a14c4d3e3260
comparison
equal deleted inserted replaced
27456:a8e2d91995ce 27457:4c16acb2525f
1 " Test for insert completion 1 " Test for insert completion
2 2
3 source screendump.vim 3 source screendump.vim
4 source check.vim 4 source check.vim
5 source vim9.vim 5 import './vim9.vim' as v9
6 6
7 " Test for insert expansion 7 " Test for insert expansion
8 func Test_ins_complete() 8 func Test_ins_complete()
9 edit test_ins_complete.vim 9 edit test_ins_complete.vim
10 " The files in the current directory interferes with the files 10 " The files in the current directory interferes with the files
1357 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 1357 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
1358 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:CompleteFunc1Args) 1358 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:CompleteFunc1Args)
1359 bw! 1359 bw!
1360 1360
1361 #" Test for using a lambda function with set 1361 #" Test for using a lambda function with set
1362 VAR optval = "LSTART a, b LMIDDLE CompleteFunc1(16, a, b) LEND" 1362 VAR optval = "LSTART a, b LMIDDLE g:CompleteFunc1(16, a, b) LEND"
1363 LET optval = substitute(optval, ' ', '\\ ', 'g') 1363 LET optval = substitute(optval, ' ', '\\ ', 'g')
1364 exe "set completefunc=" .. optval 1364 exe "set completefunc=" .. optval
1365 new 1365 new
1366 call setline(1, 'five') 1366 call setline(1, 'five')
1367 LET g:CompleteFunc1Args = [] 1367 LET g:CompleteFunc1Args = []
1368 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 1368 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
1369 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:CompleteFunc1Args) 1369 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:CompleteFunc1Args)
1370 bw! 1370 bw!
1371 1371
1372 #" Set 'completefunc' to a lambda expression 1372 #" Set 'completefunc' to a lambda expression
1373 LET &completefunc = LSTART a, b LMIDDLE CompleteFunc1(17, a, b) LEND 1373 LET &completefunc = LSTART a, b LMIDDLE g:CompleteFunc1(17, a, b) LEND
1374 new 1374 new
1375 call setline(1, 'six') 1375 call setline(1, 'six')
1376 LET g:CompleteFunc1Args = [] 1376 LET g:CompleteFunc1Args = []
1377 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 1377 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
1378 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:CompleteFunc1Args) 1378 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:CompleteFunc1Args)
1379 bw! 1379 bw!
1380 1380
1381 #" Set 'completefunc' to string(lambda_expression) 1381 #" Set 'completefunc' to string(lambda_expression)
1382 LET &completefunc = 'LSTART a, b LMIDDLE CompleteFunc1(18, a, b) LEND' 1382 LET &completefunc = 'LSTART a, b LMIDDLE g:CompleteFunc1(18, a, b) LEND'
1383 new 1383 new
1384 call setline(1, 'six') 1384 call setline(1, 'six')
1385 LET g:CompleteFunc1Args = [] 1385 LET g:CompleteFunc1Args = []
1386 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 1386 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
1387 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:CompleteFunc1Args) 1387 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:CompleteFunc1Args)
1388 bw! 1388 bw!
1389 1389
1390 #" Set 'completefunc' to a variable with a lambda expression 1390 #" Set 'completefunc' to a variable with a lambda expression
1391 VAR Lambda = LSTART a, b LMIDDLE CompleteFunc1(19, a, b) LEND 1391 VAR Lambda = LSTART a, b LMIDDLE g:CompleteFunc1(19, a, b) LEND
1392 LET &completefunc = Lambda 1392 LET &completefunc = Lambda
1393 new 1393 new
1394 call setline(1, 'seven') 1394 call setline(1, 'seven')
1395 LET g:CompleteFunc1Args = [] 1395 LET g:CompleteFunc1Args = []
1396 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 1396 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
1397 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:CompleteFunc1Args) 1397 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:CompleteFunc1Args)
1398 bw! 1398 bw!
1399 1399
1400 #" Set 'completefunc' to a string(variable with a lambda expression) 1400 #" Set 'completefunc' to a string(variable with a lambda expression)
1401 LET Lambda = LSTART a, b LMIDDLE CompleteFunc1(20, a, b) LEND 1401 LET Lambda = LSTART a, b LMIDDLE g:CompleteFunc1(20, a, b) LEND
1402 LET &completefunc = string(Lambda) 1402 LET &completefunc = string(Lambda)
1403 new 1403 new
1404 call setline(1, 'seven') 1404 call setline(1, 'seven')
1405 LET g:CompleteFunc1Args = [] 1405 LET g:CompleteFunc1Args = []
1406 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 1406 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
1429 LET g:CompleteFunc2Args = [] 1429 LET g:CompleteFunc2Args = []
1430 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 1430 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
1431 call assert_equal([[1, ''], [0, 'five']], g:CompleteFunc2Args) 1431 call assert_equal([[1, ''], [0, 'five']], g:CompleteFunc2Args)
1432 bw! 1432 bw!
1433 END 1433 END
1434 call CheckLegacyAndVim9Success(lines) 1434 call v9.CheckLegacyAndVim9Success(lines)
1435 1435
1436 " Test for using a script-local function name 1436 " Test for using a script-local function name
1437 func s:CompleteFunc3(findstart, base) 1437 func s:CompleteFunc3(findstart, base)
1438 call add(g:CompleteFunc3Args, [a:findstart, a:base]) 1438 call add(g:CompleteFunc3Args, [a:findstart, a:base])
1439 return a:findstart ? 0 : [] 1439 return a:findstart ? 0 : []
1458 " invalid return value 1458 " invalid return value
1459 let &completefunc = {a -> 'abc'} 1459 let &completefunc = {a -> 'abc'}
1460 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 1460 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
1461 1461
1462 " Using Vim9 lambda expression in legacy context should fail 1462 " Using Vim9 lambda expression in legacy context should fail
1463 set completefunc=(a,\ b)\ =>\ CompleteFunc1(21,\ a,\ b) 1463 set completefunc=(a,\ b)\ =>\ g:CompleteFunc1(21,\ a,\ b)
1464 new | only 1464 new | only
1465 let g:CompleteFunc1Args = [] 1465 let g:CompleteFunc1Args = []
1466 call assert_fails('call feedkeys("A\<C-X>\<C-U>\<Esc>", "x")', 'E117:') 1466 call assert_fails('call feedkeys("A\<C-X>\<C-U>\<Esc>", "x")', 'E117:')
1467 call assert_equal([], g:CompleteFunc1Args) 1467 call assert_equal([], g:CompleteFunc1Args)
1468 1468
1524 g:LocalCompleteFuncArgs = [] 1524 g:LocalCompleteFuncArgs = []
1525 feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 1525 feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
1526 assert_equal([[1, ''], [0, 'three']], g:LocalCompleteFuncArgs) 1526 assert_equal([[1, ''], [0, 'three']], g:LocalCompleteFuncArgs)
1527 bw! 1527 bw!
1528 END 1528 END
1529 call CheckScriptSuccess(lines) 1529 call v9.CheckScriptSuccess(lines)
1530 1530
1531 " cleanup 1531 " cleanup
1532 set completefunc& 1532 set completefunc&
1533 delfunc CompleteFunc1 1533 delfunc CompleteFunc1
1534 delfunc CompleteFunc2 1534 delfunc CompleteFunc2
1614 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1614 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1615 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:OmniFunc1Args) 1615 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:OmniFunc1Args)
1616 bw! 1616 bw!
1617 1617
1618 #" Test for using a lambda function with set 1618 #" Test for using a lambda function with set
1619 VAR optval = "LSTART a, b LMIDDLE OmniFunc1(16, a, b) LEND" 1619 VAR optval = "LSTART a, b LMIDDLE g:OmniFunc1(16, a, b) LEND"
1620 LET optval = substitute(optval, ' ', '\\ ', 'g') 1620 LET optval = substitute(optval, ' ', '\\ ', 'g')
1621 exe "set omnifunc=" .. optval 1621 exe "set omnifunc=" .. optval
1622 new 1622 new
1623 call setline(1, 'five') 1623 call setline(1, 'five')
1624 LET g:OmniFunc1Args = [] 1624 LET g:OmniFunc1Args = []
1625 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1625 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1626 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:OmniFunc1Args) 1626 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:OmniFunc1Args)
1627 bw! 1627 bw!
1628 1628
1629 #" Set 'omnifunc' to a lambda expression 1629 #" Set 'omnifunc' to a lambda expression
1630 LET &omnifunc = LSTART a, b LMIDDLE OmniFunc1(17, a, b) LEND 1630 LET &omnifunc = LSTART a, b LMIDDLE g:OmniFunc1(17, a, b) LEND
1631 new 1631 new
1632 call setline(1, 'six') 1632 call setline(1, 'six')
1633 LET g:OmniFunc1Args = [] 1633 LET g:OmniFunc1Args = []
1634 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1634 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1635 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:OmniFunc1Args) 1635 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:OmniFunc1Args)
1636 bw! 1636 bw!
1637 1637
1638 #" Set 'omnifunc' to a string(lambda_expression) 1638 #" Set 'omnifunc' to a string(lambda_expression)
1639 LET &omnifunc = 'LSTART a, b LMIDDLE OmniFunc1(18, a, b) LEND' 1639 LET &omnifunc = 'LSTART a, b LMIDDLE g:OmniFunc1(18, a, b) LEND'
1640 new 1640 new
1641 call setline(1, 'six') 1641 call setline(1, 'six')
1642 LET g:OmniFunc1Args = [] 1642 LET g:OmniFunc1Args = []
1643 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1643 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1644 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:OmniFunc1Args) 1644 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:OmniFunc1Args)
1645 bw! 1645 bw!
1646 1646
1647 #" Set 'omnifunc' to a variable with a lambda expression 1647 #" Set 'omnifunc' to a variable with a lambda expression
1648 VAR Lambda = LSTART a, b LMIDDLE OmniFunc1(19, a, b) LEND 1648 VAR Lambda = LSTART a, b LMIDDLE g:OmniFunc1(19, a, b) LEND
1649 LET &omnifunc = Lambda 1649 LET &omnifunc = Lambda
1650 new 1650 new
1651 call setline(1, 'seven') 1651 call setline(1, 'seven')
1652 LET g:OmniFunc1Args = [] 1652 LET g:OmniFunc1Args = []
1653 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1653 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1654 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:OmniFunc1Args) 1654 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:OmniFunc1Args)
1655 bw! 1655 bw!
1656 1656
1657 #" Set 'omnifunc' to a string(variable with a lambda expression) 1657 #" Set 'omnifunc' to a string(variable with a lambda expression)
1658 LET Lambda = LSTART a, b LMIDDLE OmniFunc1(20, a, b) LEND 1658 LET Lambda = LSTART a, b LMIDDLE g:OmniFunc1(20, a, b) LEND
1659 LET &omnifunc = string(Lambda) 1659 LET &omnifunc = string(Lambda)
1660 new 1660 new
1661 call setline(1, 'seven') 1661 call setline(1, 'seven')
1662 LET g:OmniFunc1Args = [] 1662 LET g:OmniFunc1Args = []
1663 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1663 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1686 LET g:OmniFunc2Args = [] 1686 LET g:OmniFunc2Args = []
1687 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1687 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1688 call assert_equal([[1, ''], [0, 'nine']], g:OmniFunc2Args) 1688 call assert_equal([[1, ''], [0, 'nine']], g:OmniFunc2Args)
1689 bw! 1689 bw!
1690 END 1690 END
1691 call CheckLegacyAndVim9Success(lines) 1691 call v9.CheckLegacyAndVim9Success(lines)
1692 1692
1693 " Test for using a script-local function name 1693 " Test for using a script-local function name
1694 func s:OmniFunc3(findstart, base) 1694 func s:OmniFunc3(findstart, base)
1695 call add(g:OmniFunc3Args, [a:findstart, a:base]) 1695 call add(g:OmniFunc3Args, [a:findstart, a:base])
1696 return a:findstart ? 0 : [] 1696 return a:findstart ? 0 : []
1781 g:LocalOmniFuncArgs = [] 1781 g:LocalOmniFuncArgs = []
1782 feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1782 feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1783 assert_equal([[1, ''], [0, 'three']], g:LocalOmniFuncArgs) 1783 assert_equal([[1, ''], [0, 'three']], g:LocalOmniFuncArgs)
1784 bw! 1784 bw!
1785 END 1785 END
1786 call CheckScriptSuccess(lines) 1786 call v9.CheckScriptSuccess(lines)
1787 1787
1788 " cleanup 1788 " cleanup
1789 set omnifunc& 1789 set omnifunc&
1790 delfunc OmniFunc1 1790 delfunc OmniFunc1
1791 delfunc OmniFunc2 1791 delfunc OmniFunc2
1871 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1871 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1872 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:TsrFunc1Args) 1872 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:TsrFunc1Args)
1873 bw! 1873 bw!
1874 1874
1875 #" Test for using a lambda function 1875 #" Test for using a lambda function
1876 VAR optval = "LSTART a, b LMIDDLE TsrFunc1(16, a, b) LEND" 1876 VAR optval = "LSTART a, b LMIDDLE g:TsrFunc1(16, a, b) LEND"
1877 LET optval = substitute(optval, ' ', '\\ ', 'g') 1877 LET optval = substitute(optval, ' ', '\\ ', 'g')
1878 exe "set thesaurusfunc=" .. optval 1878 exe "set thesaurusfunc=" .. optval
1879 new 1879 new
1880 call setline(1, 'five') 1880 call setline(1, 'five')
1881 LET g:TsrFunc1Args = [] 1881 LET g:TsrFunc1Args = []
1882 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1882 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1883 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:TsrFunc1Args) 1883 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:TsrFunc1Args)
1884 bw! 1884 bw!
1885 1885
1886 #" Test for using a lambda function with set 1886 #" Test for using a lambda function with set
1887 LET &thesaurusfunc = LSTART a, b LMIDDLE TsrFunc1(17, a, b) LEND 1887 LET &thesaurusfunc = LSTART a, b LMIDDLE g:TsrFunc1(17, a, b) LEND
1888 new 1888 new
1889 call setline(1, 'six') 1889 call setline(1, 'six')
1890 LET g:TsrFunc1Args = [] 1890 LET g:TsrFunc1Args = []
1891 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1891 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1892 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:TsrFunc1Args) 1892 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:TsrFunc1Args)
1893 bw! 1893 bw!
1894 1894
1895 #" Set 'thesaurusfunc' to a string(lambda expression) 1895 #" Set 'thesaurusfunc' to a string(lambda expression)
1896 LET &thesaurusfunc = 'LSTART a, b LMIDDLE TsrFunc1(18, a, b) LEND' 1896 LET &thesaurusfunc = 'LSTART a, b LMIDDLE g:TsrFunc1(18, a, b) LEND'
1897 new 1897 new
1898 call setline(1, 'six') 1898 call setline(1, 'six')
1899 LET g:TsrFunc1Args = [] 1899 LET g:TsrFunc1Args = []
1900 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1900 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1901 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:TsrFunc1Args) 1901 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:TsrFunc1Args)
1902 bw! 1902 bw!
1903 1903
1904 #" Set 'thesaurusfunc' to a variable with a lambda expression 1904 #" Set 'thesaurusfunc' to a variable with a lambda expression
1905 VAR Lambda = LSTART a, b LMIDDLE TsrFunc1(19, a, b) LEND 1905 VAR Lambda = LSTART a, b LMIDDLE g:TsrFunc1(19, a, b) LEND
1906 LET &thesaurusfunc = Lambda 1906 LET &thesaurusfunc = Lambda
1907 new 1907 new
1908 call setline(1, 'seven') 1908 call setline(1, 'seven')
1909 LET g:TsrFunc1Args = [] 1909 LET g:TsrFunc1Args = []
1910 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1910 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1911 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:TsrFunc1Args) 1911 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:TsrFunc1Args)
1912 bw! 1912 bw!
1913 1913
1914 #" Set 'thesaurusfunc' to a string(variable with a lambda expression) 1914 #" Set 'thesaurusfunc' to a string(variable with a lambda expression)
1915 LET Lambda = LSTART a, b LMIDDLE TsrFunc1(20, a, b) LEND 1915 LET Lambda = LSTART a, b LMIDDLE g:TsrFunc1(20, a, b) LEND
1916 LET &thesaurusfunc = string(Lambda) 1916 LET &thesaurusfunc = string(Lambda)
1917 new 1917 new
1918 call setline(1, 'seven') 1918 call setline(1, 'seven')
1919 LET g:TsrFunc1Args = [] 1919 LET g:TsrFunc1Args = []
1920 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1920 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1966 call feedkeys("A\<C-X>\<C-T>\<Esc>", "x") 1966 call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
1967 call assert_equal('sun', getline(1)) 1967 call assert_equal('sun', getline(1))
1968 call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:TsrFunc1Args) 1968 call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:TsrFunc1Args)
1969 :%bw! 1969 :%bw!
1970 END 1970 END
1971 call CheckLegacyAndVim9Success(lines) 1971 call v9.CheckLegacyAndVim9Success(lines)
1972 1972
1973 " Test for using a script-local function name 1973 " Test for using a script-local function name
1974 func s:TsrFunc3(findstart, base) 1974 func s:TsrFunc3(findstart, base)
1975 call add(g:TsrFunc3Args, [a:findstart, a:base]) 1975 call add(g:TsrFunc3Args, [a:findstart, a:base])
1976 return a:findstart ? 0 : [] 1976 return a:findstart ? 0 : []
2074 g:LocalTsrFuncArgs = [] 2074 g:LocalTsrFuncArgs = []
2075 feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 2075 feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
2076 assert_equal([[1, ''], [0, 'three']], g:LocalTsrFuncArgs) 2076 assert_equal([[1, ''], [0, 'three']], g:LocalTsrFuncArgs)
2077 bw! 2077 bw!
2078 END 2078 END
2079 call CheckScriptSuccess(lines) 2079 call v9.CheckScriptSuccess(lines)
2080 2080
2081 " cleanup 2081 " cleanup
2082 set thesaurusfunc& 2082 set thesaurusfunc&
2083 delfunc TsrFunc1 2083 delfunc TsrFunc1
2084 delfunc TsrFunc2 2084 delfunc TsrFunc2