comparison src/testdir/test_ins_complete.vim @ 26526:33d680d372aa v8.2.3792

patch 8.2.3792: setting *func options insufficiently tested Commit: https://github.com/vim/vim/commit/04ef1fb13d200f770952e670357dddadb6210dd4 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sun Dec 12 20:08:05 2021 +0000 patch 8.2.3792: setting *func options insufficiently tested Problem: Setting *func options insufficiently tested. Solution: Impove tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/9337)
author Bram Moolenaar <Bram@vim.org>
date Sun, 12 Dec 2021 21:15:03 +0100
parents 13ba00ef7687
children b531c26f728b
comparison
equal deleted inserted replaced
26525:508ea60b5118 26526:33d680d372aa
868 close! 868 close!
869 endfunc 869 endfunc
870 870
871 " Test for different ways of setting the 'completefunc' option 871 " Test for different ways of setting the 'completefunc' option
872 func Test_completefunc_callback() 872 func Test_completefunc_callback()
873 func MycompleteFunc1(val, findstart, base) 873 func CompleteFunc1(callnr, findstart, base)
874 call add(g:MycompleteFunc1_args, [a:val, a:findstart, a:base]) 874 call add(g:CompleteFunc1Args, [a:callnr, a:findstart, a:base])
875 return a:findstart ? 0 : [] 875 return a:findstart ? 0 : []
876 endfunc 876 endfunc
877 func CompleteFunc2(findstart, base)
878 call add(g:CompleteFunc2Args, [a:findstart, a:base])
879 return a:findstart ? 0 : []
880 endfunc
877 881
878 let lines =<< trim END 882 let lines =<< trim END
883 #" Test for using a function name
884 LET &completefunc = 'g:CompleteFunc2'
885 new
886 call setline(1, 'zero')
887 LET g:CompleteFunc2Args = []
888 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
889 call assert_equal([[1, ''], [0, 'zero']], g:CompleteFunc2Args)
890 bw!
891
879 #" Test for using a function() 892 #" Test for using a function()
880 set completefunc=function('g:MycompleteFunc1',\ [10]) 893 set completefunc=function('g:CompleteFunc1',\ [10])
881 new | only 894 new
882 call setline(1, 'one') 895 call setline(1, 'one')
883 LET g:MycompleteFunc1_args = [] 896 LET g:CompleteFunc1Args = []
884 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 897 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
885 call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MycompleteFunc1_args) 898 call assert_equal([[10, 1, ''], [10, 0, 'one']], g:CompleteFunc1Args)
886 bw! 899 bw!
887 900
888 #" Using a funcref variable to set 'completefunc' 901 #" Using a funcref variable to set 'completefunc'
889 VAR Fn = function('g:MycompleteFunc1', [11]) 902 VAR Fn = function('g:CompleteFunc1', [11])
890 LET &completefunc = Fn 903 LET &completefunc = Fn
891 new | only 904 new
892 call setline(1, 'two') 905 call setline(1, 'two')
893 LET g:MycompleteFunc1_args = [] 906 LET g:CompleteFunc1Args = []
894 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 907 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
895 call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MycompleteFunc1_args) 908 call assert_equal([[11, 1, ''], [11, 0, 'two']], g:CompleteFunc1Args)
896 bw! 909 bw!
897 910
898 #" Using string(funcref_variable) to set 'completefunc' 911 #" Using string(funcref_variable) to set 'completefunc'
899 LET Fn = function('g:MycompleteFunc1', [12]) 912 LET Fn = function('g:CompleteFunc1', [12])
900 LET &completefunc = string(Fn) 913 LET &completefunc = string(Fn)
901 new | only 914 new
902 call setline(1, 'two') 915 call setline(1, 'two')
903 LET g:MycompleteFunc1_args = [] 916 LET g:CompleteFunc1Args = []
904 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 917 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
905 call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MycompleteFunc1_args) 918 call assert_equal([[12, 1, ''], [12, 0, 'two']], g:CompleteFunc1Args)
906 bw! 919 bw!
907 920
908 #" Test for using a funcref() 921 #" Test for using a funcref()
909 set completefunc=funcref('g:MycompleteFunc1',\ [13]) 922 set completefunc=funcref('g:CompleteFunc1',\ [13])
910 new | only 923 new
911 call setline(1, 'three') 924 call setline(1, 'three')
912 LET g:MycompleteFunc1_args = [] 925 LET g:CompleteFunc1Args = []
913 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 926 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
914 call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MycompleteFunc1_args) 927 call assert_equal([[13, 1, ''], [13, 0, 'three']], g:CompleteFunc1Args)
915 bw! 928 bw!
916 929
917 #" Using a funcref variable to set 'completefunc' 930 #" Using a funcref variable to set 'completefunc'
918 LET Fn = funcref('g:MycompleteFunc1', [14]) 931 LET Fn = funcref('g:CompleteFunc1', [14])
919 LET &completefunc = Fn 932 LET &completefunc = Fn
920 new | only 933 new
921 call setline(1, 'four') 934 call setline(1, 'four')
922 LET g:MycompleteFunc1_args = [] 935 LET g:CompleteFunc1Args = []
923 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 936 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
924 call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MycompleteFunc1_args) 937 call assert_equal([[14, 1, ''], [14, 0, 'four']], g:CompleteFunc1Args)
925 bw! 938 bw!
926 939
927 #" Using a string(funcref_variable) to set 'completefunc' 940 #" Using a string(funcref_variable) to set 'completefunc'
928 LET Fn = funcref('g:MycompleteFunc1', [15]) 941 LET Fn = funcref('g:CompleteFunc1', [15])
929 LET &completefunc = string(Fn) 942 LET &completefunc = string(Fn)
930 new | only 943 new
931 call setline(1, 'four') 944 call setline(1, 'four')
932 LET g:MycompleteFunc1_args = [] 945 LET g:CompleteFunc1Args = []
933 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 946 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
934 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MycompleteFunc1_args) 947 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:CompleteFunc1Args)
935 bw! 948 bw!
936 949
937 #" Test for using a lambda function with set 950 #" Test for using a lambda function with set
938 VAR optval = "LSTART a, b LMIDDLE MycompleteFunc1(16, a, b) LEND" 951 VAR optval = "LSTART a, b LMIDDLE CompleteFunc1(16, a, b) LEND"
939 LET optval = substitute(optval, ' ', '\\ ', 'g') 952 LET optval = substitute(optval, ' ', '\\ ', 'g')
940 exe "set completefunc=" .. optval 953 exe "set completefunc=" .. optval
941 new | only 954 new
942 call setline(1, 'five') 955 call setline(1, 'five')
943 LET g:MycompleteFunc1_args = [] 956 LET g:CompleteFunc1Args = []
944 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 957 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
945 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MycompleteFunc1_args) 958 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:CompleteFunc1Args)
946 bw! 959 bw!
947 960
948 #" Set 'completefunc' to a lambda expression 961 #" Set 'completefunc' to a lambda expression
949 LET &completefunc = LSTART a, b LMIDDLE MycompleteFunc1(17, a, b) LEND 962 LET &completefunc = LSTART a, b LMIDDLE CompleteFunc1(17, a, b) LEND
950 new | only 963 new
951 call setline(1, 'six') 964 call setline(1, 'six')
952 LET g:MycompleteFunc1_args = [] 965 LET g:CompleteFunc1Args = []
953 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 966 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
954 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MycompleteFunc1_args) 967 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:CompleteFunc1Args)
955 bw! 968 bw!
956 969
957 #" Set 'completefunc' to string(lambda_expression) 970 #" Set 'completefunc' to string(lambda_expression)
958 LET &completefunc = 'LSTART a, b LMIDDLE MycompleteFunc1(18, a, b) LEND' 971 LET &completefunc = 'LSTART a, b LMIDDLE CompleteFunc1(18, a, b) LEND'
959 new | only 972 new
960 call setline(1, 'six') 973 call setline(1, 'six')
961 LET g:MycompleteFunc1_args = [] 974 LET g:CompleteFunc1Args = []
962 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 975 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
963 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MycompleteFunc1_args) 976 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:CompleteFunc1Args)
964 bw! 977 bw!
965 978
966 #" Set 'completefunc' to a variable with a lambda expression 979 #" Set 'completefunc' to a variable with a lambda expression
967 VAR Lambda = LSTART a, b LMIDDLE MycompleteFunc1(19, a, b) LEND 980 VAR Lambda = LSTART a, b LMIDDLE CompleteFunc1(19, a, b) LEND
968 LET &completefunc = Lambda 981 LET &completefunc = Lambda
969 new | only 982 new
970 call setline(1, 'seven') 983 call setline(1, 'seven')
971 LET g:MycompleteFunc1_args = [] 984 LET g:CompleteFunc1Args = []
972 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 985 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
973 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MycompleteFunc1_args) 986 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:CompleteFunc1Args)
974 bw! 987 bw!
975 988
976 #" Set 'completefunc' to a string(variable with a lambda expression) 989 #" Set 'completefunc' to a string(variable with a lambda expression)
977 LET Lambda = LSTART a, b LMIDDLE MycompleteFunc1(20, a, b) LEND 990 LET Lambda = LSTART a, b LMIDDLE CompleteFunc1(20, a, b) LEND
978 LET &completefunc = string(Lambda) 991 LET &completefunc = string(Lambda)
979 new | only 992 new
980 call setline(1, 'seven') 993 call setline(1, 'seven')
981 LET g:MycompleteFunc1_args = [] 994 LET g:CompleteFunc1Args = []
982 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 995 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
983 call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MycompleteFunc1_args) 996 call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:CompleteFunc1Args)
984 bw! 997 bw!
985 998
986 #" Test for using a lambda function with incorrect return value 999 #" Test for using a lambda function with incorrect return value
987 LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND 1000 LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
988 LET &completefunc = Lambda 1001 LET &completefunc = Lambda
989 new | only 1002 new
990 call setline(1, 'eight') 1003 call setline(1, 'eight')
991 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 1004 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
992 bw! 1005 bw!
993 1006
994 #" Test for clearing the 'completefunc' option 1007 #" Test for clearing the 'completefunc' option
996 set completefunc& 1009 set completefunc&
997 call assert_fails("set completefunc=function('abc')", "E700:") 1010 call assert_fails("set completefunc=function('abc')", "E700:")
998 call assert_fails("set completefunc=funcref('abc')", "E700:") 1011 call assert_fails("set completefunc=funcref('abc')", "E700:")
999 1012
1000 #" set 'completefunc' to a non-existing function 1013 #" set 'completefunc' to a non-existing function
1001 func MycompleteFunc2(findstart, base) 1014 set completefunc=CompleteFunc2
1002 call add(g:MycompleteFunc2_args, [a:findstart, a:base])
1003 return a:findstart ? 0 : []
1004 endfunc
1005 set completefunc=MycompleteFunc2
1006 call setline(1, 'five') 1015 call setline(1, 'five')
1007 call assert_fails("set completefunc=function('NonExistingFunc')", 'E700:') 1016 call assert_fails("set completefunc=function('NonExistingFunc')", 'E700:')
1008 call assert_fails("LET &completefunc = function('NonExistingFunc')", 'E700:') 1017 call assert_fails("LET &completefunc = function('NonExistingFunc')", 'E700:')
1009 LET g:MycompleteFunc2_args = [] 1018 LET g:CompleteFunc2Args = []
1010 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 1019 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
1011 call assert_equal([[1, ''], [0, 'five']], g:MycompleteFunc2_args) 1020 call assert_equal([[1, ''], [0, 'five']], g:CompleteFunc2Args)
1012 bw! 1021 bw!
1013 END 1022 END
1014 call CheckLegacyAndVim9Success(lines) 1023 call CheckLegacyAndVim9Success(lines)
1015 1024
1016 let &completefunc = {a -> 'abc'} 1025 let &completefunc = {a -> 'abc'}
1017 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x') 1026 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
1018 1027
1019 " Using Vim9 lambda expression in legacy context should fail 1028 " Using Vim9 lambda expression in legacy context should fail
1020 set completefunc=(a,\ b)\ =>\ MycompleteFunc1(21,\ a,\ b) 1029 set completefunc=(a,\ b)\ =>\ CompleteFunc1(21,\ a,\ b)
1021 new | only 1030 new | only
1022 let g:MycompleteFunc1_args = [] 1031 let g:CompleteFunc1Args = []
1023 call assert_fails('call feedkeys("A\<C-X>\<C-U>\<Esc>", "x")', 'E117:') 1032 call assert_fails('call feedkeys("A\<C-X>\<C-U>\<Esc>", "x")', 'E117:')
1024 call assert_equal([], g:MycompleteFunc1_args) 1033 call assert_equal([], g:CompleteFunc1Args)
1025 1034
1026 " set 'completefunc' to a partial with dict. This used to cause a crash. 1035 " set 'completefunc' to a partial with dict. This used to cause a crash.
1027 func SetCompleteFunc() 1036 func SetCompleteFunc()
1028 let params = {'complete': function('g:DictCompleteFunc')} 1037 let params = {'complete': function('g:DictCompleteFunc')}
1029 let &completefunc = params.complete 1038 let &completefunc = params.complete
1061 bw! 1070 bw!
1062 END 1071 END
1063 call CheckScriptSuccess(lines) 1072 call CheckScriptSuccess(lines)
1064 1073
1065 " cleanup 1074 " cleanup
1066 delfunc MycompleteFunc1
1067 delfunc MycompleteFunc2
1068 set completefunc& 1075 set completefunc&
1076 delfunc CompleteFunc1
1077 delfunc CompleteFunc2
1078 unlet g:CompleteFunc1Args g:CompleteFunc2Args
1069 %bw! 1079 %bw!
1070 endfunc 1080 endfunc
1071 1081
1072 " Test for different ways of setting the 'omnifunc' option 1082 " Test for different ways of setting the 'omnifunc' option
1073 func Test_omnifunc_callback() 1083 func Test_omnifunc_callback()
1074 func MyomniFunc1(val, findstart, base) 1084 func OmniFunc1(callnr, findstart, base)
1075 call add(g:MyomniFunc1_args, [a:val, a:findstart, a:base]) 1085 call add(g:OmniFunc1Args, [a:callnr, a:findstart, a:base])
1076 return a:findstart ? 0 : [] 1086 return a:findstart ? 0 : []
1077 endfunc 1087 endfunc
1088 func OmniFunc2(findstart, base)
1089 call add(g:OmniFunc2Args, [a:findstart, a:base])
1090 return a:findstart ? 0 : []
1091 endfunc
1078 1092
1079 let lines =<< trim END 1093 let lines =<< trim END
1094 #" Test for using a function name
1095 LET &omnifunc = 'g:OmniFunc2'
1096 new
1097 call setline(1, 'zero')
1098 LET g:OmniFunc2Args = []
1099 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1100 call assert_equal([[1, ''], [0, 'zero']], g:OmniFunc2Args)
1101 bw!
1102
1080 #" Test for using a function() 1103 #" Test for using a function()
1081 set omnifunc=function('g:MyomniFunc1',\ [10]) 1104 set omnifunc=function('g:OmniFunc1',\ [10])
1082 new | only 1105 new
1083 call setline(1, 'one') 1106 call setline(1, 'one')
1084 LET g:MyomniFunc1_args = [] 1107 LET g:OmniFunc1Args = []
1085 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1108 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1086 call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MyomniFunc1_args) 1109 call assert_equal([[10, 1, ''], [10, 0, 'one']], g:OmniFunc1Args)
1087 bw! 1110 bw!
1088 1111
1089 #" Using a funcref variable to set 'omnifunc' 1112 #" Using a funcref variable to set 'omnifunc'
1090 VAR Fn = function('g:MyomniFunc1', [11]) 1113 VAR Fn = function('g:OmniFunc1', [11])
1091 LET &omnifunc = Fn 1114 LET &omnifunc = Fn
1092 new | only 1115 new
1093 call setline(1, 'two') 1116 call setline(1, 'two')
1094 LET g:MyomniFunc1_args = [] 1117 LET g:OmniFunc1Args = []
1095 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1118 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1096 call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MyomniFunc1_args) 1119 call assert_equal([[11, 1, ''], [11, 0, 'two']], g:OmniFunc1Args)
1097 bw! 1120 bw!
1098 1121
1099 #" Using a string(funcref_variable) to set 'omnifunc' 1122 #" Using a string(funcref_variable) to set 'omnifunc'
1100 LET Fn = function('g:MyomniFunc1', [12]) 1123 LET Fn = function('g:OmniFunc1', [12])
1101 LET &omnifunc = string(Fn) 1124 LET &omnifunc = string(Fn)
1102 new | only 1125 new
1103 call setline(1, 'two') 1126 call setline(1, 'two')
1104 LET g:MyomniFunc1_args = [] 1127 LET g:OmniFunc1Args = []
1105 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1128 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1106 call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MyomniFunc1_args) 1129 call assert_equal([[12, 1, ''], [12, 0, 'two']], g:OmniFunc1Args)
1107 bw! 1130 bw!
1108 1131
1109 #" Test for using a funcref() 1132 #" Test for using a funcref()
1110 set omnifunc=funcref('g:MyomniFunc1',\ [13]) 1133 set omnifunc=funcref('g:OmniFunc1',\ [13])
1111 new | only 1134 new
1112 call setline(1, 'three') 1135 call setline(1, 'three')
1113 LET g:MyomniFunc1_args = [] 1136 LET g:OmniFunc1Args = []
1114 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1137 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1115 call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MyomniFunc1_args) 1138 call assert_equal([[13, 1, ''], [13, 0, 'three']], g:OmniFunc1Args)
1116 bw! 1139 bw!
1117 1140
1118 #" Use let to set 'omnifunc' to a funcref 1141 #" Use let to set 'omnifunc' to a funcref
1119 LET Fn = funcref('g:MyomniFunc1', [14]) 1142 LET Fn = funcref('g:OmniFunc1', [14])
1120 LET &omnifunc = Fn 1143 LET &omnifunc = Fn
1121 new | only 1144 new
1122 call setline(1, 'four') 1145 call setline(1, 'four')
1123 LET g:MyomniFunc1_args = [] 1146 LET g:OmniFunc1Args = []
1124 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1147 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1125 call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MyomniFunc1_args) 1148 call assert_equal([[14, 1, ''], [14, 0, 'four']], g:OmniFunc1Args)
1126 bw! 1149 bw!
1127 1150
1128 #" Using a string(funcref) to set 'omnifunc' 1151 #" Using a string(funcref) to set 'omnifunc'
1129 LET Fn = funcref("g:MyomniFunc1", [15]) 1152 LET Fn = funcref("g:OmniFunc1", [15])
1130 LET &omnifunc = string(Fn) 1153 LET &omnifunc = string(Fn)
1131 new | only 1154 new
1132 call setline(1, 'four') 1155 call setline(1, 'four')
1133 LET g:MyomniFunc1_args = [] 1156 LET g:OmniFunc1Args = []
1134 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1157 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1135 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MyomniFunc1_args) 1158 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:OmniFunc1Args)
1136 bw! 1159 bw!
1137 1160
1138 #" Test for using a lambda function with set 1161 #" Test for using a lambda function with set
1139 VAR optval = "LSTART a, b LMIDDLE MyomniFunc1(16, a, b) LEND" 1162 VAR optval = "LSTART a, b LMIDDLE OmniFunc1(16, a, b) LEND"
1140 LET optval = substitute(optval, ' ', '\\ ', 'g') 1163 LET optval = substitute(optval, ' ', '\\ ', 'g')
1141 exe "set omnifunc=" .. optval 1164 exe "set omnifunc=" .. optval
1142 new | only 1165 new
1143 call setline(1, 'five') 1166 call setline(1, 'five')
1144 LET g:MyomniFunc1_args = [] 1167 LET g:OmniFunc1Args = []
1145 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1168 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1146 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MyomniFunc1_args) 1169 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:OmniFunc1Args)
1147 bw! 1170 bw!
1148 1171
1149 #" Set 'omnifunc' to a lambda expression 1172 #" Set 'omnifunc' to a lambda expression
1150 LET &omnifunc = LSTART a, b LMIDDLE MyomniFunc1(17, a, b) LEND 1173 LET &omnifunc = LSTART a, b LMIDDLE OmniFunc1(17, a, b) LEND
1151 new | only 1174 new
1152 call setline(1, 'six') 1175 call setline(1, 'six')
1153 LET g:MyomniFunc1_args = [] 1176 LET g:OmniFunc1Args = []
1154 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1177 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1155 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MyomniFunc1_args) 1178 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:OmniFunc1Args)
1156 bw! 1179 bw!
1157 1180
1158 #" Set 'omnifunc' to a string(lambda_expression) 1181 #" Set 'omnifunc' to a string(lambda_expression)
1159 LET &omnifunc = 'LSTART a, b LMIDDLE MyomniFunc1(18, a, b) LEND' 1182 LET &omnifunc = 'LSTART a, b LMIDDLE OmniFunc1(18, a, b) LEND'
1160 new | only 1183 new
1161 call setline(1, 'six') 1184 call setline(1, 'six')
1162 LET g:MyomniFunc1_args = [] 1185 LET g:OmniFunc1Args = []
1163 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1186 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1164 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MyomniFunc1_args) 1187 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:OmniFunc1Args)
1165 bw! 1188 bw!
1166 1189
1167 #" Set 'omnifunc' to a variable with a lambda expression 1190 #" Set 'omnifunc' to a variable with a lambda expression
1168 VAR Lambda = LSTART a, b LMIDDLE MyomniFunc1(19, a, b) LEND 1191 VAR Lambda = LSTART a, b LMIDDLE OmniFunc1(19, a, b) LEND
1169 LET &omnifunc = Lambda 1192 LET &omnifunc = Lambda
1170 new | only 1193 new
1171 call setline(1, 'seven') 1194 call setline(1, 'seven')
1172 LET g:MyomniFunc1_args = [] 1195 LET g:OmniFunc1Args = []
1173 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1196 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1174 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MyomniFunc1_args) 1197 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:OmniFunc1Args)
1175 bw! 1198 bw!
1176 1199
1177 #" Set 'omnifunc' to a string(variable with a lambda expression) 1200 #" Set 'omnifunc' to a string(variable with a lambda expression)
1178 LET Lambda = LSTART a, b LMIDDLE MyomniFunc1(20, a, b) LEND 1201 LET Lambda = LSTART a, b LMIDDLE OmniFunc1(20, a, b) LEND
1179 LET &omnifunc = string(Lambda) 1202 LET &omnifunc = string(Lambda)
1180 new | only 1203 new
1181 call setline(1, 'seven') 1204 call setline(1, 'seven')
1182 LET g:MyomniFunc1_args = [] 1205 LET g:OmniFunc1Args = []
1183 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1206 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1184 call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MyomniFunc1_args) 1207 call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:OmniFunc1Args)
1185 bw! 1208 bw!
1186 1209
1187 #" Test for using a lambda function with incorrect return value 1210 #" Test for using a lambda function with incorrect return value
1188 LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND 1211 LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
1189 LET &omnifunc = Lambda 1212 LET &omnifunc = Lambda
1190 new | only 1213 new
1191 call setline(1, 'eight') 1214 call setline(1, 'eight')
1192 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1215 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1193 bw! 1216 bw!
1194 1217
1195 #" Test for clearing the 'omnifunc' option 1218 #" Test for clearing the 'omnifunc' option
1197 set omnifunc& 1220 set omnifunc&
1198 call assert_fails("set omnifunc=function('abc')", "E700:") 1221 call assert_fails("set omnifunc=function('abc')", "E700:")
1199 call assert_fails("set omnifunc=funcref('abc')", "E700:") 1222 call assert_fails("set omnifunc=funcref('abc')", "E700:")
1200 1223
1201 #" set 'omnifunc' to a non-existing function 1224 #" set 'omnifunc' to a non-existing function
1202 func MyomniFunc2(findstart, base) 1225 set omnifunc=OmniFunc2
1203 call add(g:MyomniFunc2_args, [a:findstart, a:base])
1204 return a:findstart ? 0 : []
1205 endfunc
1206 set omnifunc=MyomniFunc2
1207 call setline(1, 'nine') 1226 call setline(1, 'nine')
1208 call assert_fails("set omnifunc=function('NonExistingFunc')", 'E700:') 1227 call assert_fails("set omnifunc=function('NonExistingFunc')", 'E700:')
1209 call assert_fails("LET &omnifunc = function('NonExistingFunc')", 'E700:') 1228 call assert_fails("LET &omnifunc = function('NonExistingFunc')", 'E700:')
1210 LET g:MyomniFunc2_args = [] 1229 LET g:OmniFunc2Args = []
1211 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1230 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1212 call assert_equal([[1, ''], [0, 'nine']], g:MyomniFunc2_args) 1231 call assert_equal([[1, ''], [0, 'nine']], g:OmniFunc2Args)
1213 bw! 1232 bw!
1214 END 1233 END
1215 call CheckLegacyAndVim9Success(lines) 1234 call CheckLegacyAndVim9Success(lines)
1216 1235
1217 let &omnifunc = {a -> 'abc'} 1236 let &omnifunc = {a -> 'abc'}
1218 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') 1237 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
1219 1238
1220 " Using Vim9 lambda expression in legacy context should fail 1239 " Using Vim9 lambda expression in legacy context should fail
1221 set omnifunc=(a,\ b)\ =>\ MyomniFunc1(21,\ a,\ b) 1240 set omnifunc=(a,\ b)\ =>\ OmniFunc1(21,\ a,\ b)
1222 new | only 1241 new | only
1223 let g:MyomniFunc1_args = [] 1242 let g:OmniFunc1Args = []
1224 call assert_fails('call feedkeys("A\<C-X>\<C-O>\<Esc>", "x")', 'E117:') 1243 call assert_fails('call feedkeys("A\<C-X>\<C-O>\<Esc>", "x")', 'E117:')
1225 call assert_equal([], g:MyomniFunc1_args) 1244 call assert_equal([], g:OmniFunc1Args)
1226 1245
1227 " set 'omnifunc' to a partial with dict. This used to cause a crash. 1246 " set 'omnifunc' to a partial with dict. This used to cause a crash.
1228 func SetOmniFunc() 1247 func SetOmniFunc()
1229 let params = {'omni': function('g:DictOmniFunc')} 1248 let params = {'omni': function('g:DictOmniFunc')}
1230 let &omnifunc = params.omni 1249 let &omnifunc = params.omni
1262 bw! 1281 bw!
1263 END 1282 END
1264 call CheckScriptSuccess(lines) 1283 call CheckScriptSuccess(lines)
1265 1284
1266 " cleanup 1285 " cleanup
1267 delfunc MyomniFunc1
1268 delfunc MyomniFunc2
1269 set omnifunc& 1286 set omnifunc&
1287 delfunc OmniFunc1
1288 delfunc OmniFunc2
1289 unlet g:OmniFunc1Args g:OmniFunc2Args
1270 %bw! 1290 %bw!
1271 endfunc 1291 endfunc
1272 1292
1273 " Test for different ways of setting the 'thesaurusfunc' option 1293 " Test for different ways of setting the 'thesaurusfunc' option
1274 func Test_thesaurusfunc_callback() 1294 func Test_thesaurusfunc_callback()
1275 func MytsrFunc1(val, findstart, base) 1295 func TsrFunc1(callnr, findstart, base)
1276 call add(g:MytsrFunc1_args, [a:val, a:findstart, a:base]) 1296 call add(g:TsrFunc1Args, [a:callnr, a:findstart, a:base])
1277 return a:findstart ? 0 : [] 1297 return a:findstart ? 0 : []
1278 endfunc 1298 endfunc
1299 func TsrFunc2(findstart, base)
1300 call add(g:TsrFunc2Args, [a:findstart, a:base])
1301 return a:findstart ? 0 : ['sunday']
1302 endfunc
1279 1303
1280 let lines =<< trim END 1304 let lines =<< trim END
1305 #" Test for using a function name
1306 LET &thesaurusfunc = 'g:TsrFunc2'
1307 new
1308 call setline(1, 'zero')
1309 LET g:TsrFunc2Args = []
1310 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1311 call assert_equal([[1, ''], [0, 'zero']], g:TsrFunc2Args)
1312 bw!
1313
1281 #" Test for using a function() 1314 #" Test for using a function()
1282 set thesaurusfunc=function('g:MytsrFunc1',\ [10]) 1315 set thesaurusfunc=function('g:TsrFunc1',\ [10])
1283 new | only 1316 new
1284 call setline(1, 'one') 1317 call setline(1, 'one')
1285 LET g:MytsrFunc1_args = [] 1318 LET g:TsrFunc1Args = []
1286 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1319 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1287 call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MytsrFunc1_args) 1320 call assert_equal([[10, 1, ''], [10, 0, 'one']], g:TsrFunc1Args)
1288 bw! 1321 bw!
1289 1322
1290 #" Using a funcref variable to set 'thesaurusfunc' 1323 #" Using a funcref variable to set 'thesaurusfunc'
1291 VAR Fn = function('g:MytsrFunc1', [11]) 1324 VAR Fn = function('g:TsrFunc1', [11])
1292 LET &thesaurusfunc = Fn 1325 LET &thesaurusfunc = Fn
1293 new | only 1326 new
1294 call setline(1, 'two') 1327 call setline(1, 'two')
1295 LET g:MytsrFunc1_args = [] 1328 LET g:TsrFunc1Args = []
1296 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1329 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1297 call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MytsrFunc1_args) 1330 call assert_equal([[11, 1, ''], [11, 0, 'two']], g:TsrFunc1Args)
1298 bw! 1331 bw!
1299 1332
1300 #" Using a string(funcref_variable) to set 'thesaurusfunc' 1333 #" Using a string(funcref_variable) to set 'thesaurusfunc'
1301 LET Fn = function('g:MytsrFunc1', [12]) 1334 LET Fn = function('g:TsrFunc1', [12])
1302 LET &thesaurusfunc = string(Fn) 1335 LET &thesaurusfunc = string(Fn)
1303 new | only 1336 new
1304 call setline(1, 'two') 1337 call setline(1, 'two')
1305 LET g:MytsrFunc1_args = [] 1338 LET g:TsrFunc1Args = []
1306 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1339 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1307 call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MytsrFunc1_args) 1340 call assert_equal([[12, 1, ''], [12, 0, 'two']], g:TsrFunc1Args)
1308 bw! 1341 bw!
1309 1342
1310 #" Test for using a funcref() 1343 #" Test for using a funcref()
1311 set thesaurusfunc=funcref('g:MytsrFunc1',\ [13]) 1344 set thesaurusfunc=funcref('g:TsrFunc1',\ [13])
1312 new | only 1345 new
1313 call setline(1, 'three') 1346 call setline(1, 'three')
1314 LET g:MytsrFunc1_args = [] 1347 LET g:TsrFunc1Args = []
1315 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1348 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1316 call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MytsrFunc1_args) 1349 call assert_equal([[13, 1, ''], [13, 0, 'three']], g:TsrFunc1Args)
1317 bw! 1350 bw!
1318 1351
1319 #" Using a funcref variable to set 'thesaurusfunc' 1352 #" Using a funcref variable to set 'thesaurusfunc'
1320 LET Fn = funcref('g:MytsrFunc1', [14]) 1353 LET Fn = funcref('g:TsrFunc1', [14])
1321 LET &thesaurusfunc = Fn 1354 LET &thesaurusfunc = Fn
1322 new | only 1355 new
1323 call setline(1, 'four') 1356 call setline(1, 'four')
1324 LET g:MytsrFunc1_args = [] 1357 LET g:TsrFunc1Args = []
1325 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1358 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1326 call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MytsrFunc1_args) 1359 call assert_equal([[14, 1, ''], [14, 0, 'four']], g:TsrFunc1Args)
1327 bw! 1360 bw!
1328 1361
1329 #" Using a string(funcref_variable) to set 'thesaurusfunc' 1362 #" Using a string(funcref_variable) to set 'thesaurusfunc'
1330 LET Fn = funcref('g:MytsrFunc1', [15]) 1363 LET Fn = funcref('g:TsrFunc1', [15])
1331 LET &thesaurusfunc = string(Fn) 1364 LET &thesaurusfunc = string(Fn)
1332 new | only 1365 new
1333 call setline(1, 'four') 1366 call setline(1, 'four')
1334 LET g:MytsrFunc1_args = [] 1367 LET g:TsrFunc1Args = []
1335 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1368 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1336 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MytsrFunc1_args) 1369 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:TsrFunc1Args)
1337 bw! 1370 bw!
1338 1371
1339 #" Test for using a lambda function 1372 #" Test for using a lambda function
1340 VAR optval = "LSTART a, b LMIDDLE MytsrFunc1(16, a, b) LEND" 1373 VAR optval = "LSTART a, b LMIDDLE TsrFunc1(16, a, b) LEND"
1341 LET optval = substitute(optval, ' ', '\\ ', 'g') 1374 LET optval = substitute(optval, ' ', '\\ ', 'g')
1342 exe "set thesaurusfunc=" .. optval 1375 exe "set thesaurusfunc=" .. optval
1343 new | only 1376 new
1344 call setline(1, 'five') 1377 call setline(1, 'five')
1345 LET g:MytsrFunc1_args = [] 1378 LET g:TsrFunc1Args = []
1346 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1379 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1347 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MytsrFunc1_args) 1380 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:TsrFunc1Args)
1348 bw! 1381 bw!
1349 1382
1350 #" Test for using a lambda function with set 1383 #" Test for using a lambda function with set
1351 LET &thesaurusfunc = LSTART a, b LMIDDLE MytsrFunc1(17, a, b) LEND 1384 LET &thesaurusfunc = LSTART a, b LMIDDLE TsrFunc1(17, a, b) LEND
1352 new | only 1385 new
1353 call setline(1, 'six') 1386 call setline(1, 'six')
1354 LET g:MytsrFunc1_args = [] 1387 LET g:TsrFunc1Args = []
1355 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1388 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1356 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MytsrFunc1_args) 1389 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:TsrFunc1Args)
1357 bw! 1390 bw!
1358 1391
1359 #" Set 'thesaurusfunc' to a string(lambda expression) 1392 #" Set 'thesaurusfunc' to a string(lambda expression)
1360 LET &thesaurusfunc = 'LSTART a, b LMIDDLE MytsrFunc1(18, a, b) LEND' 1393 LET &thesaurusfunc = 'LSTART a, b LMIDDLE TsrFunc1(18, a, b) LEND'
1361 new | only 1394 new
1362 call setline(1, 'six') 1395 call setline(1, 'six')
1363 LET g:MytsrFunc1_args = [] 1396 LET g:TsrFunc1Args = []
1364 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1397 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1365 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MytsrFunc1_args) 1398 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:TsrFunc1Args)
1366 bw! 1399 bw!
1367 1400
1368 #" Set 'thesaurusfunc' to a variable with a lambda expression 1401 #" Set 'thesaurusfunc' to a variable with a lambda expression
1369 VAR Lambda = LSTART a, b LMIDDLE MytsrFunc1(19, a, b) LEND 1402 VAR Lambda = LSTART a, b LMIDDLE TsrFunc1(19, a, b) LEND
1370 LET &thesaurusfunc = Lambda 1403 LET &thesaurusfunc = Lambda
1371 new | only 1404 new
1372 call setline(1, 'seven') 1405 call setline(1, 'seven')
1373 LET g:MytsrFunc1_args = [] 1406 LET g:TsrFunc1Args = []
1374 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1407 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1375 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MytsrFunc1_args) 1408 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:TsrFunc1Args)
1376 bw! 1409 bw!
1377 1410
1378 #" Set 'thesaurusfunc' to a string(variable with a lambda expression) 1411 #" Set 'thesaurusfunc' to a string(variable with a lambda expression)
1379 LET Lambda = LSTART a, b LMIDDLE MytsrFunc1(20, a, b) LEND 1412 LET Lambda = LSTART a, b LMIDDLE TsrFunc1(20, a, b) LEND
1380 LET &thesaurusfunc = string(Lambda) 1413 LET &thesaurusfunc = string(Lambda)
1381 new | only 1414 new
1382 call setline(1, 'seven') 1415 call setline(1, 'seven')
1383 LET g:MytsrFunc1_args = [] 1416 LET g:TsrFunc1Args = []
1384 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1417 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1385 call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MytsrFunc1_args) 1418 call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:TsrFunc1Args)
1386 bw! 1419 bw!
1387 1420
1388 #" Test for using a lambda function with incorrect return value 1421 #" Test for using a lambda function with incorrect return value
1389 LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND 1422 LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
1390 LET &thesaurusfunc = Lambda 1423 LET &thesaurusfunc = Lambda
1391 new | only 1424 new
1392 call setline(1, 'eight') 1425 call setline(1, 'eight')
1393 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1426 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1394 bw! 1427 bw!
1395 1428
1396 #" Test for clearing the 'thesaurusfunc' option 1429 #" Test for clearing the 'thesaurusfunc' option
1398 set thesaurusfunc& 1431 set thesaurusfunc&
1399 call assert_fails("set thesaurusfunc=function('abc')", "E700:") 1432 call assert_fails("set thesaurusfunc=function('abc')", "E700:")
1400 call assert_fails("set thesaurusfunc=funcref('abc')", "E700:") 1433 call assert_fails("set thesaurusfunc=funcref('abc')", "E700:")
1401 1434
1402 #" set 'thesaurusfunc' to a non-existing function 1435 #" set 'thesaurusfunc' to a non-existing function
1403 func MytsrFunc2(findstart, base) 1436 set thesaurusfunc=TsrFunc2
1404 call add(g:MytsrFunc2_args, [a:findstart, a:base])
1405 return a:findstart ? 0 : ['sunday']
1406 endfunc
1407 set thesaurusfunc=MytsrFunc2
1408 call setline(1, 'ten') 1437 call setline(1, 'ten')
1409 call assert_fails("set thesaurusfunc=function('NonExistingFunc')", 'E700:') 1438 call assert_fails("set thesaurusfunc=function('NonExistingFunc')", 'E700:')
1410 call assert_fails("LET &thesaurusfunc = function('NonExistingFunc')", 'E700:') 1439 call assert_fails("LET &thesaurusfunc = function('NonExistingFunc')", 'E700:')
1411 LET g:MytsrFunc2_args = [] 1440 LET g:TsrFunc2Args = []
1412 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1441 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1413 call assert_equal([[1, ''], [0, 'ten']], g:MytsrFunc2_args) 1442 call assert_equal([[1, ''], [0, 'ten']], g:TsrFunc2Args)
1414 bw! 1443 bw!
1415 1444
1416 #" Use a buffer-local value and a global value 1445 #" Use a buffer-local value and a global value
1417 set thesaurusfunc& 1446 set thesaurusfunc&
1418 setlocal thesaurusfunc=function('g:MytsrFunc1',\ [22]) 1447 setlocal thesaurusfunc=function('g:TsrFunc1',\ [22])
1419 call setline(1, 'sun') 1448 call setline(1, 'sun')
1420 LET g:MytsrFunc1_args = [] 1449 LET g:TsrFunc1Args = []
1421 call feedkeys("A\<C-X>\<C-T>\<Esc>", "x") 1450 call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
1422 call assert_equal('sun', getline(1)) 1451 call assert_equal('sun', getline(1))
1423 call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:MytsrFunc1_args) 1452 call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:TsrFunc1Args)
1424 new 1453 new
1425 call setline(1, 'sun') 1454 call setline(1, 'sun')
1426 LET g:MytsrFunc1_args = [] 1455 LET g:TsrFunc1Args = []
1427 call feedkeys("A\<C-X>\<C-T>\<Esc>", "x") 1456 call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
1428 call assert_equal('sun', getline(1)) 1457 call assert_equal('sun', getline(1))
1429 call assert_equal([], g:MytsrFunc1_args) 1458 call assert_equal([], g:TsrFunc1Args)
1430 set thesaurusfunc=function('g:MytsrFunc1',\ [23]) 1459 set thesaurusfunc=function('g:TsrFunc1',\ [23])
1431 wincmd w 1460 wincmd w
1432 call setline(1, 'sun') 1461 call setline(1, 'sun')
1433 LET g:MytsrFunc1_args = [] 1462 LET g:TsrFunc1Args = []
1434 call feedkeys("A\<C-X>\<C-T>\<Esc>", "x") 1463 call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
1435 call assert_equal('sun', getline(1)) 1464 call assert_equal('sun', getline(1))
1436 call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:MytsrFunc1_args) 1465 call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:TsrFunc1Args)
1437 :%bw! 1466 :%bw!
1438 END 1467 END
1439 call CheckLegacyAndVim9Success(lines) 1468 call CheckLegacyAndVim9Success(lines)
1440 1469
1441 let &thesaurusfunc = {a -> 'abc'} 1470 let &thesaurusfunc = {a -> 'abc'}
1442 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x') 1471 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
1443 1472
1444 " Using Vim9 lambda expression in legacy context should fail 1473 " Using Vim9 lambda expression in legacy context should fail
1445 set thesaurusfunc=(a,\ b)\ =>\ MytsrFunc1(21,\ a,\ b) 1474 set thesaurusfunc=(a,\ b)\ =>\ TsrFunc1(21,\ a,\ b)
1446 new | only 1475 new | only
1447 let g:MytsrFunc1_args = [] 1476 let g:TsrFunc1Args = []
1448 call assert_fails('call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")', 'E117:') 1477 call assert_fails('call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")', 'E117:')
1449 call assert_equal([], g:MytsrFunc1_args) 1478 call assert_equal([], g:TsrFunc1Args)
1450 bw! 1479 bw!
1451 1480
1452 " set 'thesaurusfunc' to a partial with dict. This used to cause a crash. 1481 " set 'thesaurusfunc' to a partial with dict. This used to cause a crash.
1453 func SetTsrFunc() 1482 func SetTsrFunc()
1454 let params = {'thesaurus': function('g:DictTsrFunc')} 1483 let params = {'thesaurus': function('g:DictTsrFunc')}
1500 END 1529 END
1501 call CheckScriptSuccess(lines) 1530 call CheckScriptSuccess(lines)
1502 1531
1503 " cleanup 1532 " cleanup
1504 set thesaurusfunc& 1533 set thesaurusfunc&
1505 delfunc MytsrFunc1 1534 delfunc TsrFunc1
1506 delfunc MytsrFunc2 1535 delfunc TsrFunc2
1536 unlet g:TsrFunc1Args g:TsrFunc2Args
1507 %bw! 1537 %bw!
1508 endfunc 1538 endfunc
1509 1539
1510 " vim: shiftwidth=2 sts=2 expandtab 1540 " vim: shiftwidth=2 sts=2 expandtab