test_preview.vim 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. " Tests for the preview window
  2. source check.vim
  3. CheckFeature quickfix
  4. func Test_Psearch()
  5. " this used to cause ml_get errors
  6. help
  7. let wincount = winnr('$')
  8. 0f
  9. ps.
  10. call assert_equal(wincount + 1, winnr('$'))
  11. pclose
  12. call assert_equal(wincount, winnr('$'))
  13. bwipe
  14. endfunc
  15. func s:goto_preview_and_close()
  16. " Go to the preview window
  17. wincmd P
  18. call assert_equal(1, &previewwindow)
  19. call assert_equal('preview', win_gettype())
  20. " Close preview window
  21. wincmd z
  22. call assert_equal(1, winnr('$'))
  23. call assert_equal(0, &previewwindow)
  24. call assert_fails('wincmd P', 'E441:')
  25. endfunc
  26. func Test_window_preview()
  27. CheckFeature quickfix
  28. " Open a preview window
  29. pedit Xa
  30. call assert_equal(2, winnr('$'))
  31. call assert_equal(0, &previewwindow)
  32. call s:goto_preview_and_close()
  33. endfunc
  34. func Test_window_preview_from_pbuffer()
  35. CheckFeature quickfix
  36. call writefile(['/* some C code */'], 'Xpreview.c', 'D')
  37. edit Xpreview.c
  38. const buf_num = bufnr('%')
  39. enew
  40. call feedkeys(":pbuffer Xpre\<C-A>\<C-B>\"\<CR>", 'xt')
  41. call assert_equal("\"pbuffer Xpreview.c", @:)
  42. call assert_equal(1, winnr('$'))
  43. exe 'pbuffer ' . buf_num
  44. call assert_equal(2, winnr('$'))
  45. call assert_equal(0, &previewwindow)
  46. call s:goto_preview_and_close()
  47. call assert_equal(1, winnr('$'))
  48. pbuffer Xpreview.c
  49. call assert_equal(2, winnr('$'))
  50. call assert_equal(0, &previewwindow)
  51. call s:goto_preview_and_close()
  52. endfunc
  53. func Test_window_preview_terminal()
  54. CheckFeature quickfix
  55. " CheckFeature terminal
  56. " term ++curwin
  57. term
  58. const buf_num = bufnr('$')
  59. call assert_equal(1, winnr('$'))
  60. exe 'pbuffer' . buf_num
  61. call assert_equal(2, winnr('$'))
  62. call assert_equal(0, &previewwindow)
  63. call s:goto_preview_and_close()
  64. endfunc
  65. func Test_window_preview_from_help()
  66. CheckFeature quickfix
  67. filetype on
  68. call writefile(['/* some C code */'], 'Xpreview.c')
  69. help
  70. pedit Xpreview.c
  71. wincmd P
  72. call assert_equal(1, &previewwindow)
  73. call assert_equal('c', &filetype)
  74. wincmd z
  75. filetype off
  76. close
  77. call delete('Xpreview.c')
  78. endfunc
  79. func Test_multiple_preview_windows()
  80. new
  81. set previewwindow
  82. new
  83. call assert_fails('set previewwindow', 'E590:')
  84. %bw!
  85. endfunc
  86. " vim: shiftwidth=2 sts=2 expandtab