test_blockedit.vim 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. " Test for block inserting
  2. "
  3. func Test_blockinsert_indent()
  4. new
  5. filetype plugin indent on
  6. setlocal sw=2 et ft=vim
  7. call setline(1, ['let a=[', ' ''eins'',', ' ''zwei'',', ' ''drei'']'])
  8. call cursor(2, 3)
  9. exe "norm! \<c-v>2jI\\ \<esc>"
  10. call assert_equal(['let a=[', ' \ ''eins'',', ' \ ''zwei'',', ' \ ''drei'']'],
  11. \ getline(1,'$'))
  12. " reset to sane state
  13. filetype off
  14. bwipe!
  15. endfunc
  16. func Test_blockinsert_autoindent()
  17. new
  18. let lines =<< trim END
  19. vim9script
  20. var d = {
  21. a: () => 0,
  22. b: () => 0,
  23. c: () => 0,
  24. }
  25. END
  26. call setline(1, lines)
  27. filetype plugin indent on
  28. setlocal sw=2 et ft=vim
  29. setlocal indentkeys+=:
  30. exe "norm! 3Gf)\<c-v>2jA: asdf\<esc>"
  31. let expected =<< trim END
  32. vim9script
  33. var d = {
  34. a: (): asdf => 0,
  35. b: (): asdf => 0,
  36. c: (): asdf => 0,
  37. }
  38. END
  39. call assert_equal(expected, getline(1, 6))
  40. " insert on the next column should do exactly the same
  41. :%dele
  42. call setline(1, lines)
  43. exe "norm! 3Gf)l\<c-v>2jI: asdf\<esc>"
  44. call assert_equal(expected, getline(1, 6))
  45. :%dele
  46. call setline(1, lines)
  47. setlocal sw=8 noet
  48. exe "norm! 3Gf)\<c-v>2jA: asdf\<esc>"
  49. let expected =<< trim END
  50. vim9script
  51. var d = {
  52. a: (): asdf => 0,
  53. b: (): asdf => 0,
  54. c: (): asdf => 0,
  55. }
  56. END
  57. call assert_equal(expected, getline(1, 6))
  58. " insert on the next column should do exactly the same
  59. :%dele
  60. call setline(1, lines)
  61. exe "norm! 3Gf)l\<c-v>2jI: asdf\<esc>"
  62. call assert_equal(expected, getline(1, 6))
  63. filetype off
  64. bwipe!
  65. endfunc
  66. func Test_blockinsert_delete()
  67. new
  68. let _bs = &bs
  69. set bs=2
  70. call setline(1, ['case Arg is ', ' when Name_Async,', ' when Name_Num_Gangs,', 'end if;'])
  71. exe "norm! ggjVj\<c-v>$o$A\<bs>\<esc>"
  72. "call feedkeys("Vj\<c-v>$o$A\<bs>\<esc>", 'ti')
  73. call assert_equal(["case Arg is ", " when Name_Async", " when Name_Num_Gangs,", "end if;"],
  74. \ getline(1,'$'))
  75. " reset to sane state
  76. let &bs = _bs
  77. bwipe!
  78. endfunc
  79. func Test_blockappend_eol_cursor()
  80. new
  81. " Test 1 Move 1 char left
  82. call setline(1, ['aaa', 'bbb', 'ccc'])
  83. exe "norm! gg$\<c-v>2jA\<left>x\<esc>"
  84. call assert_equal(['aaxa', 'bbxb', 'ccxc'], getline(1, '$'))
  85. " Test 2 Move 2 chars left
  86. sil %d
  87. call setline(1, ['aaa', 'bbb', 'ccc'])
  88. exe "norm! gg$\<c-v>2jA\<left>\<left>x\<esc>"
  89. call assert_equal(['axaa', 'bxbb', 'cxcc'], getline(1, '$'))
  90. " Test 3 Move 3 chars left (outside of the visual selection)
  91. sil %d
  92. call setline(1, ['aaa', 'bbb', 'ccc'])
  93. exe "norm! ggl$\<c-v>2jA\<left>\<left>\<left>x\<esc>"
  94. call assert_equal(['xaaa', 'bbb', 'ccc'], getline(1, '$'))
  95. bw!
  96. endfunc
  97. func Test_blockappend_eol_cursor2()
  98. new
  99. " Test 1 Move 1 char left
  100. call setline(1, ['aaaaa', 'bbb', 'ccccc'])
  101. exe "norm! gg\<c-v>$2jA\<left>x\<esc>"
  102. call assert_equal(['aaaaxa', 'bbbx', 'ccccxc'], getline(1, '$'))
  103. " Test 2 Move 2 chars left
  104. sil %d
  105. call setline(1, ['aaaaa', 'bbb', 'ccccc'])
  106. exe "norm! gg\<c-v>$2jA\<left>\<left>x\<esc>"
  107. call assert_equal(['aaaxaa', 'bbbx', 'cccxcc'], getline(1, '$'))
  108. " Test 3 Move 3 chars left (to the beginning of the visual selection)
  109. sil %d
  110. call setline(1, ['aaaaa', 'bbb', 'ccccc'])
  111. exe "norm! gg\<c-v>$2jA\<left>\<left>\<left>x\<esc>"
  112. call assert_equal(['aaxaaa', 'bbxb', 'ccxccc'], getline(1, '$'))
  113. " Test 4 Move 3 chars left (outside of the visual selection)
  114. sil %d
  115. call setline(1, ['aaaaa', 'bbb', 'ccccc'])
  116. exe "norm! ggl\<c-v>$2jA\<left>\<left>\<left>x\<esc>"
  117. call assert_equal(['aaxaaa', 'bbxb', 'ccxccc'], getline(1, '$'))
  118. " Test 5 Move 4 chars left (outside of the visual selection)
  119. sil %d
  120. call setline(1, ['aaaaa', 'bbb', 'ccccc'])
  121. exe "norm! ggl\<c-v>$2jA\<left>\<left>\<left>\<left>x\<esc>"
  122. call assert_equal(['axaaaa', 'bxbb', 'cxcccc'], getline(1, '$'))
  123. bw!
  124. endfunc
  125. " vim: shiftwidth=2 sts=2 expandtab