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