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

patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent Commit: https://github.com/vim/vim/commit/62aec93bfdb9e1b40d03a6d2e8e9511f8b1bdb2d Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 29 21:45:34 2022 +0000 patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent Problem: Vim9: finding global function without g: prefix but not finding global variable is inconsistent. Solution: Require using g: for a global function. Change the vim9.vim script into a Vim9 script with exports. Fix that import in legacy script does not work.
author Bram Moolenaar <Bram@vim.org>
date Sat, 29 Jan 2022 23:00:05 +0100
parents 6f43253463cc
children 95d6e3c9aa1e
comparison
equal deleted inserted replaced
27456:a8e2d91995ce 27457:4c16acb2525f
2 2
3 source view_util.vim 3 source view_util.vim
4 source screendump.vim 4 source screendump.vim
5 source check.vim 5 source check.vim
6 source script_util.vim 6 source script_util.vim
7 source vim9.vim 7 import './vim9.vim' as v9
8 8
9 func ClearDict(d) 9 func ClearDict(d)
10 for k in keys(a:d) 10 for k in keys(a:d)
11 call remove(a:d, k) 11 call remove(a:d, k)
12 endfor 12 endfor
1009 call assert_equal('IncSearch', hlget('MyHLGroup')[0].linksto) 1009 call assert_equal('IncSearch', hlget('MyHLGroup')[0].linksto)
1010 highlight clear MyHLGroup 1010 highlight clear MyHLGroup
1011 call assert_equal([], hlget(test_null_string())) 1011 call assert_equal([], hlget(test_null_string()))
1012 call assert_equal([], hlget("")) 1012 call assert_equal([], hlget(""))
1013 END 1013 END
1014 call CheckLegacyAndVim9Success(lines) 1014 call v9.CheckLegacyAndVim9Success(lines)
1015 1015
1016 " Test for resolving highlight group links 1016 " Test for resolving highlight group links
1017 let lines =<< trim END 1017 let lines =<< trim END
1018 highlight hlgA term=bold 1018 highlight hlgA term=bold
1019 VAR hlgAid = hlID('hlgA') 1019 VAR hlgAid = hlID('hlgA')
1040 call assert_equal([{'id': hlgBid, 'name': 'hlgB', 1040 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1041 \ 'term': {'bold': v:true}}], hlget('hlgB', 1)) 1041 \ 'term': {'bold': v:true}}], hlget('hlgB', 1))
1042 call assert_equal([{'id': hlgCid, 'name': 'hlgC', 1042 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1043 \ 'term': {'bold': v:true}}], hlget('hlgC', v:true)) 1043 \ 'term': {'bold': v:true}}], hlget('hlgC', v:true))
1044 END 1044 END
1045 call CheckLegacyAndVim9Success(lines) 1045 call v9.CheckLegacyAndVim9Success(lines)
1046 1046
1047 call assert_fails('call hlget([])', 'E1174:') 1047 call assert_fails('call hlget([])', 'E1174:')
1048 call assert_fails('call hlget("abc", "xyz")', 'E1212:') 1048 call assert_fails('call hlget("abc", "xyz")', 'E1212:')
1049 endfunc 1049 endfunc
1050 1050
1096 call assert_fails("call hlset([{'name': 'NewHLGroup', 'term': 'Cyan'}])", 1096 call assert_fails("call hlset([{'name': 'NewHLGroup', 'term': 'Cyan'}])",
1097 \ 'E715:') 1097 \ 'E715:')
1098 call assert_equal('Search', hlget('NewHLGroup')[0].linksto) 1098 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1099 highlight clear NewHLGroup 1099 highlight clear NewHLGroup
1100 END 1100 END
1101 call CheckLegacyAndVim9Success(lines) 1101 call v9.CheckLegacyAndVim9Success(lines)
1102 1102
1103 " Test for clearing the 'term', 'cterm' and 'gui' attributes of a highlight 1103 " Test for clearing the 'term', 'cterm' and 'gui' attributes of a highlight
1104 " group. 1104 " group.
1105 let lines =<< trim END 1105 let lines =<< trim END
1106 highlight myhlg1 term=bold cterm=italic gui=standout 1106 highlight myhlg1 term=bold cterm=italic gui=standout
1115 call hlset([{'name': 'myhlg1', 'gui': {}}]) 1115 call hlset([{'name': 'myhlg1', 'gui': {}}])
1116 call assert_equal([{'id': id, 'name': 'myhlg1', 'cleared': v:true}], 1116 call assert_equal([{'id': id, 'name': 'myhlg1', 'cleared': v:true}],
1117 \ hlget('myhlg1')) 1117 \ hlget('myhlg1'))
1118 highlight clear myhlg1 1118 highlight clear myhlg1
1119 END 1119 END
1120 call CheckLegacyAndVim9Success(lines) 1120 call v9.CheckLegacyAndVim9Success(lines)
1121 1121
1122 " Test for setting all the 'term', 'cterm' and 'gui' attributes of a 1122 " Test for setting all the 'term', 'cterm' and 'gui' attributes of a
1123 " highlight group 1123 " highlight group
1124 let lines =<< trim END 1124 let lines =<< trim END
1125 VAR attr = {'bold': v:true, 'underline': v:true, 'undercurl': v:true, 1125 VAR attr = {'bold': v:true, 'underline': v:true, 'undercurl': v:true,
1132 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g') 1132 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1133 call assert_equal(expected, output) 1133 call assert_equal(expected, output)
1134 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr, 1134 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1135 \ 'term': attr, 'cterm': attr}], hlget('myhlg2')) 1135 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1136 END 1136 END
1137 call CheckLegacyAndVim9Success(lines) 1137 call v9.CheckLegacyAndVim9Success(lines)
1138 1138
1139 " Test for clearing some of the 'term', 'cterm' and 'gui' attributes of a 1139 " Test for clearing some of the 'term', 'cterm' and 'gui' attributes of a
1140 " highlight group 1140 " highlight group
1141 let lines =<< trim END 1141 let lines =<< trim END
1142 VAR attr = {'bold': v:false, 'underline': v:true, 'strikethrough': v:true} 1142 VAR attr = {'bold': v:false, 'underline': v:true, 'strikethrough': v:true}
1148 call assert_equal(expected, output) 1148 call assert_equal(expected, output)
1149 LET attr = {'underline': v:true, 'strikethrough': v:true} 1149 LET attr = {'underline': v:true, 'strikethrough': v:true}
1150 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr, 1150 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1151 \ 'term': attr, 'cterm': attr}], hlget('myhlg2')) 1151 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1152 END 1152 END
1153 call CheckLegacyAndVim9Success(lines) 1153 call v9.CheckLegacyAndVim9Success(lines)
1154 1154
1155 " Test for clearing the attributes and link of a highlight group 1155 " Test for clearing the attributes and link of a highlight group
1156 let lines =<< trim END 1156 let lines =<< trim END
1157 highlight myhlg3 ctermbg=green guibg=green 1157 highlight myhlg3 ctermbg=green guibg=green
1158 highlight! default link myhlg3 ErrorMsg 1158 highlight! default link myhlg3 ErrorMsg
1160 call hlset([{'name': 'myhlg3', 'cleared': v:true, 'linksto': 'NONE'}]) 1160 call hlset([{'name': 'myhlg3', 'cleared': v:true, 'linksto': 'NONE'}])
1161 call assert_equal([{'id': id3, 'name': 'myhlg3', 'cleared': v:true}], 1161 call assert_equal([{'id': id3, 'name': 'myhlg3', 'cleared': v:true}],
1162 \ hlget('myhlg3')) 1162 \ hlget('myhlg3'))
1163 highlight clear hlg3 1163 highlight clear hlg3
1164 END 1164 END
1165 call CheckLegacyAndVim9Success(lines) 1165 call v9.CheckLegacyAndVim9Success(lines)
1166 1166
1167 " Test for setting default attributes for a highlight group 1167 " Test for setting default attributes for a highlight group
1168 let lines =<< trim END 1168 let lines =<< trim END
1169 call hlset([{'name': 'hlg4', 'ctermfg': '8'}]) 1169 call hlset([{'name': 'hlg4', 'ctermfg': '8'}])
1170 call hlset([{'name': 'hlg4', 'default': v:true, 'ctermfg': '9'}]) 1170 call hlset([{'name': 'hlg4', 'default': v:true, 'ctermfg': '9'}])
1185 call hlset([{'name': 'hlg6', 'default': v:true, 'ctermbg': '2'}]) 1185 call hlset([{'name': 'hlg6', 'default': v:true, 'ctermbg': '2'}])
1186 call assert_equal([{'id': id6, 'name': 'hlg6', 'linksto': 'Error'}], 1186 call assert_equal([{'id': id6, 'name': 'hlg6', 'linksto': 'Error'}],
1187 \ hlget('hlg6')) 1187 \ hlget('hlg6'))
1188 highlight clear hlg6 1188 highlight clear hlg6
1189 END 1189 END
1190 call CheckLegacyAndVim9Success(lines) 1190 call v9.CheckLegacyAndVim9Success(lines)
1191 1191
1192 " Test for setting default links for a highlight group 1192 " Test for setting default links for a highlight group
1193 let lines =<< trim END 1193 let lines =<< trim END
1194 call hlset([{'name': 'hlg7', 'ctermfg': '5'}]) 1194 call hlset([{'name': 'hlg7', 'ctermfg': '5'}])
1195 call hlset([{'name': 'hlg7', 'default': v:true, 'linksto': 'Search'}]) 1195 call hlset([{'name': 'hlg7', 'default': v:true, 'linksto': 'Search'}])
1215 highlight clear hlg9dup 1215 highlight clear hlg9dup
1216 call assert_equal([{'id': id9, 'name': 'hlg9dup', 'default': v:true, 1216 call assert_equal([{'id': id9, 'name': 'hlg9dup', 'default': v:true,
1217 \ 'linksto': 'ErrorMsg'}], hlget('hlg9dup')) 1217 \ 'linksto': 'ErrorMsg'}], hlget('hlg9dup'))
1218 highlight clear hlg9 1218 highlight clear hlg9
1219 END 1219 END
1220 call CheckLegacyAndVim9Success(lines) 1220 call v9.CheckLegacyAndVim9Success(lines)
1221 1221
1222 " Test for force creating a link to a highlight group 1222 " Test for force creating a link to a highlight group
1223 let lines =<< trim END 1223 let lines =<< trim END
1224 call hlset([{'name': 'hlg10', 'ctermfg': '8'}]) 1224 call hlset([{'name': 'hlg10', 'ctermfg': '8'}])
1225 call hlset([{'name': 'hlg10', 'linksto': 'Search'}]) 1225 call hlset([{'name': 'hlg10', 'linksto': 'Search'}])
1229 call hlset([{'name': 'hlg10', 'linksto': 'Search', 'force': v:true}]) 1229 call hlset([{'name': 'hlg10', 'linksto': 'Search', 'force': v:true}])
1230 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8', 1230 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8',
1231 \ 'linksto': 'Search'}], hlget('hlg10')) 1231 \ 'linksto': 'Search'}], hlget('hlg10'))
1232 highlight clear hlg10 1232 highlight clear hlg10
1233 END 1233 END
1234 call CheckLegacyAndVim9Success(lines) 1234 call v9.CheckLegacyAndVim9Success(lines)
1235 1235
1236 " Test for empty values of attributes 1236 " Test for empty values of attributes
1237 call hlset([{'name': 'hlg11', 'cterm': {}}]) 1237 call hlset([{'name': 'hlg11', 'cterm': {}}])
1238 call hlset([{'name': 'hlg11', 'ctermfg': ''}]) 1238 call hlset([{'name': 'hlg11', 'ctermfg': ''}])
1239 call hlset([{'name': 'hlg11', 'ctermbg': ''}]) 1239 call hlset([{'name': 'hlg11', 'ctermbg': ''}])