blob: 7c7883ace06b3fa0c4866ec78ddd154d07866ab6 [file] [log] [blame]
Bram Moolenaarc31f9ae2017-07-23 22:02:02 +02001" Tests for the preview window
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02002
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01003source check.vim
4CheckFeature quickfix
Bram Moolenaarc31f9ae2017-07-23 22:02:02 +02005
6func 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
16endfunc
Bram Moolenaaree4e0c12020-04-06 21:35:05 +020017
Yinzuo Jianga2a2fe82024-12-16 21:22:09 +010018func s:goto_preview_and_close()
Bram Moolenaaree4e0c12020-04-06 21:35:05 +020019 " Go to the preview window
20 wincmd P
21 call assert_equal(1, &previewwindow)
Bram Moolenaar0fe937f2020-06-16 22:42:04 +020022 call assert_equal('preview', win_gettype())
Bram Moolenaaree4e0c12020-04-06 21:35:05 +020023
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:')
30endfunc
31
Yinzuo Jianga2a2fe82024-12-16 21:22:09 +010032func 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()
41endfunc
42
43func 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
zeertzjq3baf19a2024-12-19 20:05:28 +010050
51 call feedkeys(":pbuffer Xpre\<C-A>\<C-B>\"\<CR>", 'xt')
52 call assert_equal("\"pbuffer Xpreview.c", @:)
53
Yinzuo Jianga2a2fe82024-12-16 21:22:09 +010054 call assert_equal(1, winnr('$'))
55 exe 'pbuffer ' . buf_num
56 call assert_equal(2, winnr('$'))
57 call assert_equal(0, &previewwindow)
58
59 call s:goto_preview_and_close()
zeertzjq3baf19a2024-12-19 20:05:28 +010060
61 call assert_equal(1, winnr('$'))
62 pbuffer Xpreview.c
63 call assert_equal(2, winnr('$'))
64 call assert_equal(0, &previewwindow)
65
66 call s:goto_preview_and_close()
Yinzuo Jianga2a2fe82024-12-16 21:22:09 +010067endfunc
68
69func Test_window_preview_terminal()
70 CheckFeature quickfix
71 CheckFeature terminal
72
73 term ++curwin
74 const buf_num = bufnr('$')
75 call assert_equal(1, winnr('$'))
76 exe 'pbuffer' . buf_num
77 call assert_equal(2, winnr('$'))
78 call assert_equal(0, &previewwindow)
79
80 call s:goto_preview_and_close()
81endfunc
82
Bram Moolenaaree4e0c12020-04-06 21:35:05 +020083func Test_window_preview_from_help()
84 CheckFeature quickfix
85
86 filetype on
Bram Moolenaar145d1fd2022-09-30 21:57:11 +010087 call writefile(['/* some C code */'], 'Xpreview.c', 'D')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +020088 help
89 pedit Xpreview.c
90 wincmd P
91 call assert_equal(1, &previewwindow)
92 call assert_equal('c', &filetype)
93 wincmd z
94
95 filetype off
96 close
Bram Moolenaaree4e0c12020-04-06 21:35:05 +020097endfunc
98
99func Test_multiple_preview_windows()
100 new
101 set previewwindow
102 new
103 call assert_fails('set previewwindow', 'E590:')
104 %bw!
105endfunc
106
107" vim: shiftwidth=2 sts=2 expandtab