test_preview.vim (2253B)
1 " Tests for the preview window 2 3 source check.vim 4 CheckFeature quickfix 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 17 18 func s:goto_preview_and_close() 19 " Go to the preview window 20 wincmd P 21 call assert_equal(1, &previewwindow) 22 call assert_equal('preview', win_gettype()) 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 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 51 call feedkeys(":pbuffer Xpre\<C-A>\<C-B>\"\<CR>", 'xt') 52 call assert_equal("\"pbuffer Xpreview.c", @:) 53 54 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() 60 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() 67 endfunc 68 69 func Test_window_preview_terminal() 70 CheckFeature quickfix 71 " CheckFeature terminal 72 73 " term ++curwin 74 term 75 const buf_num = bufnr('$') 76 call assert_equal(1, winnr('$')) 77 exe 'pbuffer' . buf_num 78 call assert_equal(2, winnr('$')) 79 call assert_equal(0, &previewwindow) 80 81 call s:goto_preview_and_close() 82 endfunc 83 84 func Test_window_preview_from_help() 85 CheckFeature quickfix 86 87 filetype on 88 call writefile(['/* some C code */'], 'Xpreview.c') 89 help 90 pedit Xpreview.c 91 wincmd P 92 call assert_equal(1, &previewwindow) 93 call assert_equal('c', &filetype) 94 wincmd z 95 96 filetype off 97 close 98 call delete('Xpreview.c') 99 endfunc 100 101 func Test_multiple_preview_windows() 102 new 103 set previewwindow 104 new 105 call assert_fails('set previewwindow', 'E590:') 106 %bw! 107 endfunc 108 109 " vim: shiftwidth=2 sts=2 expandtab