Mercurial > vim
comparison src/testdir/test_gui.vim @ 27462:b43f6c879d52 v8.2.4259
patch 8.2.4259: number of test functions for GUI events is growing
Commit: https://github.com/vim/vim/commit/06011e1a55f32e47fe0af4bd449be6f0e3ff0814
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Sun Jan 30 12:37:29 2022 +0000
patch 8.2.4259: number of test functions for GUI events is growing
Problem: Number of test functions for GUI events is growing.
Solution: Use one function with a dictionary. (Yegappan Lakshmanan,
closes #9660)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 30 Jan 2022 13:45:03 +0100 |
parents | 722db0819111 |
children | f0096e5b3df9 |
comparison
equal
deleted
inserted
replaced
27461:883cfa2dc041 | 27462:b43f6c879d52 |
---|---|
895 new | 895 new |
896 call setline(1, ['one two three', 'four five six']) | 896 call setline(1, ['one two three', 'four five six']) |
897 | 897 |
898 " place the cursor using left click in normal mode | 898 " place the cursor using left click in normal mode |
899 call cursor(1, 1) | 899 call cursor(1, 1) |
900 call test_gui_mouse_event(0, 2, 4, 0, 0) | 900 let args = #{button: 0, row: 2, col: 4, multiclick: 0, modifiers: 0} |
901 call test_gui_mouse_event(3, 2, 4, 0, 0) | 901 call test_gui_event('mouse', args) |
902 let args.button = 3 | |
903 eval 'mouse'->test_gui_event(args) | |
902 call feedkeys("\<Esc>", 'Lx!') | 904 call feedkeys("\<Esc>", 'Lx!') |
903 call assert_equal([0, 2, 4, 0], getpos('.')) | 905 call assert_equal([0, 2, 4, 0], getpos('.')) |
904 | 906 |
905 " select and yank a word | 907 " select and yank a word |
906 let @" = '' | 908 let @" = '' |
907 call test_gui_mouse_event(0, 1, 9, 0, 0) | 909 let args = #{button: 0, row: 1, col: 9, multiclick: 0, modifiers: 0} |
908 call test_gui_mouse_event(0, 1, 9, 1, 0) | 910 call test_gui_event('mouse', args) |
909 call test_gui_mouse_event(3, 1, 9, 0, 0) | 911 let args.multiclick = 1 |
912 call test_gui_event('mouse', args) | |
913 let args.button = 3 | |
914 let args.multiclick = 0 | |
915 call test_gui_event('mouse', args) | |
910 call feedkeys("y", 'Lx!') | 916 call feedkeys("y", 'Lx!') |
911 call assert_equal('three', @") | 917 call assert_equal('three', @") |
912 | 918 |
913 " create visual selection using right click | 919 " create visual selection using right click |
914 let @" = '' | 920 let @" = '' |
915 call test_gui_mouse_event(0, 2, 6, 0, 0) | 921 let args = #{button: 0, row: 2, col: 6, multiclick: 0, modifiers: 0} |
916 call test_gui_mouse_event(3, 2, 6, 0, 0) | 922 call test_gui_event('mouse', args) |
917 call test_gui_mouse_event(2, 2, 13, 0, 0) | 923 let args.button = 3 |
918 call test_gui_mouse_event(3, 2, 13, 0, 0) | 924 call test_gui_event('mouse', args) |
925 let args = #{button: 2, row: 2, col: 13, multiclick: 0, modifiers: 0} | |
926 call test_gui_event('mouse', args) | |
927 let args.button = 3 | |
928 call test_gui_event('mouse', args) | |
919 call feedkeys("y", 'Lx!') | 929 call feedkeys("y", 'Lx!') |
920 call assert_equal('five six', @") | 930 call assert_equal('five six', @") |
921 | 931 |
922 " paste using middle mouse button | 932 " paste using middle mouse button |
923 let @* = 'abc ' | 933 let @* = 'abc ' |
924 call feedkeys('""', 'Lx!') | 934 call feedkeys('""', 'Lx!') |
925 call test_gui_mouse_event(1, 1, 9, 0, 0) | 935 let args = #{button: 1, row: 1, col: 9, multiclick: 0, modifiers: 0} |
926 call test_gui_mouse_event(3, 1, 9, 0, 0) | 936 call test_gui_event('mouse', args) |
937 let args.button = 3 | |
938 call test_gui_event('mouse', args) | |
927 call feedkeys("\<Esc>", 'Lx!') | 939 call feedkeys("\<Esc>", 'Lx!') |
928 call assert_equal(['one two abc three', 'four five six'], getline(1, '$')) | 940 call assert_equal(['one two abc three', 'four five six'], getline(1, '$')) |
929 | 941 |
930 " extend visual selection using right click in visual mode | 942 " extend visual selection using right click in visual mode |
931 let @" = '' | 943 let @" = '' |
932 call cursor(1, 1) | 944 call cursor(1, 1) |
933 call feedkeys('v', 'Lx!') | 945 call feedkeys('v', 'Lx!') |
934 call test_gui_mouse_event(2, 1, 17, 0, 0) | 946 let args = #{button: 2, row: 1, col: 17, multiclick: 0, modifiers: 0} |
935 call test_gui_mouse_event(3, 1, 17, 0, 0) | 947 call test_gui_event('mouse', args) |
948 let args.button = 3 | |
949 call test_gui_event('mouse', args) | |
936 call feedkeys("y", 'Lx!') | 950 call feedkeys("y", 'Lx!') |
937 call assert_equal('one two abc three', @") | 951 call assert_equal('one two abc three', @") |
938 | 952 |
939 " extend visual selection using mouse drag | 953 " extend visual selection using mouse drag |
940 let @" = '' | 954 let @" = '' |
941 call cursor(1, 1) | 955 call cursor(1, 1) |
942 call test_gui_mouse_event(0, 2, 1, 0, 0) | 956 let args = #{button: 0, row: 2, col: 1, multiclick: 0, modifiers: 0} |
943 call test_gui_mouse_event(0x43, 2, 9, 0, 0) | 957 call test_gui_event('mouse', args) |
944 call test_gui_mouse_event(0x3, 2, 9, 0, 0) | 958 let args = #{button: 0x43, row: 2, col: 9, multiclick: 0, modifiers: 0} |
959 call test_gui_event('mouse', args) | |
960 let args.button = 0x3 | |
961 call test_gui_event('mouse', args) | |
945 call feedkeys("y", 'Lx!') | 962 call feedkeys("y", 'Lx!') |
946 call assert_equal('four five', @") | 963 call assert_equal('four five', @") |
947 | 964 |
948 " select text by moving the mouse | 965 " select text by moving the mouse |
949 let @" = '' | 966 let @" = '' |
950 call cursor(1, 1) | 967 call cursor(1, 1) |
951 redraw! | 968 redraw! |
952 call test_gui_mouse_event(0, 1, 4, 0, 0) | 969 let args = #{button: 0, row: 1, col: 4, multiclick: 0, modifiers: 0} |
953 call test_gui_mouse_event(0x700, 1, 9, 0, 0) | 970 call test_gui_event('mouse', args) |
954 call test_gui_mouse_event(0x700, 1, 13, 0, 0) | 971 let args.button = 0x700 |
955 call test_gui_mouse_event(0x3, 1, 13, 0, 0) | 972 let args.col = 9 |
973 call test_gui_event('mouse', args) | |
974 let args.col = 13 | |
975 call test_gui_event('mouse', args) | |
976 let args.button = 3 | |
977 call test_gui_event('mouse', args) | |
956 call feedkeys("y", 'Lx!') | 978 call feedkeys("y", 'Lx!') |
957 call assert_equal(' two abc t', @") | 979 call assert_equal(' two abc t', @") |
958 | 980 |
959 " Using mouse in insert mode | 981 " Using mouse in insert mode |
960 call cursor(1, 1) | 982 call cursor(1, 1) |
961 call feedkeys('i', 't') | 983 call feedkeys('i', 't') |
962 call test_gui_mouse_event(0, 2, 11, 0, 0) | 984 let args = #{button: 0, row: 2, col: 11, multiclick: 0, modifiers: 0} |
963 call test_gui_mouse_event(3, 2, 11, 0, 0) | 985 call test_gui_event('mouse', args) |
986 let args.button = 3 | |
987 call test_gui_event('mouse', args) | |
964 call feedkeys("po\<Esc>", 'Lx!') | 988 call feedkeys("po\<Esc>", 'Lx!') |
965 call assert_equal(['one two abc three', 'four five posix'], getline(1, '$')) | 989 call assert_equal(['one two abc three', 'four five posix'], getline(1, '$')) |
966 | 990 |
967 %d _ | 991 %d _ |
968 call setline(1, range(1, 100)) | 992 call setline(1, range(1, 100)) |
969 " scroll up | 993 " scroll up |
970 call test_gui_mouse_event(0x200, 2, 1, 0, 0) | 994 let args = #{button: 0x200, row: 2, col: 1, multiclick: 0, modifiers: 0} |
971 call test_gui_mouse_event(0x200, 2, 1, 0, 0) | 995 call test_gui_event('mouse', args) |
972 call test_gui_mouse_event(0x200, 2, 1, 0, 0) | 996 call test_gui_event('mouse', args) |
997 call test_gui_event('mouse', args) | |
973 call feedkeys("H", 'Lx!') | 998 call feedkeys("H", 'Lx!') |
974 call assert_equal(10, line('.')) | 999 call assert_equal(10, line('.')) |
975 | 1000 |
976 " scroll down | 1001 " scroll down |
977 call test_gui_mouse_event(0x100, 2, 1, 0, 0) | 1002 let args = #{button: 0x100, row: 2, col: 1, multiclick: 0, modifiers: 0} |
978 call test_gui_mouse_event(0x100, 2, 1, 0, 0) | 1003 call test_gui_event('mouse', args) |
1004 call test_gui_event('mouse', args) | |
979 call feedkeys("H", 'Lx!') | 1005 call feedkeys("H", 'Lx!') |
980 call assert_equal(4, line('.')) | 1006 call assert_equal(4, line('.')) |
981 | 1007 |
982 %d _ | 1008 %d _ |
983 set nowrap | 1009 set nowrap |
984 call setline(1, range(10)->join('')->repeat(10)) | 1010 call setline(1, range(10)->join('')->repeat(10)) |
985 " scroll left | 1011 " scroll left |
986 call test_gui_mouse_event(0x500, 1, 5, 0, 0) | 1012 let args = #{button: 0x500, row: 1, col: 5, multiclick: 0, modifiers: 0} |
987 call test_gui_mouse_event(0x500, 1, 10, 0, 0) | 1013 call test_gui_event('mouse', args) |
988 call test_gui_mouse_event(0x500, 1, 15, 0, 0) | 1014 let args.col = 10 |
1015 call test_gui_event('mouse', args) | |
1016 let args.col = 15 | |
1017 call test_gui_event('mouse', args) | |
989 call feedkeys('g0', 'Lx!') | 1018 call feedkeys('g0', 'Lx!') |
990 call assert_equal(19, col('.')) | 1019 call assert_equal(19, col('.')) |
991 | 1020 |
992 " scroll right | 1021 " scroll right |
993 call test_gui_mouse_event(0x600, 1, 15, 0, 0) | 1022 let args = #{button: 0x600, row: 1, col: 15, multiclick: 0, modifiers: 0} |
994 call test_gui_mouse_event(0x600, 1, 10, 0, 0) | 1023 call test_gui_event('mouse', args) |
1024 let args.col = 10 | |
1025 call test_gui_event('mouse', args) | |
995 call feedkeys('g0', 'Lx!') | 1026 call feedkeys('g0', 'Lx!') |
996 call assert_equal(7, col('.')) | 1027 call assert_equal(7, col('.')) |
997 set wrap& | 1028 set wrap& |
998 | 1029 |
999 %d _ | 1030 %d _ |
1019 | 1050 |
1020 " Test various mouse buttons (0 - Left, 1 - Middle, 2 - Right, 0x300 - X1, | 1051 " Test various mouse buttons (0 - Left, 1 - Middle, 2 - Right, 0x300 - X1, |
1021 " 0x300- X2) | 1052 " 0x300- X2) |
1022 for button in [0, 1, 2, 0x300, 0x400] | 1053 for button in [0, 1, 2, 0x300, 0x400] |
1023 " Single click | 1054 " Single click |
1024 call test_gui_mouse_event(button, 2, 5, 0, 0) | 1055 let args = #{button: button, row: 2, col: 5, multiclick: 0, modifiers: 0} |
1025 call test_gui_mouse_event(3, 2, 5, 0, 0) | 1056 call test_gui_event('mouse', args) |
1057 let args.button = 3 | |
1058 call test_gui_event('mouse', args) | |
1026 | 1059 |
1027 " Double/Triple click is supported by only the Left/Middle/Right mouse | 1060 " Double/Triple click is supported by only the Left/Middle/Right mouse |
1028 " buttons | 1061 " buttons |
1029 if button <= 2 | 1062 if button <= 2 |
1030 " Double Click | 1063 " Double Click |
1031 call test_gui_mouse_event(button, 2, 5, 0, 0) | 1064 let args.button = button |
1032 call test_gui_mouse_event(button, 2, 5, 1, 0) | 1065 call test_gui_event('mouse', args) |
1033 call test_gui_mouse_event(3, 2, 5, 0, 0) | 1066 let args.multiclick = 1 |
1067 call test_gui_event('mouse', args) | |
1068 let args.button = 3 | |
1069 let args.multiclick = 0 | |
1070 call test_gui_event('mouse', args) | |
1034 | 1071 |
1035 " Triple Click | 1072 " Triple Click |
1036 call test_gui_mouse_event(button, 2, 5, 0, 0) | 1073 let args.button = button |
1037 call test_gui_mouse_event(button, 2, 5, 1, 0) | 1074 call test_gui_event('mouse', args) |
1038 call test_gui_mouse_event(button, 2, 5, 1, 0) | 1075 let args.multiclick = 1 |
1039 call test_gui_mouse_event(3, 2, 5, 0, 0) | 1076 call test_gui_event('mouse', args) |
1077 call test_gui_event('mouse', args) | |
1078 let args.button = 3 | |
1079 let args.multiclick = 0 | |
1080 call test_gui_event('mouse', args) | |
1040 endif | 1081 endif |
1041 | 1082 |
1042 " Shift click | 1083 " Shift click |
1043 call test_gui_mouse_event(button, 3, 7, 0, 4) | 1084 let args = #{button: button, row: 3, col: 7, multiclick: 0, modifiers: 4} |
1044 call test_gui_mouse_event(3, 3, 7, 0, 4) | 1085 call test_gui_event('mouse', args) |
1086 let args.button = 3 | |
1087 call test_gui_event('mouse', args) | |
1045 | 1088 |
1046 " Alt click | 1089 " Alt click |
1047 call test_gui_mouse_event(button, 3, 7, 0, 8) | 1090 let args.button = button |
1048 call test_gui_mouse_event(3, 3, 7, 0, 8) | 1091 let args.modifiers = 8 |
1092 call test_gui_event('mouse', args) | |
1093 let args.button = 3 | |
1094 call test_gui_event('mouse', args) | |
1049 | 1095 |
1050 " Ctrl click | 1096 " Ctrl click |
1051 call test_gui_mouse_event(button, 3, 7, 0, 16) | 1097 let args.button = button |
1052 call test_gui_mouse_event(3, 3, 7, 0, 16) | 1098 let args.modifiers = 16 |
1099 call test_gui_event('mouse', args) | |
1100 let args.button = 3 | |
1101 call test_gui_event('mouse', args) | |
1053 | 1102 |
1054 call feedkeys("\<Esc>", 'Lx!') | 1103 call feedkeys("\<Esc>", 'Lx!') |
1055 endfor | 1104 endfor |
1056 | 1105 |
1057 call assert_equal(['LeftMouse', 'LeftRelease', 'LeftMouse', '2-LeftMouse', | 1106 call assert_equal(['LeftMouse', 'LeftRelease', 'LeftMouse', '2-LeftMouse', |
1077 call setline(1, ['one two three', 'four five sixteen']) | 1126 call setline(1, ['one two three', 'four five sixteen']) |
1078 call cursor(1, 1) | 1127 call cursor(1, 1) |
1079 redraw! | 1128 redraw! |
1080 " Double click should select the word and copy it to clipboard | 1129 " Double click should select the word and copy it to clipboard |
1081 let @* = '' | 1130 let @* = '' |
1082 call test_gui_mouse_event(0, 2, 11, 0, 0) | 1131 let args = #{button: 0, row: 2, col: 11, multiclick: 0, modifiers: 0} |
1083 call test_gui_mouse_event(0, 2, 11, 1, 0) | 1132 call test_gui_event('mouse', args) |
1084 call test_gui_mouse_event(3, 2, 11, 0, 0) | 1133 let args.multiclick = 1 |
1134 call test_gui_event('mouse', args) | |
1135 let args.button = 3 | |
1136 let args.multiclick = 0 | |
1137 call test_gui_event('mouse', args) | |
1085 call feedkeys("\<Esc>", 'Lx!') | 1138 call feedkeys("\<Esc>", 'Lx!') |
1086 call assert_equal([0, 1, 1, 0], getpos('.')) | 1139 call assert_equal([0, 1, 1, 0], getpos('.')) |
1087 call assert_equal('sixteen', @*) | 1140 call assert_equal('sixteen', @*) |
1088 " Right click should extend the selection from cursor | 1141 " Right click should extend the selection from cursor |
1089 call cursor(1, 6) | 1142 call cursor(1, 6) |
1090 redraw! | 1143 redraw! |
1091 let @* = '' | 1144 let @* = '' |
1092 call test_gui_mouse_event(2, 1, 11, 0, 0) | 1145 let args = #{button: 2, row: 1, col: 11, multiclick: 0, modifiers: 0} |
1093 call test_gui_mouse_event(3, 1, 11, 0, 0) | 1146 call test_gui_event('mouse', args) |
1147 let args.button = 3 | |
1148 call test_gui_event('mouse', args) | |
1094 call feedkeys("\<Esc>", 'Lx!') | 1149 call feedkeys("\<Esc>", 'Lx!') |
1095 call assert_equal([0, 1, 6, 0], getpos('.')) | 1150 call assert_equal([0, 1, 6, 0], getpos('.')) |
1096 call assert_equal('wo thr', @*) | 1151 call assert_equal('wo thr', @*) |
1097 " Middle click should paste the clipboard contents | 1152 " Middle click should paste the clipboard contents |
1098 call cursor(2, 1) | 1153 call cursor(2, 1) |
1099 redraw! | 1154 redraw! |
1100 call test_gui_mouse_event(1, 1, 11, 0, 0) | 1155 let args = #{button: 1, row: 1, col: 11, multiclick: 0, modifiers: 0} |
1101 call test_gui_mouse_event(3, 1, 11, 0, 0) | 1156 call test_gui_event('mouse', args) |
1157 let args.button = 3 | |
1158 call test_gui_event('mouse', args) | |
1102 call feedkeys("\<Esc>", 'Lx!') | 1159 call feedkeys("\<Esc>", 'Lx!') |
1103 call assert_equal([0, 2, 7, 0], getpos('.')) | 1160 call assert_equal([0, 2, 7, 0], getpos('.')) |
1104 call assert_equal('wo thrfour five sixteen', getline(2)) | 1161 call assert_equal('wo thrfour five sixteen', getline(2)) |
1105 set mouse& | 1162 set mouse& |
1106 let &guioptions = save_guioptions | 1163 let &guioptions = save_guioptions |
1107 | 1164 |
1108 " Test invalid parameters for test_gui_mouse_event() | 1165 " Test invalid parameters for test_gui_event() |
1109 call assert_fails('call test_gui_mouse_event("", 1, 2, 3, 4)', 'E1210:') | 1166 let args = #{row: 2, col: 4, multiclick: 0, modifiers: 0} |
1110 call assert_fails('call test_gui_mouse_event(0, "", 2, 3, 4)', 'E1210:') | 1167 call assert_false(test_gui_event('mouse', args)) |
1111 call assert_fails('call test_gui_mouse_event(0, 1, "", 3, 4)', 'E1210:') | 1168 let args = #{button: 0, col: 4, multiclick: 0, modifiers: 0} |
1112 call assert_fails('call test_gui_mouse_event(0, 1, 2, "", 4)', 'E1210:') | 1169 call assert_false(test_gui_event('mouse', args)) |
1113 call assert_fails('call test_gui_mouse_event(0, 1, 2, 3, "")', 'E1210:') | 1170 let args = #{button: 0, row: 2, multiclick: 0, modifiers: 0} |
1171 call assert_false(test_gui_event('mouse', args)) | |
1172 let args = #{button: 0, row: 2, col: 4, modifiers: 0} | |
1173 call assert_false(test_gui_event('mouse', args)) | |
1174 let args = #{button: 0, row: 2, col: 4, multiclick: 0} | |
1175 call assert_false(test_gui_event('mouse', args)) | |
1176 | |
1177 " Error cases for test_gui_event() | |
1178 call assert_fails("call test_gui_event('a1b2c3', args)", 'E475:') | |
1179 call assert_fails("call test_gui_event([], args)", 'E1174:') | |
1180 call assert_fails("call test_gui_event('abc', [])", 'E1206:') | |
1181 call assert_fails("call test_gui_event(test_null_string(), {})", 'E475:') | |
1182 call assert_false(test_gui_event('mouse', test_null_dict())) | |
1114 | 1183 |
1115 bw! | 1184 bw! |
1116 call test_override('no_query_mouse', 0) | 1185 call test_override('no_query_mouse', 0) |
1117 set mousemodel& | 1186 set mousemodel& |
1118 endfunc | 1187 endfunc |
1176 " Test for dropping files into a window in GUI | 1245 " Test for dropping files into a window in GUI |
1177 func DropFilesInCmdLine() | 1246 func DropFilesInCmdLine() |
1178 CheckFeature drop_file | 1247 CheckFeature drop_file |
1179 | 1248 |
1180 call feedkeys(":\"", 'L') | 1249 call feedkeys(":\"", 'L') |
1181 call test_gui_drop_files(['a.c', 'b.c'], &lines, 1, 0) | 1250 let d = #{files: ['a.c', 'b.c'], row: &lines, col: 1, modifiers: 0} |
1251 call test_gui_event('dropfiles', d) | |
1182 call feedkeys("\<CR>", 'L') | 1252 call feedkeys("\<CR>", 'L') |
1183 endfunc | 1253 endfunc |
1184 | 1254 |
1185 func Test_gui_drop_files() | 1255 func Test_gui_drop_files() |
1186 CheckFeature drop_file | 1256 CheckFeature drop_file |
1187 | 1257 |
1188 call assert_fails('call test_gui_drop_files(1, 1, 1, 0)', 'E1211:') | 1258 call assert_false(test_gui_event("dropfiles", {})) |
1189 call assert_fails('call test_gui_drop_files(["x"], "", 1, 0)', 'E1210:') | 1259 let d = #{row: 1, col: 1, modifiers: 0} |
1190 call assert_fails('call test_gui_drop_files(["x"], 1, "", 0)', 'E1210:') | 1260 call assert_false(test_gui_event("dropfiles", d)) |
1191 call assert_fails('call test_gui_drop_files(["x"], 1, 1, "")', 'E1210:') | |
1192 | 1261 |
1193 %bw! | 1262 %bw! |
1194 %argdelete | 1263 %argdelete |
1195 call test_gui_drop_files([], 1, 1, 0) | 1264 let d = #{files: [], row: 1, col: 1, modifiers: 0} |
1265 call test_gui_event('dropfiles', d) | |
1196 call assert_equal([], argv()) | 1266 call assert_equal([], argv()) |
1197 call test_gui_drop_files([1, 2], 1, 1, 0) | 1267 let d = #{files: [1, 2], row: 1, col: 1, modifiers: 0} |
1268 call test_gui_event('dropfiles', d) | |
1198 call assert_equal([], argv()) | 1269 call assert_equal([], argv()) |
1199 | 1270 |
1200 call test_gui_drop_files(['a.c', 'b.c'], 1, 1, 0) | 1271 let d = #{files: ['a.c', 'b.c'], row: 1, col: 1, modifiers: 0} |
1272 call test_gui_event('dropfiles', d) | |
1201 call assert_equal(['a.c', 'b.c'], argv()) | 1273 call assert_equal(['a.c', 'b.c'], argv()) |
1202 %bw! | 1274 %bw! |
1203 %argdelete | 1275 %argdelete |
1204 call test_gui_drop_files([], 1, 1, 0) | 1276 let d = #{files: [], row: 1, col: 1, modifiers: 0} |
1277 call test_gui_event('dropfiles', d) | |
1205 call assert_equal([], argv()) | 1278 call assert_equal([], argv()) |
1206 %bw! | 1279 %bw! |
1207 " if the buffer in the window is modified, then the file should be opened in | 1280 " if the buffer in the window is modified, then the file should be opened in |
1208 " a new window | 1281 " a new window |
1209 set modified | 1282 set modified |
1210 call test_gui_drop_files(['x.c', 'y.c'], 1, 1, 0) | 1283 let d = #{files: ['x.c', 'y.c'], row: 1, col: 1, modifiers: 0} |
1284 call test_gui_event('dropfiles', d) | |
1211 call assert_equal(['x.c', 'y.c'], argv()) | 1285 call assert_equal(['x.c', 'y.c'], argv()) |
1212 call assert_equal(2, winnr('$')) | 1286 call assert_equal(2, winnr('$')) |
1213 call assert_equal('x.c', bufname(winbufnr(1))) | 1287 call assert_equal('x.c', bufname(winbufnr(1))) |
1214 %bw! | 1288 %bw! |
1215 %argdelete | 1289 %argdelete |
1216 " if Ctrl is pressed, then the file should be opened in a new window | 1290 " if Ctrl is pressed, then the file should be opened in a new window |
1217 call test_gui_drop_files(['s.py', 't.py'], 1, 1, 0x10) | 1291 let d = #{files: ['s.py', 't.py'], row: 1, col: 1, modifiers: 0x10} |
1292 eval 'dropfiles'->test_gui_event(d) | |
1218 call assert_equal(['s.py', 't.py'], argv()) | 1293 call assert_equal(['s.py', 't.py'], argv()) |
1219 call assert_equal(2, winnr('$')) | 1294 call assert_equal(2, winnr('$')) |
1220 call assert_equal('s.py', bufname(winbufnr(1))) | 1295 call assert_equal('s.py', bufname(winbufnr(1))) |
1221 %bw! | 1296 %bw! |
1222 %argdelete | 1297 %argdelete |
1223 " drop the files in a non-current window | 1298 " drop the files in a non-current window |
1224 belowright new | 1299 belowright new |
1225 call test_gui_drop_files(['a.py', 'b.py'], 1, 1, 0) | 1300 let d = #{files: ['a.py', 'b.py'], row: 1, col: 1, modifiers: 0} |
1301 call test_gui_event('dropfiles', d) | |
1226 call assert_equal(['a.py', 'b.py'], argv()) | 1302 call assert_equal(['a.py', 'b.py'], argv()) |
1227 call assert_equal(2, winnr('$')) | 1303 call assert_equal(2, winnr('$')) |
1228 call assert_equal(1, winnr()) | 1304 call assert_equal(1, winnr()) |
1229 call assert_equal('a.py', bufname(winbufnr(1))) | 1305 call assert_equal('a.py', bufname(winbufnr(1))) |
1230 %bw! | 1306 %bw! |
1232 " pressing shift when dropping files should change directory | 1308 " pressing shift when dropping files should change directory |
1233 let save_cwd = getcwd() | 1309 let save_cwd = getcwd() |
1234 call mkdir('Xdir1') | 1310 call mkdir('Xdir1') |
1235 call writefile([], 'Xdir1/Xfile1') | 1311 call writefile([], 'Xdir1/Xfile1') |
1236 call writefile([], 'Xdir1/Xfile2') | 1312 call writefile([], 'Xdir1/Xfile2') |
1237 call test_gui_drop_files(['Xdir1/Xfile1', 'Xdir1/Xfile2'], 1, 1, 0x4) | 1313 let d = #{files: ['Xdir1/Xfile1', 'Xdir1/Xfile2'], row: 1, col: 1, |
1314 \ modifiers: 0x4} | |
1315 call test_gui_event('dropfiles', d) | |
1238 call assert_equal('Xdir1', fnamemodify(getcwd(), ':t')) | 1316 call assert_equal('Xdir1', fnamemodify(getcwd(), ':t')) |
1239 call assert_equal('Xfile1', @%) | 1317 call assert_equal('Xfile1', @%) |
1240 call chdir(save_cwd) | 1318 call chdir(save_cwd) |
1241 " pressing shift when dropping directory and files should change directory | 1319 " pressing shift when dropping directory and files should change directory |
1242 call test_gui_drop_files(['Xdir1', 'Xdir1/Xfile2'], 1, 1, 0x4) | 1320 let d = #{files: ['Xdir1', 'Xdir1/Xfile2'], row: 1, col: 1, modifiers: 0x4} |
1321 call test_gui_event('dropfiles', d) | |
1243 call assert_equal('Xdir1', fnamemodify(getcwd(), ':t')) | 1322 call assert_equal('Xdir1', fnamemodify(getcwd(), ':t')) |
1244 call assert_equal('Xdir1', fnamemodify(@%, ':t')) | 1323 call assert_equal('Xdir1', fnamemodify(@%, ':t')) |
1245 call chdir(save_cwd) | 1324 call chdir(save_cwd) |
1246 %bw! | 1325 %bw! |
1247 %argdelete | 1326 %argdelete |
1248 " dropping a directory should edit it | 1327 " dropping a directory should edit it |
1249 call test_gui_drop_files(['Xdir1'], 1, 1, 0) | 1328 let d = #{files: ['Xdir1'], row: 1, col: 1, modifiers: 0} |
1329 call test_gui_event('dropfiles', d) | |
1250 call assert_equal('Xdir1', @%) | 1330 call assert_equal('Xdir1', @%) |
1251 %bw! | 1331 %bw! |
1252 %argdelete | 1332 %argdelete |
1253 " dropping only a directory name with Shift should ignore it | 1333 " dropping only a directory name with Shift should ignore it |
1254 call test_gui_drop_files(['Xdir1'], 1, 1, 0x4) | 1334 let d = #{files: ['Xdir1'], row: 1, col: 1, modifiers: 0x4} |
1335 call test_gui_event('dropfiles', d) | |
1255 call assert_equal('', @%) | 1336 call assert_equal('', @%) |
1256 %bw! | 1337 %bw! |
1257 %argdelete | 1338 %argdelete |
1258 call delete('Xdir1', 'rf') | 1339 call delete('Xdir1', 'rf') |
1259 " drop files in the command line. The GUI drop files adds the file names to | 1340 " drop files in the command line. The GUI drop files adds the file names to |
1272 edit Xfile1 | 1353 edit Xfile1 |
1273 tabedit Xfile2 | 1354 tabedit Xfile2 |
1274 tabedit Xfile3 | 1355 tabedit Xfile3 |
1275 | 1356 |
1276 tabfirst | 1357 tabfirst |
1277 call assert_equal(v:true, test_gui_tabline_event(2)) | 1358 call assert_equal(v:true, test_gui_event('tabline', #{tabnr: 2})) |
1278 call feedkeys("y", "Lx!") | 1359 call feedkeys("y", "Lx!") |
1279 call assert_equal(2, tabpagenr()) | 1360 call assert_equal(2, tabpagenr()) |
1280 call assert_equal(v:true, test_gui_tabline_event(3)) | 1361 call assert_equal(v:true, test_gui_event('tabline', #{tabnr: 3})) |
1281 call feedkeys("y", "Lx!") | 1362 call feedkeys("y", "Lx!") |
1282 call assert_equal(3, tabpagenr()) | 1363 call assert_equal(3, tabpagenr()) |
1283 call assert_equal(v:false, test_gui_tabline_event(3)) | 1364 call assert_equal(v:false, 'tabline'->test_gui_event(#{tabnr: 3})) |
1284 | 1365 |
1285 " From the cmdline window, tabline event should not be handled | 1366 " From the cmdline window, tabline event should not be handled |
1286 call feedkeys("q::let t = test_gui_tabline_event(2)\<CR>:q\<CR>", 'x!') | 1367 call feedkeys("q::let t = test_gui_event('tabline', #{tabnr: 2})\<CR>:q\<CR>", 'x!') |
1287 call assert_equal(v:false, t) | 1368 call assert_equal(v:false, t) |
1288 | 1369 |
1289 %bw! | 1370 %bw! |
1290 endfunc | 1371 endfunc |
1291 | 1372 |
1292 " Test for generating a GUI tabline menu event to execute an action | 1373 " Test for generating a GUI tabline menu event to execute an action |
1293 func Test_gui_tabmenu_event() | 1374 func Test_gui_tabmenu_event() |
1294 %bw! | 1375 %bw! |
1295 | 1376 |
1296 " Try to close the last tab page | 1377 " Try to close the last tab page |
1297 call test_gui_tabmenu_event(1, 1) | 1378 call test_gui_event('tabmenu', #{tabnr: 1, item: 1}) |
1298 call feedkeys("y", "Lx!") | 1379 call feedkeys("y", "Lx!") |
1299 | 1380 |
1300 edit Xfile1 | 1381 edit Xfile1 |
1301 tabedit Xfile2 | 1382 tabedit Xfile2 |
1302 call test_gui_tabmenu_event(1, 1) | 1383 call test_gui_event('tabmenu', #{tabnr: 1, item: 1}) |
1303 call feedkeys("y", "Lx!") | 1384 call feedkeys("y", "Lx!") |
1304 call assert_equal(1, tabpagenr('$')) | 1385 call assert_equal(1, tabpagenr('$')) |
1305 call assert_equal('Xfile2', bufname()) | 1386 call assert_equal('Xfile2', bufname()) |
1306 | 1387 |
1307 call test_gui_tabmenu_event(1, 2) | 1388 eval 'tabmenu'->test_gui_event(#{tabnr: 1, item: 2}) |
1308 call feedkeys("y", "Lx!") | 1389 call feedkeys("y", "Lx!") |
1309 call assert_equal(2, tabpagenr('$')) | 1390 call assert_equal(2, tabpagenr('$')) |
1310 | 1391 |
1311 " If tabnr is 0, then the current tabpage should be used. | 1392 " If tabnr is 0, then the current tabpage should be used. |
1312 call test_gui_tabmenu_event(0, 2) | 1393 call test_gui_event('tabmenu', #{tabnr: 0, item: 2}) |
1313 call feedkeys("y", "Lx!") | 1394 call feedkeys("y", "Lx!") |
1314 call assert_equal(3, tabpagenr('$')) | 1395 call assert_equal(3, tabpagenr('$')) |
1315 call test_gui_tabmenu_event(0, 1) | 1396 call test_gui_event('tabmenu', #{tabnr: 0, item: 1}) |
1316 call feedkeys("y", "Lx!") | 1397 call feedkeys("y", "Lx!") |
1317 call assert_equal(2, tabpagenr('$')) | 1398 call assert_equal(2, tabpagenr('$')) |
1318 | 1399 |
1319 %bw! | 1400 %bw! |
1320 endfunc | 1401 endfunc |