blob: 0df1a90222d1650d7466f2f03fe45e9cdcb704c5 [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
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()
56endfunc
57
58func 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()
70endfunc
71
Bram Moolenaaree4e0c12020-04-06 21:35:05 +020072func Test_window_preview_from_help()
73 CheckFeature quickfix
74
75 filetype on
Bram Moolenaar145d1fd2022-09-30 21:57:11 +010076 call writefile(['/* some C code */'], 'Xpreview.c', 'D')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +020077 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 Moolenaaree4e0c12020-04-06 21:35:05 +020086endfunc
87
88func Test_multiple_preview_windows()
89 new
90 set previewwindow
91 new
92 call assert_fails('set previewwindow', 'E590:')
93 %bw!
94endfunc
95
96" vim: shiftwidth=2 sts=2 expandtab