test_hide.vim 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. " Tests for :hide command/modifier and 'hidden' option
  2. func SetUp()
  3. let s:save_hidden = &hidden
  4. let s:save_bufhidden = &bufhidden
  5. let s:save_autowrite = &autowrite
  6. set nohidden
  7. set bufhidden=
  8. set noautowrite
  9. endfunc
  10. function TearDown()
  11. let &hidden = s:save_hidden
  12. let &bufhidden = s:save_bufhidden
  13. let &autowrite = s:save_autowrite
  14. endfunc
  15. function Test_hide()
  16. let orig_bname = bufname('')
  17. let orig_winnr = winnr('$')
  18. new Xf1
  19. set modified
  20. call assert_fails('edit Xf2')
  21. bwipeout! Xf1
  22. new Xf1
  23. set modified
  24. edit! Xf2
  25. call assert_equal(['Xf2', 2], [bufname(''), winnr('$')])
  26. call assert_equal([1, 0], [buflisted('Xf1'), bufloaded('Xf1')])
  27. bwipeout! Xf1
  28. bwipeout! Xf2
  29. new Xf1
  30. set modified
  31. " :hide as a command
  32. hide
  33. call assert_equal([orig_bname, orig_winnr], [bufname(''), winnr('$')])
  34. call assert_equal([1, 1], ['Xf1'->buflisted(), 'Xf1'->bufloaded()])
  35. bwipeout! Xf1
  36. new Xf1
  37. set modified
  38. " :hide as a command with trailing comment
  39. hide " comment
  40. call assert_equal([orig_bname, orig_winnr], [bufname(''), winnr('$')])
  41. call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
  42. bwipeout! Xf1
  43. new Xf1
  44. set modified
  45. " :hide as a command with bar
  46. hide | new Xf2 " comment
  47. call assert_equal(['Xf2', 2], [bufname(''), winnr('$')])
  48. call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
  49. bwipeout! Xf1
  50. bwipeout! Xf2
  51. new Xf1
  52. set modified
  53. " :hide as a modifier with trailing comment
  54. hide edit Xf2 " comment
  55. call assert_equal(['Xf2', 2], [bufname(''), winnr('$')])
  56. call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
  57. bwipeout! Xf1
  58. bwipeout! Xf2
  59. new Xf1
  60. set modified
  61. " To check that the bar is not recognized to separate commands
  62. hide echo "one|two"
  63. call assert_equal(['Xf1', 2], [bufname(''), winnr('$')])
  64. call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
  65. bwipeout! Xf1
  66. " set hidden
  67. new Xf1
  68. set hidden
  69. set modified
  70. edit Xf2 " comment
  71. call assert_equal(['Xf2', 2], [bufname(''), winnr('$')])
  72. call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
  73. bwipeout! Xf1
  74. bwipeout! Xf2
  75. " set hidden bufhidden=wipe
  76. new Xf1
  77. set bufhidden=wipe
  78. set modified
  79. hide edit! Xf2 " comment
  80. call assert_equal(['Xf2', 2], [bufname(''), winnr('$')])
  81. call assert_equal([0, 0], [buflisted('Xf1'), bufloaded('Xf1')])
  82. bwipeout! Xf2
  83. endfunc
  84. " vim: shiftwidth=2 sts=2 expandtab