Bram Moolenaar | 12a96de | 2018-03-11 14:44:18 +0100 | [diff] [blame] | 1 | " Tests for exiting Vim. |
| 2 | |
| 3 | source shared.vim |
| 4 | |
| 5 | func Test_exiting() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 6 | let after =<< trim [CODE] |
| 7 | au QuitPre * call writefile(["QuitPre"], "Xtestout") |
| 8 | au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") |
| 9 | quit |
| 10 | [CODE] |
| 11 | |
Bram Moolenaar | 12a96de | 2018-03-11 14:44:18 +0100 | [diff] [blame] | 12 | if RunVim([], after, '') |
| 13 | call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) |
| 14 | endif |
| 15 | call delete('Xtestout') |
| 16 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 17 | let after =<< trim [CODE] |
| 18 | au QuitPre * call writefile(["QuitPre"], "Xtestout") |
| 19 | au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") |
| 20 | help |
| 21 | wincmd w |
| 22 | quit |
| 23 | [CODE] |
| 24 | |
Bram Moolenaar | 12a96de | 2018-03-11 14:44:18 +0100 | [diff] [blame] | 25 | if RunVim([], after, '') |
| 26 | call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) |
| 27 | endif |
| 28 | call delete('Xtestout') |
| 29 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 30 | let after =<< trim [CODE] |
| 31 | au QuitPre * call writefile(["QuitPre"], "Xtestout") |
| 32 | au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") |
| 33 | split |
| 34 | new |
| 35 | qall |
| 36 | [CODE] |
| 37 | |
Bram Moolenaar | 12a96de | 2018-03-11 14:44:18 +0100 | [diff] [blame] | 38 | if RunVim([], after, '') |
| 39 | call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) |
| 40 | endif |
| 41 | call delete('Xtestout') |
| 42 | |
Bram Moolenaar | 34ba06b | 2019-10-20 22:27:10 +0200 | [diff] [blame] | 43 | " ExitPre autocommand splits the window, so that it's no longer the last one. |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 44 | let after =<< trim [CODE] |
| 45 | au QuitPre * call writefile(["QuitPre"], "Xtestout", "a") |
| 46 | au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") |
| 47 | augroup nasty |
| 48 | au ExitPre * split |
| 49 | augroup END |
| 50 | quit |
| 51 | augroup nasty |
| 52 | au! ExitPre |
| 53 | augroup END |
| 54 | quit |
| 55 | [CODE] |
| 56 | |
Bram Moolenaar | 12a96de | 2018-03-11 14:44:18 +0100 | [diff] [blame] | 57 | if RunVim([], after, '') |
| 58 | call assert_equal(['QuitPre', 'ExitPre', 'QuitPre', 'ExitPre'], |
| 59 | \ readfile('Xtestout')) |
| 60 | endif |
| 61 | call delete('Xtestout') |
Bram Moolenaar | 34ba06b | 2019-10-20 22:27:10 +0200 | [diff] [blame] | 62 | |
| 63 | " ExitPre autocommand splits and closes the window, so that there is still |
| 64 | " one window but it's a different one. |
| 65 | let after =<< trim [CODE] |
| 66 | au QuitPre * call writefile(["QuitPre"], "Xtestout", "a") |
| 67 | au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") |
| 68 | augroup nasty |
| 69 | au ExitPre * split | only |
| 70 | augroup END |
| 71 | quit |
| 72 | augroup nasty |
| 73 | au! ExitPre |
| 74 | augroup END |
| 75 | quit |
| 76 | [CODE] |
| 77 | |
| 78 | if RunVim([], after, '') |
| 79 | call assert_equal(['QuitPre', 'ExitPre', 'QuitPre', 'ExitPre'], |
| 80 | \ readfile('Xtestout')) |
| 81 | endif |
| 82 | call delete('Xtestout') |
Bram Moolenaar | 12a96de | 2018-03-11 14:44:18 +0100 | [diff] [blame] | 83 | endfunc |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 84 | |
| 85 | " vim: shiftwidth=2 sts=2 expandtab |