Bram Moolenaar | c31f9ae | 2017-07-23 22:02:02 +0200 | [diff] [blame] | 1 | " Tests for the preview window |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2 | |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 3 | source check.vim |
| 4 | CheckFeature quickfix |
Bram Moolenaar | c31f9ae | 2017-07-23 22:02:02 +0200 | [diff] [blame] | 5 | |
| 6 | func Test_Psearch() |
| 7 | " this used to cause ml_get errors |
| 8 | help |
| 9 | let wincount = winnr('$') |
| 10 | 0f |
| 11 | ps. |
| 12 | call assert_equal(wincount + 1, winnr('$')) |
| 13 | pclose |
| 14 | call assert_equal(wincount, winnr('$')) |
| 15 | bwipe |
| 16 | endfunc |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 17 | |
Yinzuo Jiang | a2a2fe8 | 2024-12-16 21:22:09 +0100 | [diff] [blame] | 18 | func s:goto_preview_and_close() |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 19 | " Go to the preview window |
| 20 | wincmd P |
| 21 | call assert_equal(1, &previewwindow) |
Bram Moolenaar | 0fe937f | 2020-06-16 22:42:04 +0200 | [diff] [blame] | 22 | call assert_equal('preview', win_gettype()) |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 23 | |
| 24 | " Close preview window |
| 25 | wincmd z |
| 26 | call assert_equal(1, winnr('$')) |
| 27 | call assert_equal(0, &previewwindow) |
| 28 | |
| 29 | call assert_fails('wincmd P', 'E441:') |
| 30 | endfunc |
| 31 | |
Yinzuo Jiang | a2a2fe8 | 2024-12-16 21:22:09 +0100 | [diff] [blame] | 32 | func Test_window_preview() |
| 33 | CheckFeature quickfix |
| 34 | |
| 35 | " Open a preview window |
| 36 | pedit Xa |
| 37 | call assert_equal(2, winnr('$')) |
| 38 | call assert_equal(0, &previewwindow) |
| 39 | |
| 40 | call s:goto_preview_and_close() |
| 41 | endfunc |
| 42 | |
| 43 | func Test_window_preview_from_pbuffer() |
| 44 | CheckFeature quickfix |
| 45 | |
| 46 | call writefile(['/* some C code */'], 'Xpreview.c', 'D') |
| 47 | edit Xpreview.c |
| 48 | const buf_num = bufnr('%') |
| 49 | enew |
| 50 | call assert_equal(1, winnr('$')) |
| 51 | exe 'pbuffer ' . buf_num |
| 52 | call assert_equal(2, winnr('$')) |
| 53 | call assert_equal(0, &previewwindow) |
| 54 | |
| 55 | call s:goto_preview_and_close() |
| 56 | endfunc |
| 57 | |
| 58 | func Test_window_preview_terminal() |
| 59 | CheckFeature quickfix |
| 60 | CheckFeature terminal |
| 61 | |
| 62 | term ++curwin |
| 63 | const buf_num = bufnr('$') |
| 64 | call assert_equal(1, winnr('$')) |
| 65 | exe 'pbuffer' . buf_num |
| 66 | call assert_equal(2, winnr('$')) |
| 67 | call assert_equal(0, &previewwindow) |
| 68 | |
| 69 | call s:goto_preview_and_close() |
| 70 | endfunc |
| 71 | |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 72 | func Test_window_preview_from_help() |
| 73 | CheckFeature quickfix |
| 74 | |
| 75 | filetype on |
Bram Moolenaar | 145d1fd | 2022-09-30 21:57:11 +0100 | [diff] [blame] | 76 | call writefile(['/* some C code */'], 'Xpreview.c', 'D') |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 77 | help |
| 78 | pedit Xpreview.c |
| 79 | wincmd P |
| 80 | call assert_equal(1, &previewwindow) |
| 81 | call assert_equal('c', &filetype) |
| 82 | wincmd z |
| 83 | |
| 84 | filetype off |
| 85 | close |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 86 | endfunc |
| 87 | |
| 88 | func Test_multiple_preview_windows() |
| 89 | new |
| 90 | set previewwindow |
| 91 | new |
| 92 | call assert_fails('set previewwindow', 'E590:') |
| 93 | %bw! |
| 94 | endfunc |
| 95 | |
| 96 | " vim: shiftwidth=2 sts=2 expandtab |