annotate src/testdir/test_vim9_import.vim @ 27076:ceff6a546748 v8.2.4067

patch 8.2.4067: Vim9: cannot call imported function with :call Commit: https://github.com/vim/vim/commit/f111cdfae6edf697390e0d9a85082a6526b03da6 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 12 12:48:17 2022 +0000 patch 8.2.4067: Vim9: cannot call imported function with :call Problem: Vim9: cannot call imported function with :call. (Drew Vogel) Solution: Translate the function name. (closes https://github.com/vim/vim/issues/9510)
author Bram Moolenaar <Bram@vim.org>
date Wed, 12 Jan 2022 14:00:06 +0100
parents 19fefc42a063
children 9897dd3c6530
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27014
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Test import/export of the Vim9 script language.
27057
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
2 " Also the autoload mechanism.
27014
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 source check.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 source term_util.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 source vim9.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 let s:export_script_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 var name: string = 'bob'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 def Concat(arg: string): string
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 return name .. arg
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 g:result = Concat('bie')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 g:localname = name
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 export const CONST = 1234
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 export var exported = 9876
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 export var exp_name = 'John'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 export def Exported(): string
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 return 'Exported'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 export def ExportedValue(): number
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 return exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 export def ExportedInc()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 exported += 5
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 export final theList = [1]
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 def Undo_export_script_lines()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 unlet g:result
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 unlet g:localname
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 def Test_vim9_import_export()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 writefile(s:export_script_lines, 'Xexport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 var import_script_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 var dir = './'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 var ext = ".vim"
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 import dir .. 'Xexport' .. ext as expo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 g:exported1 = expo.exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 expo.exported += 3
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 g:exported2 = expo.exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 g:exported3 = expo.ExportedValue()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 expo.ExportedInc()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 g:exported_i1 = expo.exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 g:exported_i2 = expo.ExportedValue()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 expo.exported = 11
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 g:exported_s1 = expo.exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 g:exported_s2 = expo.ExportedValue()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 g:imported_func = expo.Exported()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 def GetExported(): string
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 var local_dict = {ref: expo.Exported}
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 return local_dict.ref()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 g:funcref_result = GetExported()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 g:imported_name = expo.exp_name
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 expo.exp_name ..= ' Doe'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 g:imported_name_appended = expo.exp_name
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 g:exported_later = expo.exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 expo.theList->add(2)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 assert_equal([1, 2], expo.theList)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 writefile(import_script_lines, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 source Ximport.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 assert_equal('bobbie', g:result)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 assert_equal('bob', g:localname)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 assert_equal(9876, g:exported1)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 assert_equal(9879, g:exported2)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 assert_equal(9879, g:exported3)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 assert_equal(9884, g:exported_i1)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 assert_equal(9884, g:exported_i2)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 assert_equal(11, g:exported_s1)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 assert_equal(11, g:exported_s2)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 assert_equal(11, g:exported_later)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 assert_equal('Exported', g:imported_func)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 assert_equal('Exported', g:funcref_result)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 assert_equal('John', g:imported_name)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 assert_equal('John Doe', g:imported_name_appended)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 assert_false(exists('g:name'))
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 Undo_export_script_lines()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 unlet g:exported1
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 unlet g:exported2
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 unlet g:exported3
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 unlet g:exported_i1
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 unlet g:exported_i2
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 unlet g:exported_later
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 unlet g:imported_func
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 unlet g:imported_name g:imported_name_appended
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 delete('Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 # similar, with line breaks
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 var import_line_break_script_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 import './Xexport.vim'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 as expo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 g:exported = expo.exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 expo.exported += 7
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 g:exported_added = expo.exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 g:imported_func = expo.Exported()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 writefile(import_line_break_script_lines, 'Ximport_lbr.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 source Ximport_lbr.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 assert_equal(11, g:exported)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 assert_equal(18, g:exported_added)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 assert_equal('Exported', g:imported_func)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 # exported script not sourced again
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 assert_false(exists('g:result'))
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 unlet g:exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 unlet g:exported_added
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 unlet g:imported_func
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 delete('Ximport_lbr.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 var line_break_before_dot =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 import './Xexport.vim' as expo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 g:exported = expo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 .exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 writefile(line_break_before_dot, 'Ximport_lbr_before_dot.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 assert_fails('source Ximport_lbr_before_dot.vim', 'E1060:', '', 3)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 delete('Ximport_lbr_before_dot.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 var line_break_after_dot =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 import './Xexport.vim' as expo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 g:exported = expo.
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 writefile(line_break_after_dot, 'Ximport_lbr_after_dot.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 assert_fails('source Ximport_lbr_after_dot.vim', 'E1074:', '', 3)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 delete('Ximport_lbr_after_dot.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 var import_star_as_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 import './Xexport.vim' as Export
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 def UseExport()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 g:exported_def = Export.exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 g:exported_script = Export.exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 assert_equal(1, exists('Export.exported'))
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 assert_equal(0, exists('Export.notexported'))
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 UseExport()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 writefile(import_star_as_lines, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 source Ximport.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 assert_equal(18, g:exported_def)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 assert_equal(18, g:exported_script)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 unlet g:exported_def
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 unlet g:exported_script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 var import_star_as_lines_no_dot =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 import './Xexport.vim' as Export
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 def Func()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 var dummy = 1
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 var imported = Export + dummy
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 defcompile
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 writefile(import_star_as_lines_no_dot, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 assert_fails('source Ximport.vim', 'E1060:', '', 2, 'Func')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 var import_star_as_lines_dot_space =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 import './Xexport.vim' as Export
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 def Func()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 var imported = Export . exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 defcompile
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 writefile(import_star_as_lines_dot_space, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 assert_fails('source Ximport.vim', 'E1074:', '', 1, 'Func')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192
27030
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
193 writefile(s:export_script_lines, 'Xexport2.vim')
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
194 var import_as_duplicated =<< trim END
27014
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 import './Xexport.vim' as expo
27030
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
197 import './Xexport2.vim' as expo
27014
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 END
27030
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
199 writefile(import_as_duplicated, 'Ximport.vim')
27014
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 assert_fails('source Ximport.vim', 'E1073:', '', 3, 'Ximport.vim')
27030
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
201 delete('Xexport2.vim')
27014
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 var import_star_as_lines_script_no_dot =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 import './Xexport.vim' as Export
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 g:imported_script = Export exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 writefile(import_star_as_lines_script_no_dot, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 assert_fails('source Ximport.vim', 'E1060: Expected dot after name: Export exported')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 var import_star_as_lines_script_space_after_dot =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 import './Xexport.vim' as Export
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 g:imported_script = Export. exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 writefile(import_star_as_lines_script_space_after_dot, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 assert_fails('source Ximport.vim', 'E1074:')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 var import_star_as_lines_missing_name =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 import './Xexport.vim' as Export
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 def Func()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 var imported = Export.
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 defcompile
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 writefile(import_star_as_lines_missing_name, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 assert_fails('source Ximport.vim', 'E1048:', '', 1, 'Func')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 var import_star_as_lbr_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 import './Xexport.vim'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 as Export
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 def UseExport()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 g:exported = Export.exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 UseExport()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 writefile(import_star_as_lbr_lines, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 source Ximport.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 assert_equal(18, g:exported)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 unlet g:exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 # try to use something that exists but is not exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 var import_not_exported_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 import './Xexport.vim' as expo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 echo expo.name
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 writefile(import_not_exported_lines, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 assert_fails('source Ximport.vim', 'E1049:', '', 3, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 # try to import something that is already defined
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 var import_already_defined =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 var exported = 'something'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 import './Xexport.vim' as exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 writefile(import_already_defined, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 assert_fails('source Ximport.vim', 'E1054:', '', 3, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 # try changing an imported const
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 var import_assign_to_const =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 import './Xexport.vim' as expo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 def Assign()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 expo.CONST = 987
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 defcompile
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 writefile(import_assign_to_const, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 assert_fails('source Ximport.vim', 'E46:', '', 1, '_Assign')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 # try changing an imported final
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 var import_assign_to_final =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 import './Xexport.vim' as expo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 def Assign()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 expo.theList = [2]
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 defcompile
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 writefile(import_assign_to_final, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 assert_fails('source Ximport.vim', 'E46:', '', 1, '_Assign')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 var import_no_as_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 import './Xexport.vim' name
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 writefile(import_no_as_lines, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 assert_fails('source Ximport.vim', 'E488:', '', 2, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 var import_invalid_string_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 import Xexport.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 writefile(import_invalid_string_lines, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 assert_fails('source Ximport.vim', 'E121:', '', 2, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 var import_wrong_name_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 import './XnoExport.vim'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 writefile(import_wrong_name_lines, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 assert_fails('source Ximport.vim', 'E1053:', '', 2, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 var import_redefining_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 import './Xexport.vim' as exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 var exported = 5
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 writefile(import_redefining_lines, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 assert_fails('source Ximport.vim', 'E1213: Redefining imported item "exported"', '', 3)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314
27057
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
315 var import_missing_dot_lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
316 vim9script
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
317 import './Xexport.vim' as expo
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
318 def Test()
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
319 expo = 9
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
320 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
321 defcompile
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
322 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
323 writefile(import_missing_dot_lines, 'Ximport.vim')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
324 assert_fails('source Ximport.vim', 'E1258:', '', 1)
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
325
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
326 var import_missing_name_lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
327 vim9script
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
328 import './Xexport.vim' as expo
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
329 def Test()
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
330 expo.99 = 9
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
331 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
332 defcompile
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
333 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
334 writefile(import_missing_name_lines, 'Ximport.vim')
27059
e97cf16731d9 patch 8.2.4058: Vim9: import test failure in wrong line
Bram Moolenaar <Bram@vim.org>
parents: 27057
diff changeset
335 assert_fails('source Ximport.vim', 'E1259:', '', 1)
27057
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
336
27014
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 var import_assign_wrong_type_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 import './Xexport.vim' as expo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 expo.exported = 'xxx'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 writefile(import_assign_wrong_type_lines, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 assert_fails('source Ximport.vim', 'E1012: Type mismatch; expected number but got string', '', 3)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 var import_assign_const_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 import './Xexport.vim' as expo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 expo.CONST = 4321
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 writefile(import_assign_const_lines, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 assert_fails('source Ximport.vim', 'E46: Cannot change read-only variable "CONST"', '', 3)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 delete('Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 delete('Ximport3.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 delete('Xexport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 # Check that in a Vim9 script 'cpo' is set to the Vim default.
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 # Flags added or removed are also applied to the restored value.
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 set cpo=abcd
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 var lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 g:cpo_in_vim9script = &cpo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 set cpo+=f
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 set cpo-=c
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 g:cpo_after_vim9script = &cpo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 writefile(lines, 'Xvim9_script')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 source Xvim9_script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 assert_equal('fabd', &cpo)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 set cpo&vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 assert_equal(&cpo, g:cpo_in_vim9script)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 var newcpo = substitute(&cpo, 'c', '', '') .. 'f'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 assert_equal(newcpo, g:cpo_after_vim9script)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 delete('Xvim9_script')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 def Test_import_funcref()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 var lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 export def F(): number
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 return 42
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 export const G = F
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 writefile(lines, 'Xlib.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 import './Xlib.vim' as lib
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 const Foo = lib.G()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 assert_equal(42, Foo)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 def DoTest()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 const Goo = lib.G()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 assert_equal(42, Goo)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 DoTest()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 CheckScriptSuccess(lines)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 delete('Xlib.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 def Test_import_fails()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 writefile([], 'Xfoo.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 var lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 import './Xfoo.vim' as foo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 foo = 'bar'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 CheckDefAndScriptFailure(lines, ['E1094:', 'E1236: Cannot use foo itself'])
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 import './Xfoo.vim' as foo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 var that = foo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 CheckScriptFailure(lines, 'E1060: Expected dot after name: foo')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 import './Xfoo.vim' as 9foo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 CheckScriptFailure(lines, 'E1047:')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 import './Xfoo.vim' as the#foo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 CheckScriptFailure(lines, 'E1047:')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 import './Xfoo.vim' as g:foo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 CheckScriptFailure(lines, 'E1047:')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 delete('Xfoo.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 def TheFunc()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 echo 'the func'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 export var Ref = TheFunc
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 writefile([], 'Xthat.vim')
27030
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
445
27014
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 import './Xthat.vim' as That
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 That()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 CheckDefAndScriptFailure(lines, ['E1094:', 'E1236: Cannot use That itself'])
27030
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
451
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
452 lines =<< trim END
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
453 import './Xthat.vim' as one
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
454 import './Xthat.vim' as two
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
455 END
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
456 CheckScriptFailure(lines, 'E1262:')
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
457
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
458 delete('Xthat.vim')
27014
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 mkdir('Ximport')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 writefile(['vim9script'], 'Ximport/.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 import './Ximport/.vim'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 CheckScriptFailure(lines, 'E1261: Cannot import .vim without using "as"')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 import './Ximport/.vim' as vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 CheckScriptSuccess(lines)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 writefile(['vim9script'], 'Ximport/.vimrc')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 import './Ximport/.vimrc'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 CheckScriptFailure(lines, 'E1257: Imported script must use "as" or end in .vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 import './Ximport/.vimrc' as vimrc
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 CheckScriptSuccess(lines)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 delete('Ximport', 'rf')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 func g:Trigger()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 source Ximport.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 return "echo 'yes'\<CR>"
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 endfunc
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 def Test_import_export_expr_map()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 # check that :import and :export work when buffer is locked
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 var export_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 export def That(): string
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 return 'yes'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 writefile(export_lines, 'Xexport_that.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 var import_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 import './Xexport_that.vim' as that
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 assert_equal('yes', that.That())
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 writefile(import_lines, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 nnoremap <expr> trigger g:Trigger()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 feedkeys('trigger', "xt")
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 delete('Xexport_that.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 delete('Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 nunmap trigger
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 def Test_import_in_filetype()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 # check that :import works when the buffer is locked
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 mkdir('ftplugin', 'p')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 var export_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 export var That = 'yes'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 writefile(export_lines, 'ftplugin/Xexport_ft.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 var import_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 import './Xexport_ft.vim' as ft
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 assert_equal('yes', ft.That)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 g:did_load_mytpe = 1
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 writefile(import_lines, 'ftplugin/qf.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 var save_rtp = &rtp
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 &rtp = getcwd() .. ',' .. &rtp
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 filetype plugin on
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 copen
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 assert_equal(1, g:did_load_mytpe)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 quit!
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 delete('Xexport_ft.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 delete('ftplugin', 'rf')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 &rtp = save_rtp
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 def Test_use_import_in_mapping()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 var lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 export def Funcx()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 g:result = 42
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 writefile(lines, 'XsomeExport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 import './XsomeExport.vim' as some
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 var Funcy = some.Funcx
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 nnoremap <F3> :call <sid>Funcy()<cr>
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 writefile(lines, 'Xmapscript.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 source Xmapscript.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 feedkeys("\<F3>", "xt")
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 assert_equal(42, g:result)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 unlet g:result
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 delete('XsomeExport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 delete('Xmapscript.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 nunmap <F3>
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 def Test_export_fails()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 CheckScriptFailure(['export var some = 123'], 'E1042:')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 CheckScriptFailure(['vim9script', 'export echo 134'], 'E1043:')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 assert_fails('export something', 'E1043:')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 func Test_import_fails_without_script()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 CheckRunVimInTerminal
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 " call indirectly to avoid compilation error for missing functions
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 call Run_Test_import_fails_on_command_line()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 endfunc
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 def Run_Test_import_fails_on_command_line()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 var export =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 export def Foo(): number
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 return 0
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 writefile(export, 'XexportCmd.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 var buf = RunVimInTerminal('-c "import Foo from ''./XexportCmd.vim''"', {
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 rows: 6, wait_for_ruler: 0})
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 WaitForAssert(() => assert_match('^E1094:', term_getline(buf, 5)))
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 delete('XexportCmd.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 StopVimInTerminal(buf)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 def Test_vim9_reload_noclear()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 var lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 export var exported = 'thexport'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 export def TheFunc(x = 0)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 writefile(lines, 'XExportReload')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 vim9script noclear
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 g:loadCount += 1
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 var s:reloaded = 'init'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 import './XExportReload' as exp
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 def Again(): string
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 return 'again'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 exp.TheFunc()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 if exists('s:loaded') | finish | endif
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 var s:loaded = true
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 var s:notReloaded = 'yes'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 s:reloaded = 'first'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 def g:Values(): list<string>
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 return [s:reloaded, s:notReloaded, Again(), Once(), exp.exported]
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 def Once(): string
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 return 'once'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 writefile(lines, 'XReloaded')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 g:loadCount = 0
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 source XReloaded
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 assert_equal(1, g:loadCount)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 assert_equal(['first', 'yes', 'again', 'once', 'thexport'], g:Values())
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 source XReloaded
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 assert_equal(2, g:loadCount)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 assert_equal(['init', 'yes', 'again', 'once', 'thexport'], g:Values())
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 source XReloaded
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 assert_equal(3, g:loadCount)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 assert_equal(['init', 'yes', 'again', 'once', 'thexport'], g:Values())
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 delete('XReloaded')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 delete('XExportReload')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 delfunc g:Values
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 unlet g:loadCount
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 def Inner()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 lines->writefile('XreloadScript.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 source XreloadScript.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 def Outer()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 def Inner()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 defcompile
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 lines->writefile('XreloadScript.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 source XreloadScript.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 delete('XreloadScript.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 def Test_vim9_reload_import()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 var lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 const var = ''
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 var valone = 1234
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 def MyFunc(arg: string)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 valone = 5678
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 var morelines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 var valtwo = 222
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 export def GetValtwo(): number
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 return valtwo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 writefile(lines + morelines, 'Xreload.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 source Xreload.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 source Xreload.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 source Xreload.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 # cannot declare a var twice
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 var valone = 1234
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 var valone = 5678
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 writefile(lines, 'Xreload.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 assert_fails('source Xreload.vim', 'E1041:', '', 3, 'Xreload.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 delete('Xreload.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 delete('Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 " if a script is reloaded with a script-local variable that changed its type, a
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 " compiled function using that variable must fail.
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 def Test_script_reload_change_type()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 var lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 vim9script noclear
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 var str = 'string'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 def g:GetStr(): string
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 return str .. 'xxx'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 writefile(lines, 'Xreload.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 source Xreload.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 echo g:GetStr()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 vim9script noclear
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 var str = 1234
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 writefile(lines, 'Xreload.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 source Xreload.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 assert_fails('echo g:GetStr()', 'E1150:')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 delfunc g:GetStr
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 delete('Xreload.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 " Define CallFunc so that the test can be compiled
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 command CallFunc echo 'nop'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 def Test_script_reload_from_function()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 var lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 if exists('g:loaded')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 finish
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 endif
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 g:loaded = 1
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 delcommand CallFunc
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 command CallFunc Func()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 def Func()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 so XreloadFunc.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 g:didTheFunc = 1
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 writefile(lines, 'XreloadFunc.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 source XreloadFunc.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 CallFunc
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 assert_equal(1, g:didTheFunc)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 delete('XreloadFunc.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 delcommand CallFunc
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 unlet g:loaded
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 unlet g:didTheFunc
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 def s:RetSome(): string
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 return 'some'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 " Not exported function that is referenced needs to be accessed by the
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 " script-local name.
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 def Test_vim9_funcref()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 var sortlines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 def Compare(i1: number, i2: number): number
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 return i2 - i1
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 export def FastSort(): list<number>
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 return range(5)->sort(Compare)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 export def GetString(arg: string): string
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 return arg
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 writefile(sortlines, 'Xsort.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 var lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 import './Xsort.vim'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 def Test()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 g:result = Xsort.FastSort()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 Test()
27030
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
798 END
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
799 writefile(lines, 'Xscript.vim')
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
800 source Xscript.vim
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
801 assert_equal([4, 3, 2, 1, 0], g:result)
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
802 unlet g:result
27014
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803
27030
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
804 lines =<< trim END
c8809b8d19de patch 8.2.4044: Vim9: no error when importing the same script twice
Bram Moolenaar <Bram@vim.org>
parents: 27014
diff changeset
805 vim9script
27014
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 # using a function imported with "as"
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 import './Xsort.vim' as anAlias
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 assert_equal('yes', anAlias.GetString('yes'))
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 # using the function from a compiled function
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 def TestMore(): string
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 var s = s:anAlias.GetString('foo')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 return s .. anAlias.GetString('bar')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 assert_equal('foobar', TestMore())
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 # error when using a function that isn't exported
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 assert_fails('anAlias.Compare(1, 2)', 'E1049:')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 writefile(lines, 'Xscript.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 delete('Xsort.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 delete('Xscript.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 var Funcref = function('s:RetSome')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 assert_equal('some', Funcref())
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 " Check that when searching for "FilterFunc" it finds the import in the
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 " script where FastFilter() is called from, both as a string and as a direct
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 " function reference.
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 def Test_vim9_funcref_other_script()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 var filterLines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 export def FilterFunc(idx: number, val: number): bool
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 return idx % 2 == 1
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 export def FastFilter(): list<number>
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 return range(10)->filter('FilterFunc(v:key, v:val)')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 export def FastFilterDirect(): list<number>
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 return range(10)->filter(FilterFunc)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 writefile(filterLines, 'Xfilter.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 var lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 import './Xfilter.vim' as filter
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 def Test()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 var x: list<number> = filter.FastFilter()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 Test()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 def TestDirect()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 var x: list<number> = filter.FastFilterDirect()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 TestDirect()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 CheckScriptSuccess(lines)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 delete('Xfilter.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 def Test_import_absolute()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 var import_lines = [
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 'vim9script',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 'import "' .. escape(getcwd(), '\') .. '/Xexport_abs.vim" as abs',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 'def UseExported()',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 ' g:imported_abs = abs.exported',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 ' abs.exported = 8888',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 ' g:imported_after = abs.exported',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 'enddef',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 'UseExported()',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 'g:import_disassembled = execute("disass UseExported")',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 ]
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 writefile(import_lines, 'Ximport_abs.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 writefile(s:export_script_lines, 'Xexport_abs.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 source Ximport_abs.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 assert_equal(9876, g:imported_abs)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 assert_equal(8888, g:imported_after)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 assert_match('<SNR>\d\+_UseExported\_s*' ..
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 'g:imported_abs = abs.exported\_s*' ..
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 '0 LOADSCRIPT exported-2 from .*Xexport_abs.vim\_s*' ..
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 '1 STOREG g:imported_abs\_s*' ..
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 'abs.exported = 8888\_s*' ..
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 '2 PUSHNR 8888\_s*' ..
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 '3 STORESCRIPT exported-2 in .*Xexport_abs.vim\_s*' ..
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 'g:imported_after = abs.exported\_s*' ..
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 '4 LOADSCRIPT exported-2 from .*Xexport_abs.vim\_s*' ..
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 '5 STOREG g:imported_after',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 g:import_disassembled)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 Undo_export_script_lines()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 unlet g:imported_abs
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 unlet g:import_disassembled
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 delete('Ximport_abs.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 delete('Xexport_abs.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 def Test_import_rtp()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 var import_lines = [
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 'vim9script',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 'import "Xexport_rtp.vim" as rtp',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 'g:imported_rtp = rtp.exported',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 ]
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 writefile(import_lines, 'Ximport_rtp.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 mkdir('import', 'p')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 writefile(s:export_script_lines, 'import/Xexport_rtp.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 var save_rtp = &rtp
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 &rtp = getcwd()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 source Ximport_rtp.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 &rtp = save_rtp
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 assert_equal(9876, g:imported_rtp)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 Undo_export_script_lines()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 unlet g:imported_rtp
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 delete('Ximport_rtp.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 delete('import', 'rf')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 def Test_import_compile_error()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 var export_lines = [
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 'vim9script',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 'export def ExpFunc(): string',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 ' return notDefined',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 'enddef',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 ]
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 writefile(export_lines, 'Xexported.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 var import_lines = [
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 'vim9script',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 'import "./Xexported.vim" as expo',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 'def ImpFunc()',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 ' echo expo.ExpFunc()',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 'enddef',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 'defcompile',
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 ]
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 writefile(import_lines, 'Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 try
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 source Ximport.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 catch /E1001/
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 # Error should be before the Xexported.vim file.
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 assert_match('E1001: Variable not found: notDefined', v:exception)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 assert_match('function <SNR>\d\+_ImpFunc\[1\]..<SNR>\d\+_ExpFunc, line 1', v:throwpoint)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 endtry
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 delete('Xexported.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 delete('Ximport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 def Test_func_overrules_import_fails()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 var export_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 export def Func()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 echo 'imported'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 writefile(export_lines, 'XexportedFunc.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 var lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 import './XexportedFunc.vim' as Func
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 def Func()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 echo 'local to function'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 CheckScriptFailure(lines, 'E1236:')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 import './XexportedFunc.vim' as Func
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 def Outer()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 def Func()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 echo 'local to function'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 defcompile
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 CheckScriptFailure(lines, 'E1236:')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 delete('XexportedFunc.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 def Test_source_vim9_from_legacy()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 var vim9_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 var local = 'local'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 g:global = 'global'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 export var exported = 'exported'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 export def GetText(): string
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 return 'text'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 writefile(vim9_lines, 'Xvim9_script.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 var legacy_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 source Xvim9_script.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 call assert_false(exists('local'))
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 call assert_false(exists('exported'))
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 call assert_false(exists('s:exported'))
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 call assert_equal('global', global)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 call assert_equal('global', g:global)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 "" imported variable becomes script-local
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 "import exported from './Xvim9_script.vim'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 "call assert_equal('exported', s:exported)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 "call assert_false(exists('exported'))
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 "" imported function becomes script-local
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 "import GetText from './Xvim9_script.vim'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 "call assert_equal('text', s:GetText())
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 "call assert_false(exists('*GetText'))
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 writefile(legacy_lines, 'Xlegacy_script.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 source Xlegacy_script.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 assert_equal('global', g:global)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 unlet g:global
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 delete('Xlegacy_script.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 delete('Xvim9_script.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 def Test_cmdline_win()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 # if the Vim syntax highlighting uses Vim9 constructs they can be used from
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 # the command line window.
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 mkdir('rtp/syntax', 'p')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 var export_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 export var That = 'yes'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 writefile(export_lines, 'rtp/syntax/Xexport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 var import_lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 import './Xexport.vim' as exp
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 echo exp.That
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 writefile(import_lines, 'rtp/syntax/vim.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 var save_rtp = &rtp
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 &rtp = getcwd() .. '/rtp' .. ',' .. &rtp
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 syntax on
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 augroup CmdWin
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 autocmd CmdwinEnter * g:got_there = 'yes'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 augroup END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 # this will open and also close the cmdline window
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 feedkeys('q:', 'xt')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 assert_equal('yes', g:got_there)
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 augroup CmdWin
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 au!
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 augroup END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 &rtp = save_rtp
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 delete('rtp', 'rf')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 def Test_import_gone_when_sourced_twice()
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 var exportlines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 if exists('g:guard')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 finish
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 endif
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 g:guard = 1
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 export var name = 'someName'
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 writefile(exportlines, 'XexportScript.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 var lines =<< trim END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 vim9script
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 import './XexportScript.vim' as expo
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 def g:GetName(): string
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 return expo.name
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 END
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 writefile(lines, 'XscriptImport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 so XscriptImport.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 assert_equal('someName', g:GetName())
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 so XexportScript.vim
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 assert_fails('call g:GetName()', 'E1149:')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 delfunc g:GetName
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 delete('XexportScript.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 delete('XscriptImport.vim')
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 unlet g:guard
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 enddef
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092
27057
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1093 " test using an auto-loaded function and variable
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1094 def Test_vim9_autoload()
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1095 var lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1096 vim9script
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1097 def some#gettest(): string
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1098 return 'test'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1099 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1100 g:some#name = 'name'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1101 g:some#dict = {key: 'value'}
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1102
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1103 def some#varargs(a1: string, ...l: list<string>): string
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1104 return a1 .. l[0] .. l[1]
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1105 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1106 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1107
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1108 mkdir('Xdir/autoload', 'p')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1109 writefile(lines, 'Xdir/autoload/some.vim')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1110 var save_rtp = &rtp
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1111 exe 'set rtp^=' .. getcwd() .. '/Xdir'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1112
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1113 assert_equal('test', g:some#gettest())
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1114 assert_equal('name', g:some#name)
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1115 assert_equal('value', g:some#dict.key)
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1116 g:some#other = 'other'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1117 assert_equal('other', g:some#other)
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1118
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1119 assert_equal('abc', some#varargs('a', 'b', 'c'))
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1120
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1121 # upper case script name works
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1122 lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1123 vim9script
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1124 def Other#getOther(): string
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1125 return 'other'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1126 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1127 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1128 writefile(lines, 'Xdir/autoload/Other.vim')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1129 assert_equal('other', g:Other#getOther())
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1130
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1131 delete('Xdir', 'rf')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1132 &rtp = save_rtp
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1133 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1134
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1135 def Test_vim9script_autoload()
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1136 mkdir('Xdir/autoload', 'p')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1137 var save_rtp = &rtp
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1138 exe 'set rtp^=' .. getcwd() .. '/Xdir'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1139
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1140 # when using "vim9script autoload" prefix is not needed
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1141 var lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1142 vim9script autoload
27074
19fefc42a063 patch 8.2.4066: Vim9: imported autoload script loaded again
Bram Moolenaar <Bram@vim.org>
parents: 27068
diff changeset
1143 g:prefixed_loaded += 1
27057
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1144
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1145 export def Gettest(): string
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1146 return 'test'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1147 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1148
27068
6a4fc2e6e6eb patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents: 27061
diff changeset
1149 export func GetMore()
6a4fc2e6e6eb patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents: 27061
diff changeset
1150 return Gettest() .. 'more'
27057
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1151 endfunc
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1152
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1153 export var name = 'name'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1154 export final fname = 'final'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1155 export const cname = 'const'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1156 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1157 writefile(lines, 'Xdir/autoload/prefixed.vim')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1158
27074
19fefc42a063 patch 8.2.4066: Vim9: imported autoload script loaded again
Bram Moolenaar <Bram@vim.org>
parents: 27068
diff changeset
1159 g:prefixed_loaded = 0
19fefc42a063 patch 8.2.4066: Vim9: imported autoload script loaded again
Bram Moolenaar <Bram@vim.org>
parents: 27068
diff changeset
1160 g:expected_loaded = 0
27057
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1161 lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1162 vim9script
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1163 import autoload 'prefixed.vim'
27074
19fefc42a063 patch 8.2.4066: Vim9: imported autoload script loaded again
Bram Moolenaar <Bram@vim.org>
parents: 27068
diff changeset
1164 assert_equal(g:expected_loaded, g:prefixed_loaded)
27057
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1165 assert_equal('test', prefixed.Gettest())
27074
19fefc42a063 patch 8.2.4066: Vim9: imported autoload script loaded again
Bram Moolenaar <Bram@vim.org>
parents: 27068
diff changeset
1166 assert_equal(1, g:prefixed_loaded)
27057
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1167
27068
6a4fc2e6e6eb patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents: 27061
diff changeset
1168 assert_equal('testmore', prefixed.GetMore())
27057
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1169 assert_equal('name', prefixed.name)
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1170 assert_equal('final', prefixed.fname)
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1171 assert_equal('const', prefixed.cname)
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1172 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1173 CheckScriptSuccess(lines)
27074
19fefc42a063 patch 8.2.4066: Vim9: imported autoload script loaded again
Bram Moolenaar <Bram@vim.org>
parents: 27068
diff changeset
1174 # can source it again, autoload script not loaded again
19fefc42a063 patch 8.2.4066: Vim9: imported autoload script loaded again
Bram Moolenaar <Bram@vim.org>
parents: 27068
diff changeset
1175 g:expected_loaded = 1
19fefc42a063 patch 8.2.4066: Vim9: imported autoload script loaded again
Bram Moolenaar <Bram@vim.org>
parents: 27068
diff changeset
1176 CheckScriptSuccess(lines)
27057
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1177
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1178 # can also get the items by autoload name
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1179 lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1180 call assert_equal('test', prefixed#Gettest())
27068
6a4fc2e6e6eb patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents: 27061
diff changeset
1181 call assert_equal('testmore', prefixed#GetMore())
27057
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1182 call assert_equal('name', prefixed#name)
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1183 call assert_equal('final', prefixed#fname)
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1184 call assert_equal('const', prefixed#cname)
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1185 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1186 CheckScriptSuccess(lines)
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1187
27076
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1188 unlet g:prefixed_loaded
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1189 unlet g:expected_loaded
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1190 delete('Xdir', 'rf')
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1191 &rtp = save_rtp
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1192 enddef
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1193
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1194 def Test_vim9script_autoload_call()
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1195 mkdir('Xdir/autoload', 'p')
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1196 var save_rtp = &rtp
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1197 exe 'set rtp^=' .. getcwd() .. '/Xdir'
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1198
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1199 var lines =<< trim END
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1200 vim9script autoload
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1201
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1202 export def Getother()
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1203 g:result = 'other'
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1204 enddef
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1205 END
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1206 writefile(lines, 'Xdir/autoload/other.vim')
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1207
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1208 lines =<< trim END
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1209 vim9script
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1210 import autoload 'other.vim'
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1211 call other.Getother()
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1212 assert_equal('other', g:result)
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1213 END
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1214 CheckScriptSuccess(lines)
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1215
ceff6a546748 patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents: 27074
diff changeset
1216 unlet g:result
27057
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1217 delete('Xdir', 'rf')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1218 &rtp = save_rtp
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1219 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1220
27061
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1221 def Test_autoload_mapping()
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1222 mkdir('Xdir/autoload', 'p')
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1223 var save_rtp = &rtp
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1224 exe 'set rtp^=' .. getcwd() .. '/Xdir'
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1225
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1226 var lines =<< trim END
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1227 vim9script autoload
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1228
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1229 g:toggle_loaded = 'yes'
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1230
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1231 export def Toggle(): string
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1232 return ":g:toggle_called = 'yes'\<CR>"
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1233 enddef
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1234 END
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1235 writefile(lines, 'Xdir/autoload/toggle.vim')
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1236
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1237 lines =<< trim END
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1238 vim9script
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1239
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1240 import autoload 'toggle.vim'
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1241
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1242 nnoremap <silent> <expr> tt toggle.Toggle()
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1243 END
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1244 CheckScriptSuccess(lines)
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1245 assert_false(exists("g:toggle_loaded"))
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1246 assert_false(exists("g:toggle_called"))
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1247
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1248 feedkeys("tt", 'xt')
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1249 assert_equal('yes', g:toggle_loaded)
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1250 assert_equal('yes', g:toggle_called)
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1251
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1252 nunmap tt
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1253 unlet g:toggle_loaded
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1254 unlet g:toggle_called
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1255 delete('Xdir', 'rf')
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1256 &rtp = save_rtp
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1257 enddef
1a56c0252772 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents: 27059
diff changeset
1258
27057
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1259 def Test_vim9script_autoload_fails()
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1260 var lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1261 vim9script autoload
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1262 var n = 0
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1263 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1264 CheckScriptFailure(lines, 'E1263:')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1265 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1266
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1267 def Test_import_autoload_fails()
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1268 var lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1269 vim9script
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1270 import autoload autoload 'prefixed.vim'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1271 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1272 CheckScriptFailure(lines, 'E121: Undefined variable: autoload')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1273
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1274 lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1275 vim9script
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1276 import autoload 'doesNotExist.vim'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1277 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1278 CheckScriptFailure(lines, 'E1264:')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1279 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1280
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1281 " test disassembling an auto-loaded function starting with "debug"
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1282 def Test_vim9_autoload_disass()
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1283 mkdir('Xdir/autoload', 'p')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1284 var save_rtp = &rtp
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1285 exe 'set rtp^=' .. getcwd() .. '/Xdir'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1286
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1287 var lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1288 vim9script
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1289 def debugit#test(): string
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1290 return 'debug'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1291 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1292 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1293 writefile(lines, 'Xdir/autoload/debugit.vim')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1294
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1295 lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1296 vim9script
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1297 def profileit#test(): string
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1298 return 'profile'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1299 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1300 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1301 writefile(lines, 'Xdir/autoload/profileit.vim')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1302
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1303 lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1304 vim9script
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1305 assert_equal('debug', debugit#test())
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1306 disass debugit#test
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1307 assert_equal('profile', profileit#test())
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1308 disass profileit#test
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1309 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1310 CheckScriptSuccess(lines)
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1311
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1312 delete('Xdir', 'rf')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1313 &rtp = save_rtp
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1314 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1315
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1316 " test using a vim9script that is auto-loaded from an autocmd
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1317 def Test_vim9_aucmd_autoload()
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1318 var lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1319 vim9script
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1320 def foo#test()
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1321 echomsg getreg('"')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1322 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1323 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1324
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1325 mkdir('Xdir/autoload', 'p')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1326 writefile(lines, 'Xdir/autoload/foo.vim')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1327 var save_rtp = &rtp
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1328 exe 'set rtp^=' .. getcwd() .. '/Xdir'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1329 augroup test
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1330 autocmd TextYankPost * call foo#test()
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1331 augroup END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1332
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1333 normal Y
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1334
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1335 augroup test
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1336 autocmd!
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1337 augroup END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1338 delete('Xdir', 'rf')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1339 &rtp = save_rtp
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1340 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1341
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1342 " This was causing a crash because suppress_errthrow wasn't reset.
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1343 def Test_vim9_autoload_error()
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1344 var lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1345 vim9script
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1346 def crash#func()
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1347 try
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1348 for x in List()
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1349 endfor
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1350 catch
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1351 endtry
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1352 g:ok = true
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1353 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1354 fu List()
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1355 invalid
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1356 endfu
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1357 try
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1358 alsoinvalid
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1359 catch /wontmatch/
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1360 endtry
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1361 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1362 call mkdir('Xruntime/autoload', 'p')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1363 call writefile(lines, 'Xruntime/autoload/crash.vim')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1364
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1365 # run in a separate Vim to avoid the side effects of assert_fails()
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1366 lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1367 exe 'set rtp^=' .. getcwd() .. '/Xruntime'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1368 call crash#func()
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1369 call writefile(['ok'], 'Xdidit')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1370 qall!
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1371 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1372 writefile(lines, 'Xscript')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1373 RunVim([], [], '-S Xscript')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1374 assert_equal(['ok'], readfile('Xdidit'))
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1375
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1376 delete('Xdidit')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1377 delete('Xscript')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1378 delete('Xruntime', 'rf')
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1379
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1380 lines =<< trim END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1381 vim9script
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1382 var foo#bar = 'asdf'
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1383 END
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1384 CheckScriptFailure(lines, 'E461: Illegal variable name: foo#bar', 2)
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1385 enddef
8f6cab688901 patch 8.2.4057: Vim9: not fully implementing the autoload mechanism
Bram Moolenaar <Bram@vim.org>
parents: 27030
diff changeset
1386
27014
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387
b861ae62860d patch 8.2.4036: Vim9: script test file is getting too long
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker