h-east | 84ac212 | 2024-06-17 18:12:30 +0200 | [diff] [blame] | 1 | *testing.txt* For Vim version 9.1. Last change: 2024 Jun 17 |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 2 | |
| 3 | |
| 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
| 5 | |
| 6 | |
| 7 | Testing Vim and Vim script *testing-support* |
| 8 | |
| 9 | Expression evaluation is explained in |eval.txt|. This file goes into details |
| 10 | about writing tests in Vim script. This can be used for testing Vim itself |
| 11 | and for testing plugins. |
| 12 | |
| 13 | 1. Testing Vim |testing| |
Bram Moolenaar | 5477506 | 2019-07-31 21:07:14 +0200 | [diff] [blame] | 14 | 2. Test functions |test-functions-details| |
| 15 | 3. Assert functions |assert-functions-details| |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 16 | |
| 17 | ============================================================================== |
| 18 | 1. Testing Vim *testing* |
| 19 | |
| 20 | Vim can be tested after building it, usually with "make test". |
| 21 | The tests are located in the directory "src/testdir". |
| 22 | |
Bram Moolenaar | b96a32e | 2020-08-13 18:59:55 +0200 | [diff] [blame] | 23 | There are two types of tests added over time: |
RestorerZ | ac9c6d5 | 2023-10-05 22:25:12 +0200 | [diff] [blame] | 24 | test20.in oldest, only for tiny builds |
Bram Moolenaar | b96a32e | 2020-08-13 18:59:55 +0200 | [diff] [blame] | 25 | test_something.vim new style tests |
| 26 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 27 | *new-style-testing* |
Bram Moolenaar | f7c4d83 | 2020-08-11 20:42:19 +0200 | [diff] [blame] | 28 | New tests should be added as new style tests. The test scripts are named |
| 29 | test_<feature>.vim (replace <feature> with the feature under test). These use |
| 30 | functions such as |assert_equal()| to keep the test commands and the expected |
| 31 | result in one place. |
Bram Moolenaar | b96a32e | 2020-08-13 18:59:55 +0200 | [diff] [blame] | 32 | *old-style-testing* |
| 33 | These tests are used only for testing Vim without the |+eval| feature. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 34 | |
| 35 | Find more information in the file src/testdir/README.txt. |
| 36 | |
| 37 | ============================================================================== |
Bram Moolenaar | 5477506 | 2019-07-31 21:07:14 +0200 | [diff] [blame] | 38 | 2. Test functions *test-functions-details* |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 39 | |
| 40 | test_alloc_fail({id}, {countdown}, {repeat}) *test_alloc_fail()* |
| 41 | This is for testing: If the memory allocation with {id} is |
| 42 | called, then decrement {countdown}, and when it reaches zero |
| 43 | let memory allocation fail {repeat} times. When {repeat} is |
| 44 | smaller than one it fails one time. |
| 45 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 46 | Can also be used as a |method|: > |
| 47 | GetAllocId()->test_alloc_fail() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 48 | < |
| 49 | Return type: |Number| |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 50 | |
Bram Moolenaar | 89a9c15 | 2021-08-29 21:55:35 +0200 | [diff] [blame] | 51 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 52 | test_autochdir() *test_autochdir()* |
| 53 | Set a flag to enable the effect of 'autochdir' before Vim |
| 54 | startup has finished. |
| 55 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 56 | Return type: |Number| |
| 57 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 58 | |
| 59 | test_feedinput({string}) *test_feedinput()* |
| 60 | Characters in {string} are queued for processing as if they |
| 61 | were typed by the user. This uses a low level input buffer. |
| 62 | This function works only when with |+unix| or GUI is running. |
| 63 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 64 | Can also be used as a |method|: > |
| 65 | GetText()->test_feedinput() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 66 | < |
| 67 | Return type: |Number| |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 68 | |
Bram Moolenaar | 89a9c15 | 2021-08-29 21:55:35 +0200 | [diff] [blame] | 69 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 70 | test_garbagecollect_now() *test_garbagecollect_now()* |
| 71 | Like garbagecollect(), but executed right away. This must |
| 72 | only be called directly to avoid any structure to exist |
| 73 | internally, and |v:testing| must have been set before calling |
Bram Moolenaar | a2baa73 | 2022-02-04 16:09:54 +0000 | [diff] [blame] | 74 | any function. *E1142* |
| 75 | This will not work when called from a :def function, because |
| 76 | variables on the stack will be freed. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 77 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 78 | Return type: |Number| |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 79 | |
| 80 | test_garbagecollect_soon() *test_garbagecollect_soon()* |
| 81 | Set the flag to call the garbagecollector as if in the main |
| 82 | loop. Only to be used in tests. |
| 83 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 84 | Return type: |Number| |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 85 | |
| 86 | test_getvalue({name}) *test_getvalue()* |
| 87 | Get the value of an internal variable. These values for |
| 88 | {name} are supported: |
| 89 | need_fileinfo |
| 90 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 91 | Can also be used as a |method|: > |
| 92 | GetName()->test_getvalue() |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 93 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 94 | Return type: |Number| |
| 95 | |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 96 | *test_gui_event()* |
| 97 | test_gui_event({event}, {args}) |
| 98 | Generate a GUI {event} with arguments {args} for testing Vim |
Yegappan Lakshmanan | ec3637c | 2022-01-30 18:01:24 +0000 | [diff] [blame] | 99 | functionality. This function works only when the GUI is |
| 100 | running. |
Bram Moolenaar | 2286304 | 2021-10-16 15:23:36 +0100 | [diff] [blame] | 101 | |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 102 | {event} is a String and the supported values are: |
| 103 | "dropfiles" drop one or more files in a window. |
Bram Moolenaar | 8a3b805 | 2022-06-26 12:21:15 +0100 | [diff] [blame] | 104 | "findrepl" search and replace text. |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 105 | "mouse" mouse button click event. |
Bram Moolenaar | 8a3b805 | 2022-06-26 12:21:15 +0100 | [diff] [blame] | 106 | "scrollbar" move or drag the scrollbar. |
Christopher Plewright | 20b795e | 2022-12-20 20:01:58 +0000 | [diff] [blame] | 107 | "key" send a low-level keyboard event. |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 108 | "tabline" select a tab page by mouse click. |
| 109 | "tabmenu" select a tabline menu entry. |
Yegappan Lakshmanan | 18d4658 | 2021-06-23 20:46:52 +0200 | [diff] [blame] | 110 | |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 111 | {args} is a Dict and contains the arguments for the event. |
| 112 | |
| 113 | "dropfiles": |
| 114 | Drop one or more files in a specified window. The supported |
| 115 | items in {args} are: |
| 116 | files: List of file names |
| 117 | row: window row number |
| 118 | col: window column number |
| 119 | modifiers: key modifiers. The supported values are: |
| 120 | 0x4 Shift |
| 121 | 0x8 Alt |
| 122 | 0x10 Ctrl |
| 123 | The files are added to the |argument-list| and the first |
| 124 | file in {files} is edited in the window. See |drag-n-drop| |
Yegappan Lakshmanan | ec3637c | 2022-01-30 18:01:24 +0000 | [diff] [blame] | 125 | for more information. This event works only when the |
| 126 | |drop_file| feature is present. |
| 127 | |
| 128 | "findrepl": |
Bram Moolenaar | a2baa73 | 2022-02-04 16:09:54 +0000 | [diff] [blame] | 129 | {only available when the GUI has a find/replace dialog} |
Yegappan Lakshmanan | ec3637c | 2022-01-30 18:01:24 +0000 | [diff] [blame] | 130 | Perform a search and replace of text. The supported items |
| 131 | in {args} are: |
| 132 | find_text: string to find. |
Bram Moolenaar | 8a3b805 | 2022-06-26 12:21:15 +0100 | [diff] [blame] | 133 | repl_text: replacement string. |
Yegappan Lakshmanan | ec3637c | 2022-01-30 18:01:24 +0000 | [diff] [blame] | 134 | flags: flags controlling the find/replace. Supported |
| 135 | values are: |
| 136 | 1 search next string (find dialog) |
| 137 | 2 search next string (replace dialog) |
| 138 | 3 replace string once |
| 139 | 4 replace all matches |
| 140 | 8 match whole words only |
| 141 | 16 match case |
| 142 | forward: set to 1 for forward search. |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 143 | |
| 144 | "mouse": |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 145 | Inject either a mouse button click, or a mouse move, event. |
| 146 | The supported items in {args} are: |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 147 | button: mouse button. The supported values are: |
Bram Moolenaar | 86b4816 | 2022-12-06 18:20:10 +0000 | [diff] [blame] | 148 | 0 left mouse button |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 149 | 1 middle mouse button |
Bram Moolenaar | 86b4816 | 2022-12-06 18:20:10 +0000 | [diff] [blame] | 150 | 2 right mouse button |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 151 | 3 mouse button release |
| 152 | 4 scroll wheel down |
| 153 | 5 scroll wheel up |
| 154 | 6 scroll wheel left |
| 155 | 7 scroll wheel right |
| 156 | row: mouse click row number. The first row of the |
| 157 | Vim window is 1 and the last row is 'lines'. |
| 158 | col: mouse click column number. The maximum value |
| 159 | of {col} is 'columns'. |
| 160 | multiclick: set to 1 to inject a multiclick mouse event. |
| 161 | modifiers: key modifiers. The supported values are: |
| 162 | 4 shift is pressed |
| 163 | 8 alt is pressed |
| 164 | 16 ctrl is pressed |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 165 | move: Optional; if used and TRUE then a mouse move |
| 166 | event can be generated. |
| 167 | Only {args} row: and col: are used and |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 168 | required; they are interpreted as pixels or |
| 169 | screen cells, depending on "cell". |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 170 | Only results in an event when 'mousemoveevent' |
| 171 | is set or a popup uses mouse move events. |
Bram Moolenaar | 7add8d3 | 2022-05-16 15:27:46 +0100 | [diff] [blame] | 172 | cell: Optional: when present and TRUE then "move" |
| 173 | uses screen cells instead of pixel positions |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 174 | |
| 175 | "scrollbar": |
| 176 | Set or drag the left, right or horizontal scrollbar. Only |
| 177 | works when the scrollbar actually exists. The supported |
| 178 | items in {args} are: |
Bram Moolenaar | 10e8ff9 | 2023-06-10 21:40:39 +0100 | [diff] [blame] | 179 | which: Selects the scrollbar. The supported values |
| 180 | are: |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 181 | left Left scrollbar of the current window |
| 182 | right Right scrollbar of the current window |
| 183 | hor Horizontal scrollbar |
Bram Moolenaar | 10e8ff9 | 2023-06-10 21:40:39 +0100 | [diff] [blame] | 184 | value: Amount to scroll. For the vertical scrollbars |
| 185 | the value can be between 0 to the line-count |
| 186 | of the buffer minus one. For the horizontal |
| 187 | scrollbar the value can be between 1 and the |
| 188 | maximum line length, assuming 'wrap' is not |
| 189 | set. |
Ernie Rael | c4cb544 | 2022-04-03 15:47:28 +0100 | [diff] [blame] | 190 | dragging: 1 to drag the scrollbar and 0 to click in the |
| 191 | scrollbar. |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 192 | |
Christopher Plewright | 20b795e | 2022-12-20 20:01:58 +0000 | [diff] [blame] | 193 | "key": |
| 194 | Send a low-level keyboard event (e.g. key-up or down). |
Yegappan Lakshmanan | 81a3ff9 | 2022-07-23 05:04:16 +0100 | [diff] [blame] | 195 | Currently only supported on MS-Windows. |
| 196 | The supported items in {args} are: |
| 197 | event: The supported string values are: |
| 198 | keyup generate a keyup event |
| 199 | keydown generate a keydown event |
| 200 | keycode: Keycode to use for a keyup or a keydown event. |
Bram Moolenaar | 2ecbe53 | 2022-07-29 21:36:21 +0100 | [diff] [blame] | 201 | *E1291* |
Yegappan Lakshmanan | 81a3ff9 | 2022-07-23 05:04:16 +0100 | [diff] [blame] | 202 | |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 203 | "tabline": |
| 204 | Inject a mouse click event on the tabline to select a |
| 205 | tabpage. The supported items in {args} are: |
| 206 | tabnr: tab page number |
| 207 | |
| 208 | "tabmenu": |
| 209 | Inject an event to select a tabline menu entry. The |
| 210 | supported items in {args} are: |
| 211 | tabnr: tab page number |
Bram Moolenaar | 938ae28 | 2023-02-20 20:44:55 +0000 | [diff] [blame] | 212 | item: tab page menu item number. 1 for the first |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 213 | menu item, 2 for the second item and so on. |
| 214 | |
| 215 | After injecting the GUI events you probably should call |
Yegappan Lakshmanan | f1e7449 | 2021-06-21 18:44:26 +0200 | [diff] [blame] | 216 | |feedkeys()| to have them processed, e.g.: > |
| 217 | call feedkeys("y", 'Lx!') |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 218 | < |
Yegappan Lakshmanan | b0ad2d9 | 2022-01-27 13:16:59 +0000 | [diff] [blame] | 219 | Returns TRUE if the event is successfully added, FALSE if |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 220 | there is a failure. |
Yegappan Lakshmanan | b0ad2d9 | 2022-01-27 13:16:59 +0000 | [diff] [blame] | 221 | |
Yegappan Lakshmanan | 06011e1 | 2022-01-30 12:37:29 +0000 | [diff] [blame] | 222 | Can also be used as a |method|: > |
| 223 | GetEvent()->test_gui_event({args}) |
| 224 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 225 | Return type: |vim9-boolean| |
| 226 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 227 | test_ignore_error({expr}) *test_ignore_error()* |
| 228 | Ignore any error containing {expr}. A normal message is given |
| 229 | instead. |
| 230 | This is only meant to be used in tests, where catching the |
| 231 | error with try/catch cannot be used (because it skips over |
| 232 | following code). |
| 233 | {expr} is used literally, not as a pattern. |
| 234 | When the {expr} is the string "RESET" then the list of ignored |
| 235 | errors is made empty. |
| 236 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 237 | Can also be used as a |method|: > |
| 238 | GetErrorText()->test_ignore_error() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 239 | < |
| 240 | Return type: |Number| |
Bram Moolenaar | be4e016 | 2023-02-02 13:59:48 +0000 | [diff] [blame] | 241 | |
Christopher Plewright | 20b795e | 2022-12-20 20:01:58 +0000 | [diff] [blame] | 242 | test_mswin_event({event}, {args}) *test_mswin_event()* |
| 243 | Generate a low-level MS-Windows {event} with arguments {args} |
Bram Moolenaar | be4e016 | 2023-02-02 13:59:48 +0000 | [diff] [blame] | 244 | for testing Vim functionality. It works for MS-Windows GUI |
Christopher Plewright | 20b795e | 2022-12-20 20:01:58 +0000 | [diff] [blame] | 245 | and for the console. |
Bram Moolenaar | be4e016 | 2023-02-02 13:59:48 +0000 | [diff] [blame] | 246 | |
Christopher Plewright | 20b795e | 2022-12-20 20:01:58 +0000 | [diff] [blame] | 247 | {event} is a String and the supported values are: |
| 248 | "mouse" mouse event. |
| 249 | "key" keyboard event. |
Anton Sharonov | 68d9472 | 2024-01-23 23:19:02 +0100 | [diff] [blame] | 250 | "set_keycode_trans_strategy" |
h_east | 026b174 | 2024-02-19 02:51:46 +0900 | [diff] [blame] | 251 | Change the key translation method. |
Christopher Plewright | 20b795e | 2022-12-20 20:01:58 +0000 | [diff] [blame] | 252 | |
| 253 | "mouse": |
| 254 | Inject either a mouse button click, or a mouse move, event. |
| 255 | The supported items in {args} are: |
| 256 | button: mouse button. The supported values are: |
| 257 | 0 right mouse button |
| 258 | 1 middle mouse button |
| 259 | 2 left mouse button |
| 260 | 3 mouse button release |
| 261 | 4 scroll wheel down |
| 262 | 5 scroll wheel up |
| 263 | 6 scroll wheel left |
| 264 | 7 scroll wheel right |
| 265 | row: mouse click row number. The first row of the |
| 266 | Vim window is 1 and the last row is 'lines'. |
| 267 | col: mouse click column number. The maximum value |
| 268 | of {col} is 'columns'. |
| 269 | Note: row and col are always interpreted as |
| 270 | screen cells for the console application. |
| 271 | But, they may be interpreted as pixels |
| 272 | for the GUI, depending on "cell". |
| 273 | multiclick: set to 1 to inject a double-click mouse event. |
| 274 | modifiers: key modifiers. The supported values are: |
| 275 | 4 shift is pressed |
| 276 | 8 alt is pressed |
| 277 | 16 ctrl is pressed |
| 278 | move: Optional; if used and TRUE then a mouse move |
| 279 | event can be generated. |
| 280 | Only {args} row: and col: are used and |
| 281 | required. |
| 282 | Only results in an event when 'mousemoveevent' |
| 283 | is set or a popup uses mouse move events. |
| 284 | cell: Optional for the GUI: when present and TRUE |
| 285 | then "move" uses screen cells instead of pixel |
| 286 | positions. Not used by the console. |
| 287 | |
| 288 | "key": |
| 289 | Send a low-level keyboard event (e.g. keyup or keydown). |
| 290 | The supported items in {args} are: |
| 291 | event: The supported string values are: |
| 292 | keyup generate a keyup event |
| 293 | keydown generate a keydown event |
Christopher Plewright | 7b0afc1 | 2022-12-30 16:54:58 +0000 | [diff] [blame] | 294 | keycode: Keycode to use for a keyup or a keydown event. |
Christopher Plewright | 20b795e | 2022-12-20 20:01:58 +0000 | [diff] [blame] | 295 | modifiers: Optional; key modifiers. |
| 296 | The supported values are: |
| 297 | 2 shift is pressed |
| 298 | 4 ctrl is pressed |
| 299 | 8 alt is pressed |
| 300 | Note: These values are different from the |
| 301 | mouse modifiers. |
Christopher Plewright | 7b0afc1 | 2022-12-30 16:54:58 +0000 | [diff] [blame] | 302 | execute: Optional. Similar to |feedkeys()| mode x. |
| 303 | When this is included and set to true |
| 304 | (non-zero) then Vim will process any buffered |
| 305 | unprocessed key events. All other {args} |
| 306 | items are optional when this is set and true. |
| 307 | |
Anton Sharonov | 68d9472 | 2024-01-23 23:19:02 +0100 | [diff] [blame] | 308 | "set_keycode_trans_strategy": |
| 309 | |w32-experimental-keycode-trans-strategy| |
h_east | 026b174 | 2024-02-19 02:51:46 +0900 | [diff] [blame] | 310 | Switch the keycode translation method. The supported methods |
| 311 | are: |
Anton Sharonov | 68d9472 | 2024-01-23 23:19:02 +0100 | [diff] [blame] | 312 | experimental: The method used after Patch v8.2.4807 |
| 313 | using ToUnicode() Win API call. |
| 314 | classic: The method used pre Patch v8.2.4807 |
| 315 | using the TranslateMessage() Win API call. |
| 316 | |
Christopher Plewright | 7b0afc1 | 2022-12-30 16:54:58 +0000 | [diff] [blame] | 317 | Returns TRUE if the event is successfully added or executed, |
| 318 | FALSE if there is a failure. |
Christopher Plewright | 20b795e | 2022-12-20 20:01:58 +0000 | [diff] [blame] | 319 | |
| 320 | Can also be used as a |method|: > |
| 321 | GetEvent()->test_mswin_event({args}) |
| 322 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 323 | Return type: |vim9-boolean| |
Bram Moolenaar | 89a9c15 | 2021-08-29 21:55:35 +0200 | [diff] [blame] | 324 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 325 | test_null_blob() *test_null_blob()* |
| 326 | Return a |Blob| that is null. Only useful for testing. |
| 327 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 328 | Return type: |Blob| |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 329 | |
| 330 | test_null_channel() *test_null_channel()* |
| 331 | Return a |Channel| that is null. Only useful for testing. |
| 332 | {only available when compiled with the +channel feature} |
| 333 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 334 | Return type: |Channel| |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 335 | |
| 336 | test_null_dict() *test_null_dict()* |
| 337 | Return a |Dict| that is null. Only useful for testing. |
| 338 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 339 | Return type: dict<any> |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 340 | |
Bram Moolenaar | e69f6d0 | 2020-04-01 22:11:01 +0200 | [diff] [blame] | 341 | test_null_function() *test_null_function()* |
Bram Moolenaar | d1caa94 | 2020-04-10 22:10:56 +0200 | [diff] [blame] | 342 | Return a |Funcref| that is null. Only useful for testing. |
Bram Moolenaar | e69f6d0 | 2020-04-01 22:11:01 +0200 | [diff] [blame] | 343 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 344 | Return type: func(...): unknown |
Bram Moolenaar | e69f6d0 | 2020-04-01 22:11:01 +0200 | [diff] [blame] | 345 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 346 | test_null_job() *test_null_job()* |
| 347 | Return a |Job| that is null. Only useful for testing. |
| 348 | {only available when compiled with the +job feature} |
| 349 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 350 | Return type: |job| |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 351 | |
| 352 | test_null_list() *test_null_list()* |
| 353 | Return a |List| that is null. Only useful for testing. |
| 354 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 355 | Return type: list<any> |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 356 | |
| 357 | test_null_partial() *test_null_partial()* |
| 358 | Return a |Partial| that is null. Only useful for testing. |
| 359 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 360 | Return type: func(...): unknown |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 361 | |
| 362 | test_null_string() *test_null_string()* |
| 363 | Return a |String| that is null. Only useful for testing. |
| 364 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 365 | Return type: |String| |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 366 | |
| 367 | test_option_not_set({name}) *test_option_not_set()* |
| 368 | Reset the flag that indicates option {name} was set. Thus it |
| 369 | looks like it still has the default value. Use like this: > |
| 370 | set ambiwidth=double |
| 371 | call test_option_not_set('ambiwidth') |
| 372 | < Now the 'ambiwidth' option behaves like it was never changed, |
| 373 | even though the value is "double". |
| 374 | Only to be used for testing! |
| 375 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 376 | Can also be used as a |method|: > |
| 377 | GetOptionName()->test_option_not_set() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 378 | < |
| 379 | Return type: |Number| |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 380 | |
| 381 | test_override({name}, {val}) *test_override()* |
| 382 | Overrides certain parts of Vim's internal processing to be able |
| 383 | to run tests. Only to be used for testing Vim! |
| 384 | The override is enabled when {val} is non-zero and removed |
| 385 | when {val} is zero. |
Bram Moolenaar | 3e4fa3d | 2022-01-13 22:05:09 +0000 | [diff] [blame] | 386 | Current supported values for {name} are: |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 387 | |
Bram Moolenaar | 3e4fa3d | 2022-01-13 22:05:09 +0000 | [diff] [blame] | 388 | {name} effect when {val} is non-zero ~ |
Bram Moolenaar | fa4873c | 2022-06-30 22:13:59 +0100 | [diff] [blame] | 389 | alloc_lines make a copy of every buffer line into allocated |
| 390 | memory, so that memory access errors can be found |
h-east | 53753f6 | 2024-05-05 18:42:31 +0200 | [diff] [blame] | 391 | by valgrind. |
Bram Moolenaar | 3e4fa3d | 2022-01-13 22:05:09 +0000 | [diff] [blame] | 392 | autoload `import autoload` will load the script right |
h-east | 53753f6 | 2024-05-05 18:42:31 +0200 | [diff] [blame] | 393 | away, not postponed until an item is used. |
| 394 | char_avail disable the char_avail() function. |
Yegappan Lakshmanan | 5715a72 | 2024-05-03 18:24:07 +0200 | [diff] [blame] | 395 | defcompile all the |:def| functions in a sourced script are |
| 396 | compiled when defined. This is similar to using |
| 397 | the |:defcompile| command in a script. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 398 | nfa_fail makes the NFA regexp engine fail to force a |
h-east | 53753f6 | 2024-05-05 18:42:31 +0200 | [diff] [blame] | 399 | fallback to the old engine. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 400 | no_query_mouse do not query the mouse position for "dec" |
h-east | 53753f6 | 2024-05-05 18:42:31 +0200 | [diff] [blame] | 401 | terminals. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 402 | no_wait_return set the "no_wait_return" flag. Not restored |
| 403 | with "ALL". |
h-east | 53753f6 | 2024-05-05 18:42:31 +0200 | [diff] [blame] | 404 | redraw disable the redrawing() function. |
| 405 | redraw_flag ignore the RedrawingDisabled flag. |
| 406 | starting reset the "starting" variable, see below. |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 407 | term_props reset all terminal properties when the version |
h-east | 53753f6 | 2024-05-05 18:42:31 +0200 | [diff] [blame] | 408 | string is detected. |
Bram Moolenaar | 3e4fa3d | 2022-01-13 22:05:09 +0000 | [diff] [blame] | 409 | ui_delay time in msec to use in ui_delay(); overrules a |
h-east | 53753f6 | 2024-05-05 18:42:31 +0200 | [diff] [blame] | 410 | wait time of up to 3 seconds for messages. |
| 411 | unreachable no error for code after `:throw` and `:return`. |
| 412 | uptime overrules sysinfo.uptime. |
ichizok | ae1bd87 | 2022-01-20 14:57:29 +0000 | [diff] [blame] | 413 | vterm_title setting the window title by a job running in a |
h-east | 53753f6 | 2024-05-05 18:42:31 +0200 | [diff] [blame] | 414 | terminal window. |
Bram Moolenaar | fa4873c | 2022-06-30 22:13:59 +0100 | [diff] [blame] | 415 | ALL clear all overrides, except alloc_lines ({val} is |
h-east | 53753f6 | 2024-05-05 18:42:31 +0200 | [diff] [blame] | 416 | not used). |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 417 | |
| 418 | "starting" is to be used when a test should behave like |
| 419 | startup was done. Since the tests are run by sourcing a |
| 420 | script the "starting" variable is non-zero. This is usually a |
Bram Moolenaar | 9d383f3 | 2023-05-14 21:38:12 +0100 | [diff] [blame] | 421 | good thing (tests run faster), but sometimes this changes |
| 422 | behavior in a way that the test doesn't work properly. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 423 | When using: > |
| 424 | call test_override('starting', 1) |
| 425 | < The value of "starting" is saved. It is restored by: > |
| 426 | call test_override('starting', 0) |
| 427 | |
Bram Moolenaar | 9d383f3 | 2023-05-14 21:38:12 +0100 | [diff] [blame] | 428 | < To make sure the flag is reset later using `:defer` can be |
| 429 | useful: > |
| 430 | call test_override('unreachable', 1) |
| 431 | defer call test_override('unreachable', 0) |
| 432 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 433 | < Can also be used as a |method|: > |
| 434 | GetOverrideVal()-> test_override('starting') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 435 | < |
| 436 | Return type: |Number| |
Bram Moolenaar | 89a9c15 | 2021-08-29 21:55:35 +0200 | [diff] [blame] | 437 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 438 | test_refcount({expr}) *test_refcount()* |
| 439 | Return the reference count of {expr}. When {expr} is of a |
| 440 | type that does not have a reference count, returns -1. Only |
| 441 | to be used for testing. |
| 442 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 443 | Can also be used as a |method|: > |
| 444 | GetVarname()->test_refcount() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 445 | < |
| 446 | Return type: |Number| |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 447 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 448 | test_setmouse({row}, {col}) *test_setmouse()* |
| 449 | Set the mouse position to be used for the next mouse action. |
| 450 | {row} and {col} are one based. |
| 451 | For example: > |
| 452 | call test_setmouse(4, 20) |
| 453 | call feedkeys("\<LeftMouse>", "xt") |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 454 | < |
| 455 | Return type: |Number| |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 456 | |
Bram Moolenaar | 89a9c15 | 2021-08-29 21:55:35 +0200 | [diff] [blame] | 457 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 458 | test_settime({expr}) *test_settime()* |
| 459 | Set the time Vim uses internally. Currently only used for |
| 460 | timestamps in the history, as they are used in viminfo, and |
| 461 | for undo. |
| 462 | Using a value of 1 makes Vim not sleep after a warning or |
| 463 | error message. |
| 464 | {expr} must evaluate to a number. When the value is zero the |
| 465 | normal behavior is restored. |
| 466 | |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 467 | Can also be used as a |method|: > |
| 468 | GetTime()->test_settime() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 469 | < |
| 470 | Return type: |Number| |
Bram Moolenaar | 89a9c15 | 2021-08-29 21:55:35 +0200 | [diff] [blame] | 471 | |
Doug Kearns | 9cd9e75 | 2024-04-07 17:42:17 +0200 | [diff] [blame] | 472 | test_srand_seed([{seed}]) *test_srand_seed()* |
| 473 | When {seed} is given this sets the seed value used by |
Bram Moolenaar | 4f645c5 | 2020-02-08 16:40:39 +0100 | [diff] [blame] | 474 | `srand()`. When omitted the test seed is removed. |
| 475 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 476 | Return type: |Number| |
Bram Moolenaar | 89a9c15 | 2021-08-29 21:55:35 +0200 | [diff] [blame] | 477 | |
| 478 | test_unknown() *test_unknown()* |
| 479 | Return a value with unknown type. Only useful for testing. |
| 480 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 481 | Return type: unknown |
Bram Moolenaar | 89a9c15 | 2021-08-29 21:55:35 +0200 | [diff] [blame] | 482 | |
| 483 | test_void() *test_void()* |
| 484 | Return a value with void type. Only useful for testing. |
| 485 | |
h-east | 84ac212 | 2024-06-17 18:12:30 +0200 | [diff] [blame] | 486 | Return type: void |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 487 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 488 | ============================================================================== |
Bram Moolenaar | 5477506 | 2019-07-31 21:07:14 +0200 | [diff] [blame] | 489 | 3. Assert functions *assert-functions-details* |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 490 | |
| 491 | |
| 492 | assert_beeps({cmd}) *assert_beeps()* |
| 493 | Run {cmd} and add an error message to |v:errors| if it does |
| 494 | NOT produce a beep or visual bell. |
Bram Moolenaar | 5b8cabf | 2021-04-02 18:55:57 +0200 | [diff] [blame] | 495 | Also see |assert_fails()|, |assert_nobeep()| and |
| 496 | |assert-return|. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 497 | |
Bram Moolenaar | 24278d2 | 2019-08-16 21:49:22 +0200 | [diff] [blame] | 498 | Can also be used as a |method|: > |
| 499 | GetCmd()->assert_beeps() |
| 500 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 501 | Return type: |Number| |
h-east | 84ac212 | 2024-06-17 18:12:30 +0200 | [diff] [blame] | 502 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 503 | *assert_equal()* |
| 504 | assert_equal({expected}, {actual} [, {msg}]) |
| 505 | When {expected} and {actual} are not equal an error message is |
| 506 | added to |v:errors| and 1 is returned. Otherwise zero is |
Bram Moolenaar | b7398fe | 2023-05-14 18:50:25 +0100 | [diff] [blame] | 507 | returned. |assert-return| |
| 508 | The error is in the form "Expected {expected} but got |
| 509 | {actual}". When {msg} is present it is prefixed to that. |
| 510 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 511 | There is no automatic conversion, the String "4" is different |
| 512 | from the Number 4. And the number 4 is different from the |
| 513 | Float 4.0. The value of 'ignorecase' is not used here, case |
| 514 | always matters. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 515 | Example: > |
| 516 | assert_equal('foo', 'bar') |
| 517 | < Will result in a string to be added to |v:errors|: |
| 518 | test.vim line 12: Expected 'foo' but got 'bar' ~ |
| 519 | |
Bram Moolenaar | 7ff7846 | 2020-07-10 22:00:53 +0200 | [diff] [blame] | 520 | Can also be used as a |method|, the base is passed as the |
| 521 | second argument: > |
Bram Moolenaar | 25e4223 | 2019-08-04 15:04:10 +0200 | [diff] [blame] | 522 | mylist->assert_equal([1, 2, 3]) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 523 | < |
| 524 | Return type: |Number| |
Bram Moolenaar | 25e4223 | 2019-08-04 15:04:10 +0200 | [diff] [blame] | 525 | |
h-east | 84ac212 | 2024-06-17 18:12:30 +0200 | [diff] [blame] | 526 | *assert_equalfile()* |
Bram Moolenaar | fb517ba | 2020-06-03 19:55:35 +0200 | [diff] [blame] | 527 | assert_equalfile({fname-one}, {fname-two} [, {msg}]) |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 528 | When the files {fname-one} and {fname-two} do not contain |
| 529 | exactly the same text an error message is added to |v:errors|. |
| 530 | Also see |assert-return|. |
| 531 | When {fname-one} or {fname-two} does not exist the error will |
| 532 | mention that. |
| 533 | Mainly useful with |terminal-diff|. |
| 534 | |
Bram Moolenaar | e49fbff | 2019-08-21 22:50:07 +0200 | [diff] [blame] | 535 | Can also be used as a |method|: > |
| 536 | GetLog()->assert_equalfile('expected.log') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 537 | < |
| 538 | Return type: |Number| |
Bram Moolenaar | e49fbff | 2019-08-21 22:50:07 +0200 | [diff] [blame] | 539 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 540 | assert_exception({error} [, {msg}]) *assert_exception()* |
| 541 | When v:exception does not contain the string {error} an error |
| 542 | message is added to |v:errors|. Also see |assert-return|. |
| 543 | This can be used to assert that a command throws an exception. |
| 544 | Using the error number, followed by a colon, avoids problems |
| 545 | with translations: > |
| 546 | try |
| 547 | commandthatfails |
| 548 | call assert_false(1, 'command should have failed') |
| 549 | catch |
| 550 | call assert_exception('E492:') |
| 551 | endtry |
Bram Moolenaar | 1d63454 | 2020-08-18 13:41:50 +0200 | [diff] [blame] | 552 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 553 | Return type: |Number| |
h-east | 84ac212 | 2024-06-17 18:12:30 +0200 | [diff] [blame] | 554 | |
Bram Moolenaar | 1d63454 | 2020-08-18 13:41:50 +0200 | [diff] [blame] | 555 | *assert_fails()* |
Bram Moolenaar | 9bd5d87 | 2020-09-06 21:47:48 +0200 | [diff] [blame] | 556 | assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]]) |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 557 | Run {cmd} and add an error message to |v:errors| if it does |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 558 | NOT produce an error or when {error} is not found in the |
| 559 | error message. Also see |assert-return|. |
Bram Moolenaar | 6f4754b | 2022-01-23 12:07:04 +0000 | [diff] [blame] | 560 | *E856* |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 561 | When {error} is a string it must be found literally in the |
| 562 | first reported error. Most often this will be the error code, |
| 563 | including the colon, e.g. "E123:". > |
| 564 | assert_fails('bad cmd', 'E987:') |
| 565 | < |
| 566 | When {error} is a |List| with one or two strings, these are |
| 567 | used as patterns. The first pattern is matched against the |
| 568 | first reported error: > |
| 569 | assert_fails('cmd', ['E987:.*expected bool']) |
| 570 | < The second pattern, if present, is matched against the last |
Bram Moolenaar | 4072ba5 | 2020-12-23 13:56:35 +0100 | [diff] [blame] | 571 | reported error. |
| 572 | If there is only one error then both patterns must match. This |
| 573 | can be used to check that there is only one error. |
| 574 | To only match the last error use an empty string for the first |
| 575 | error: > |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 576 | assert_fails('cmd', ['', 'E987:']) |
| 577 | < |
Bram Moolenaar | 1d63454 | 2020-08-18 13:41:50 +0200 | [diff] [blame] | 578 | If {msg} is empty then it is not used. Do this to get the |
| 579 | default message when passing the {lnum} argument. |
Bram Moolenaar | f10911e | 2022-01-29 22:20:48 +0000 | [diff] [blame] | 580 | *E1115* |
Bram Moolenaar | 1d63454 | 2020-08-18 13:41:50 +0200 | [diff] [blame] | 581 | When {lnum} is present and not negative, and the {error} |
| 582 | argument is present and matches, then this is compared with |
| 583 | the line number at which the error was reported. That can be |
| 584 | the line number in a function or in a script. |
Bram Moolenaar | f10911e | 2022-01-29 22:20:48 +0000 | [diff] [blame] | 585 | *E1116* |
Bram Moolenaar | 9bd5d87 | 2020-09-06 21:47:48 +0200 | [diff] [blame] | 586 | When {context} is present it is used as a pattern and matched |
| 587 | against the context (script name or function name) where |
| 588 | {lnum} is located in. |
| 589 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 590 | Note that beeping is not considered an error, and some failing |
| 591 | commands only beep. Use |assert_beeps()| for those. |
| 592 | |
Bram Moolenaar | 24278d2 | 2019-08-16 21:49:22 +0200 | [diff] [blame] | 593 | Can also be used as a |method|: > |
| 594 | GetCmd()->assert_fails('E99:') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 595 | < |
| 596 | Return type: |Number| |
Bram Moolenaar | 24278d2 | 2019-08-16 21:49:22 +0200 | [diff] [blame] | 597 | |
Bram Moolenaar | 1d63454 | 2020-08-18 13:41:50 +0200 | [diff] [blame] | 598 | assert_false({actual} [, {msg}]) *assert_false()* |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 599 | When {actual} is not false an error message is added to |
| 600 | |v:errors|, like with |assert_equal()|. |
Bram Moolenaar | b7398fe | 2023-05-14 18:50:25 +0100 | [diff] [blame] | 601 | The error is in the form "Expected False but got {actual}". |
| 602 | When {msg} is present it is prepended to that. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 603 | Also see |assert-return|. |
Bram Moolenaar | b7398fe | 2023-05-14 18:50:25 +0100 | [diff] [blame] | 604 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 605 | A value is false when it is zero. When {actual} is not a |
| 606 | number the assert fails. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 607 | |
Bram Moolenaar | 24278d2 | 2019-08-16 21:49:22 +0200 | [diff] [blame] | 608 | Can also be used as a |method|: > |
| 609 | GetResult()->assert_false() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 610 | < |
| 611 | Return type: |Number| |
Bram Moolenaar | 24278d2 | 2019-08-16 21:49:22 +0200 | [diff] [blame] | 612 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 613 | assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()* |
| 614 | This asserts number and |Float| values. When {actual} is lower |
| 615 | than {lower} or higher than {upper} an error message is added |
| 616 | to |v:errors|. Also see |assert-return|. |
Bram Moolenaar | b7398fe | 2023-05-14 18:50:25 +0100 | [diff] [blame] | 617 | The error is in the form "Expected range {lower} - {upper}, |
| 618 | but got {actual}". When {msg} is present it is prefixed to |
| 619 | that. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 620 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 621 | Return type: |Number| |
| 622 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 623 | *assert_match()* |
| 624 | assert_match({pattern}, {actual} [, {msg}]) |
| 625 | When {pattern} does not match {actual} an error message is |
| 626 | added to |v:errors|. Also see |assert-return|. |
Bram Moolenaar | b7398fe | 2023-05-14 18:50:25 +0100 | [diff] [blame] | 627 | The error is in the form "Pattern {pattern} does not match |
| 628 | {actual}". When {msg} is present it is prefixed to that. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 629 | |
| 630 | {pattern} is used as with |=~|: The matching is always done |
| 631 | like 'magic' was set and 'cpoptions' is empty, no matter what |
| 632 | the actual value of 'magic' or 'cpoptions' is. |
| 633 | |
| 634 | {actual} is used as a string, automatic conversion applies. |
| 635 | Use "^" and "$" to match with the start and end of the text. |
| 636 | Use both to match the whole text. |
| 637 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 638 | Example: > |
| 639 | assert_match('^f.*o$', 'foobar') |
| 640 | < Will result in a string to be added to |v:errors|: |
| 641 | test.vim line 12: Pattern '^f.*o$' does not match 'foobar' ~ |
| 642 | |
Bram Moolenaar | 24278d2 | 2019-08-16 21:49:22 +0200 | [diff] [blame] | 643 | Can also be used as a |method|: > |
| 644 | getFile()->assert_match('foo.*') |
| 645 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 646 | Return type: |Number| |
| 647 | |
Bram Moolenaar | 5b8cabf | 2021-04-02 18:55:57 +0200 | [diff] [blame] | 648 | assert_nobeep({cmd}) *assert_nobeep()* |
| 649 | Run {cmd} and add an error message to |v:errors| if it |
| 650 | produces a beep or visual bell. |
| 651 | Also see |assert_beeps()|. |
| 652 | |
| 653 | Can also be used as a |method|: > |
| 654 | GetCmd()->assert_nobeep() |
| 655 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 656 | Return type: |Number| |
| 657 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 658 | *assert_notequal()* |
| 659 | assert_notequal({expected}, {actual} [, {msg}]) |
| 660 | The opposite of `assert_equal()`: add an error message to |
| 661 | |v:errors| when {expected} and {actual} are equal. |
| 662 | Also see |assert-return|. |
| 663 | |
Bram Moolenaar | 25e4223 | 2019-08-04 15:04:10 +0200 | [diff] [blame] | 664 | Can also be used as a |method|: > |
| 665 | mylist->assert_notequal([1, 2, 3]) |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 666 | < |
| 667 | Return type: |Number| |
Bram Moolenaar | 25e4223 | 2019-08-04 15:04:10 +0200 | [diff] [blame] | 668 | |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 669 | *assert_notmatch()* |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 670 | assert_notmatch({pattern}, {actual} [, {msg}]) |
| 671 | The opposite of `assert_match()`: add an error message to |
| 672 | |v:errors| when {pattern} matches {actual}. |
| 673 | Also see |assert-return|. |
| 674 | |
Bram Moolenaar | 24278d2 | 2019-08-16 21:49:22 +0200 | [diff] [blame] | 675 | Can also be used as a |method|: > |
| 676 | getFile()->assert_notmatch('bar.*') |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 677 | < |
| 678 | Return type: |Number| |
Bram Moolenaar | e49fbff | 2019-08-21 22:50:07 +0200 | [diff] [blame] | 679 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 680 | assert_report({msg}) *assert_report()* |
Bram Moolenaar | 6aa5729 | 2021-08-14 21:25:52 +0200 | [diff] [blame] | 681 | Report a test failure directly, using String {msg}. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 682 | Always returns one. |
| 683 | |
Bram Moolenaar | e49fbff | 2019-08-21 22:50:07 +0200 | [diff] [blame] | 684 | Can also be used as a |method|: > |
| 685 | GetMessage()->assert_report() |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 686 | < |
| 687 | Return type: |Number| |
Bram Moolenaar | e49fbff | 2019-08-21 22:50:07 +0200 | [diff] [blame] | 688 | |
| 689 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 690 | assert_true({actual} [, {msg}]) *assert_true()* |
| 691 | When {actual} is not true an error message is added to |
| 692 | |v:errors|, like with |assert_equal()|. |
| 693 | Also see |assert-return|. |
| 694 | A value is TRUE when it is a non-zero number. When {actual} |
| 695 | is not a number the assert fails. |
Bram Moolenaar | b7398fe | 2023-05-14 18:50:25 +0100 | [diff] [blame] | 696 | When {msg} is given it precedes the default message. |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 697 | |
Bram Moolenaar | 24278d2 | 2019-08-16 21:49:22 +0200 | [diff] [blame] | 698 | Can also be used as a |method|: > |
| 699 | GetResult()->assert_true() |
| 700 | < |
Christian Brabandt | 5674c9a | 2024-06-09 00:13:43 +0200 | [diff] [blame] | 701 | Return type: |Number| |
| 702 | |
Bram Moolenaar | ed997ad | 2019-07-21 16:42:00 +0200 | [diff] [blame] | 703 | |
| 704 | vim:tw=78:ts=8:noet:ft=help:norl: |