Mercurial > vim
comparison src/testdir/test_vim9_import.vim @ 27472:55613f0d59bc v8.2.4264
patch 8.2.4264: Vim9: can use old style autoload function name
Commit: https://github.com/vim/vim/commit/d8fe6d34bb582438142d7c1f73d0bd8537bb3a7a
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 30 18:40:44 2022 +0000
patch 8.2.4264: Vim9: can use old style autoload function name
Problem: Vim9: can use old style autoload function name.
Solution: Give an error for old style autoload function name.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 30 Jan 2022 19:45:03 +0100 |
parents | a14c4d3e3260 |
children | df414fc12eed |
comparison
equal
deleted
inserted
replaced
27471:769fe460984e | 27472:55613f0d59bc |
---|---|
1612 | 1612 |
1613 " test using an auto-loaded function and variable | 1613 " test using an auto-loaded function and variable |
1614 def Test_vim9_autoload_full_name() | 1614 def Test_vim9_autoload_full_name() |
1615 var lines =<< trim END | 1615 var lines =<< trim END |
1616 vim9script | 1616 vim9script |
1617 def some#gettest(): string | 1617 export def Gettest(): string |
1618 return 'test' | 1618 return 'test' |
1619 enddef | 1619 enddef |
1620 g:some#name = 'name' | 1620 g:some#name = 'name' |
1621 g:some#dict = {key: 'value'} | 1621 g:some#dict = {key: 'value'} |
1622 | 1622 |
1623 def some#varargs(a1: string, ...l: list<string>): string | 1623 export def Varargs(a1: string, ...l: list<string>): string |
1624 return a1 .. l[0] .. l[1] | 1624 return a1 .. l[0] .. l[1] |
1625 enddef | 1625 enddef |
1626 END | 1626 END |
1627 | 1627 |
1628 mkdir('Xdir/autoload', 'p') | 1628 mkdir('Xdir/autoload', 'p') |
1629 writefile(lines, 'Xdir/autoload/some.vim') | 1629 writefile(lines, 'Xdir/autoload/some.vim') |
1630 var save_rtp = &rtp | 1630 var save_rtp = &rtp |
1631 exe 'set rtp^=' .. getcwd() .. '/Xdir' | 1631 exe 'set rtp^=' .. getcwd() .. '/Xdir' |
1632 | 1632 |
1633 assert_equal('test', g:some#gettest()) | 1633 assert_equal('test', g:some#Gettest()) |
1634 assert_equal('name', g:some#name) | 1634 assert_equal('name', g:some#name) |
1635 assert_equal('value', g:some#dict.key) | 1635 assert_equal('value', g:some#dict.key) |
1636 g:some#other = 'other' | 1636 g:some#other = 'other' |
1637 assert_equal('other', g:some#other) | 1637 assert_equal('other', g:some#other) |
1638 | 1638 |
1639 assert_equal('abc', some#varargs('a', 'b', 'c')) | 1639 assert_equal('abc', some#Varargs('a', 'b', 'c')) |
1640 | 1640 |
1641 # upper case script name works | 1641 # upper case script name works |
1642 lines =<< trim END | 1642 lines =<< trim END |
1643 vim9script | 1643 vim9script |
1644 def Other#getOther(): string | 1644 export def GetOther(): string |
1645 return 'other' | 1645 return 'other' |
1646 enddef | 1646 enddef |
1647 END | 1647 END |
1648 writefile(lines, 'Xdir/autoload/Other.vim') | 1648 writefile(lines, 'Xdir/autoload/Other.vim') |
1649 assert_equal('other', g:Other#getOther()) | 1649 assert_equal('other', g:Other#GetOther()) |
1650 | 1650 |
1651 delete('Xdir', 'rf') | 1651 delete('Xdir', 'rf') |
1652 &rtp = save_rtp | 1652 &rtp = save_rtp |
1653 enddef | 1653 enddef |
1654 | 1654 |
2018 delete('Xdir', 'rf') | 2018 delete('Xdir', 'rf') |
2019 enddef | 2019 enddef |
2020 | 2020 |
2021 def Test_autoload_name_wrong() | 2021 def Test_autoload_name_wrong() |
2022 var lines =<< trim END | 2022 var lines =<< trim END |
2023 vim9script | |
2024 def Xscriptname#Func() | 2023 def Xscriptname#Func() |
2025 enddef | 2024 enddef |
2026 END | 2025 END |
2027 writefile(lines, 'Xscriptname.vim') | 2026 writefile(lines, 'Xscriptname.vim') |
2028 v9.CheckScriptFailure(lines, 'E1263:') | 2027 v9.CheckScriptFailure(lines, 'E746:') |
2029 | |
2030 delete('Xscriptname.vim') | 2028 delete('Xscriptname.vim') |
2029 | |
2030 mkdir('Xdir/autoload', 'p') | |
2031 lines =<< trim END | |
2032 vim9script | |
2033 def somescript#Func() | |
2034 enddef | |
2035 END | |
2036 writefile(lines, 'Xdir/autoload/somescript.vim') | |
2037 assert_fails('source Xdir/autoload/somescript.vim', 'E1263:') | |
2038 | |
2039 delete('Xdir', 'rf') | |
2031 enddef | 2040 enddef |
2032 | 2041 |
2033 def Test_import_autoload_postponed() | 2042 def Test_import_autoload_postponed() |
2034 mkdir('Xdir/autoload', 'p') | 2043 mkdir('Xdir/autoload', 'p') |
2035 var save_rtp = &rtp | 2044 var save_rtp = &rtp |
2200 var save_rtp = &rtp | 2209 var save_rtp = &rtp |
2201 exe 'set rtp^=' .. getcwd() .. '/Xdir' | 2210 exe 'set rtp^=' .. getcwd() .. '/Xdir' |
2202 | 2211 |
2203 var lines =<< trim END | 2212 var lines =<< trim END |
2204 vim9script | 2213 vim9script |
2205 def debugit#test(): string | 2214 export def Test(): string |
2206 return 'debug' | 2215 return 'debug' |
2207 enddef | 2216 enddef |
2208 END | 2217 END |
2209 writefile(lines, 'Xdir/autoload/debugit.vim') | 2218 writefile(lines, 'Xdir/autoload/debugit.vim') |
2210 | 2219 |
2211 lines =<< trim END | 2220 lines =<< trim END |
2212 vim9script | 2221 vim9script |
2213 def profileit#test(): string | 2222 export def Test(): string |
2214 return 'profile' | 2223 return 'profile' |
2215 enddef | 2224 enddef |
2216 END | 2225 END |
2217 writefile(lines, 'Xdir/autoload/profileit.vim') | 2226 writefile(lines, 'Xdir/autoload/profileit.vim') |
2218 | 2227 |
2219 lines =<< trim END | 2228 lines =<< trim END |
2220 vim9script | 2229 vim9script |
2221 assert_equal('debug', debugit#test()) | 2230 assert_equal('debug', debugit#Test()) |
2222 disass debugit#test | 2231 disass debugit#Test |
2223 assert_equal('profile', profileit#test()) | 2232 assert_equal('profile', profileit#Test()) |
2224 disass profileit#test | 2233 disass profileit#Test |
2225 END | 2234 END |
2226 v9.CheckScriptSuccess(lines) | 2235 v9.CheckScriptSuccess(lines) |
2227 | 2236 |
2228 delete('Xdir', 'rf') | 2237 delete('Xdir', 'rf') |
2229 &rtp = save_rtp | 2238 &rtp = save_rtp |
2231 | 2240 |
2232 " test using a vim9script that is auto-loaded from an autocmd | 2241 " test using a vim9script that is auto-loaded from an autocmd |
2233 def Test_vim9_aucmd_autoload() | 2242 def Test_vim9_aucmd_autoload() |
2234 var lines =<< trim END | 2243 var lines =<< trim END |
2235 vim9script | 2244 vim9script |
2236 def foo#test() | 2245 export def Test() |
2237 echomsg getreg('"') | 2246 echomsg getreg('"') |
2238 enddef | 2247 enddef |
2239 END | 2248 END |
2240 | 2249 |
2241 mkdir('Xdir/autoload', 'p') | 2250 mkdir('Xdir/autoload', 'p') |
2242 writefile(lines, 'Xdir/autoload/foo.vim') | 2251 writefile(lines, 'Xdir/autoload/foo.vim') |
2243 var save_rtp = &rtp | 2252 var save_rtp = &rtp |
2244 exe 'set rtp^=' .. getcwd() .. '/Xdir' | 2253 exe 'set rtp^=' .. getcwd() .. '/Xdir' |
2245 augroup test | 2254 augroup test |
2246 autocmd TextYankPost * call foo#test() | 2255 autocmd TextYankPost * call foo#Test() |
2247 augroup END | 2256 augroup END |
2248 | 2257 |
2249 normal Y | 2258 normal Y |
2250 | 2259 |
2251 augroup test | 2260 augroup test |