blob: e06139c3f3e60b610c971299253c975d9c011a7a [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 +01003CheckFeature quickfix
Bram Moolenaarc31f9ae2017-07-23 22:02:02 +02004
5func 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
15endfunc
Bram Moolenaaree4e0c12020-04-06 21:35:05 +020016
Yinzuo Jianga2a2fe82024-12-16 21:22:09 +010017func s:goto_preview_and_close()
Bram Moolenaaree4e0c12020-04-06 21:35:05 +020018 " Go to the preview window
19 wincmd P
20 call assert_equal(1, &previewwindow)
Bram Moolenaar0fe937f2020-06-16 22:42:04 +020021 call assert_equal('preview', win_gettype())
Bram Moolenaaree4e0c12020-04-06 21:35:05 +020022
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:')
29endfunc
30
Yinzuo Jianga2a2fe82024-12-16 21:22:09 +010031func 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()
40endfunc
41
42func 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
zeertzjq3baf19a2024-12-19 20:05:28 +010049
50 call feedkeys(":pbuffer Xpre\<C-A>\<C-B>\"\<CR>", 'xt')
51 call assert_equal("\"pbuffer Xpreview.c", @:)
52
Yinzuo Jianga2a2fe82024-12-16 21:22:09 +010053 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()
zeertzjq3baf19a2024-12-19 20:05:28 +010059
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 Jianga2a2fe82024-12-16 21:22:09 +010066endfunc
67
68func 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()
80endfunc
81
Bram Moolenaaree4e0c12020-04-06 21:35:05 +020082func Test_window_preview_from_help()
83 CheckFeature quickfix
84
85 filetype on
Bram Moolenaar145d1fd2022-09-30 21:57:11 +010086 call writefile(['/* some C code */'], 'Xpreview.c', 'D')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +020087 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 Moolenaaree4e0c12020-04-06 21:35:05 +020096endfunc
97
98func Test_multiple_preview_windows()
99 new
100 set previewwindow
101 new
102 call assert_fails('set previewwindow', 'E590:')
103 %bw!
104endfunc
105
106" vim: shiftwidth=2 sts=2 expandtab