test_shift.vim 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. " Test shifting lines with :> and :<
  2. source check.vim
  3. func Test_ex_shift_right()
  4. set shiftwidth=2
  5. " shift right current line.
  6. call setline(1, range(1, 5))
  7. 2
  8. >
  9. 3
  10. >>
  11. call assert_equal(['1',
  12. \ ' 2',
  13. \ ' 3',
  14. \ '4',
  15. \ '5'], getline(1, '$'))
  16. " shift right with range.
  17. call setline(1, range(1, 4))
  18. 2,3>>
  19. call assert_equal(['1',
  20. \ ' 2',
  21. \ ' 3',
  22. \ '4',
  23. \ '5'], getline(1, '$'))
  24. " shift right with range and count.
  25. call setline(1, range(1, 4))
  26. 2>3
  27. call assert_equal(['1',
  28. \ ' 2',
  29. \ ' 3',
  30. \ ' 4',
  31. \ '5'], getline(1, '$'))
  32. bw!
  33. set shiftwidth&
  34. endfunc
  35. func Test_ex_shift_left()
  36. set shiftwidth=2
  37. call setline(1, range(1, 5))
  38. %>>>
  39. " left shift current line.
  40. 2<
  41. 3<<
  42. 4<<<<<
  43. call assert_equal([' 1',
  44. \ ' 2',
  45. \ ' 3',
  46. \ '4',
  47. \ ' 5'], getline(1, '$'))
  48. " shift right with range.
  49. call setline(1, range(1, 5))
  50. %>>>
  51. 2,3<<
  52. call assert_equal([' 1',
  53. \ ' 2',
  54. \ ' 3',
  55. \ ' 4',
  56. \ ' 5'], getline(1, '$'))
  57. " shift right with range and count.
  58. call setline(1, range(1, 5))
  59. %>>>
  60. 2<<3
  61. call assert_equal([' 1',
  62. \ ' 2',
  63. \ ' 3',
  64. \ ' 4',
  65. \ ' 5'], getline(1, '$'))
  66. bw!
  67. set shiftwidth&
  68. endfunc
  69. func Test_ex_shift_rightleft()
  70. CheckFeature rightleft
  71. set shiftwidth=2 rightleft
  72. call setline(1, range(1, 4))
  73. 2,3<<
  74. call assert_equal(['1',
  75. \ ' 2',
  76. \ ' 3',
  77. \ '4'], getline(1, '$'))
  78. 3,4>
  79. call assert_equal(['1',
  80. \ ' 2',
  81. \ ' 3',
  82. \ '4'], getline(1, '$'))
  83. bw!
  84. set rightleft& shiftwidth&
  85. endfunc
  86. func Test_ex_shift_errors()
  87. call assert_fails('><', 'E488:')
  88. call assert_fails('<>', 'E488:')
  89. call assert_fails('>!', 'E477:')
  90. call assert_fails('<!', 'E477:')
  91. call assert_fails('2,1>', 'E493:')
  92. call assert_fails('2,1<', 'E493:')
  93. endfunc
  94. " Test inserting a backspace at the start of a line.
  95. "
  96. " This is to verify the proper behavior of tabstop_start() as called from
  97. " ins_bs().
  98. "
  99. func Test_shift_ins_bs()
  100. set backspace=indent,start
  101. set softtabstop=11
  102. call setline(1, repeat(" ", 33) . "word")
  103. exe "norm! I\<BS>"
  104. call assert_equal(repeat(" ", 22) . "word", getline(1))
  105. call setline(1, repeat(" ", 23) . "word")
  106. exe "norm! I\<BS>"
  107. call assert_equal(repeat(" ", 22) . "word", getline(1))
  108. exe "norm! I\<BS>"
  109. call assert_equal(repeat(" ", 11) . "word", getline(1))
  110. set backspace& softtabstop&
  111. bw!
  112. endfunc
  113. " Test inserting a backspace at the start of a line, with 'varsofttabstop'.
  114. "
  115. func Test_shift_ins_bs_vartabs()
  116. CheckFeature vartabs
  117. set backspace=indent,start
  118. set varsofttabstop=13,11,7
  119. call setline(1, repeat(" ", 44) . "word")
  120. exe "norm! I\<BS>"
  121. call assert_equal(repeat(" ", 38) . "word", getline(1))
  122. call setline(1, repeat(" ", 39) . "word")
  123. exe "norm! I\<BS>"
  124. call assert_equal(repeat(" ", 38) . "word", getline(1))
  125. exe "norm! I\<BS>"
  126. call assert_equal(repeat(" ", 31) . "word", getline(1))
  127. exe "norm! I\<BS>"
  128. call assert_equal(repeat(" ", 24) . "word", getline(1))
  129. exe "norm! I\<BS>"
  130. call assert_equal(repeat(" ", 13) . "word", getline(1))
  131. exe "norm! I\<BS>"
  132. call assert_equal( "word", getline(1))
  133. exe "norm! I\<BS>"
  134. call assert_equal( "word", getline(1))
  135. set backspace& varsofttabstop&
  136. bw!
  137. endfunc
  138. " Test the >> and << normal-mode commands.
  139. "
  140. func Test_shift_norm()
  141. set expandtab " Don't want to worry about tabs vs. spaces in
  142. " results.
  143. set shiftwidth=5
  144. set tabstop=7
  145. call setline(1, " word")
  146. " Shift by 'shiftwidth' right and left.
  147. norm! >>
  148. call assert_equal(repeat(" ", 7) . "word", getline(1))
  149. norm! >>
  150. call assert_equal(repeat(" ", 12) . "word", getline(1))
  151. norm! >>
  152. call assert_equal(repeat(" ", 17) . "word", getline(1))
  153. norm! <<
  154. call assert_equal(repeat(" ", 12) . "word", getline(1))
  155. norm! <<
  156. call assert_equal(repeat(" ", 7) . "word", getline(1))
  157. norm! <<
  158. call assert_equal(repeat(" ", 2) . "word", getline(1))
  159. norm! <<
  160. call assert_equal(repeat(" ", 0) . "word", getline(1))
  161. " Shift by 'tabstop' right and left.
  162. set shiftwidth=0
  163. call setline(1, " word")
  164. norm! >>
  165. call assert_equal(repeat(" ", 9) . "word", getline(1))
  166. norm! >>
  167. call assert_equal(repeat(" ", 16) . "word", getline(1))
  168. norm! >>
  169. call assert_equal(repeat(" ", 23) . "word", getline(1))
  170. norm! <<
  171. call assert_equal(repeat(" ", 16) . "word", getline(1))
  172. norm! <<
  173. call assert_equal(repeat(" ", 9) . "word", getline(1))
  174. norm! <<
  175. call assert_equal(repeat(" ", 2) . "word", getline(1))
  176. norm! <<
  177. call assert_equal(repeat(" ", 0) . "word", getline(1))
  178. set expandtab& shiftwidth& tabstop&
  179. bw!
  180. endfunc
  181. " Test the >> and << normal-mode commands, with 'vartabstop'.
  182. "
  183. func Test_shift_norm_vartabs()
  184. CheckFeature vartabs
  185. set expandtab " Don't want to worry about tabs vs. spaces in
  186. " results.
  187. set shiftwidth=0
  188. set vartabstop=19,17,11
  189. " Shift by 'vartabstop' right and left.
  190. call setline(1, " word")
  191. norm! >>
  192. call assert_equal(repeat(" ", 21) . "word", getline(1))
  193. norm! >>
  194. call assert_equal(repeat(" ", 38) . "word", getline(1))
  195. norm! >>
  196. call assert_equal(repeat(" ", 49) . "word", getline(1))
  197. norm! >>
  198. call assert_equal(repeat(" ", 60) . "word", getline(1))
  199. norm! <<
  200. call assert_equal(repeat(" ", 49) . "word", getline(1))
  201. norm! <<
  202. call assert_equal(repeat(" ", 38) . "word", getline(1))
  203. norm! <<
  204. call assert_equal(repeat(" ", 21) . "word", getline(1))
  205. norm! <<
  206. call assert_equal(repeat(" ", 2) . "word", getline(1))
  207. norm! <<
  208. call assert_equal(repeat(" ", 0) . "word", getline(1))
  209. set expandtab& shiftwidth& vartabstop&
  210. bw!
  211. endfunc
  212. " Test the >> and << normal-mode commands with 'shiftround'.
  213. "
  214. func Test_shift_norm_round()
  215. set expandtab " Don't want to worry about tabs vs. spaces in
  216. " results.
  217. set shiftround
  218. set shiftwidth=5
  219. set tabstop=7
  220. call setline(1, "word")
  221. " Shift by 'shiftwidth' right and left.
  222. exe "norm! I "
  223. norm! >>
  224. call assert_equal(repeat(" ", 5) . "word", getline(1))
  225. exe "norm! I "
  226. norm! >>
  227. call assert_equal(repeat(" ", 10) . "word", getline(1))
  228. exe "norm! I "
  229. norm! >>
  230. call assert_equal(repeat(" ", 15) . "word", getline(1))
  231. norm! >>
  232. call assert_equal(repeat(" ", 20) . "word", getline(1))
  233. norm! >>
  234. call assert_equal(repeat(" ", 25) . "word", getline(1))
  235. norm! <<
  236. call assert_equal(repeat(" ", 20) . "word", getline(1))
  237. norm! <<
  238. call assert_equal(repeat(" ", 15) . "word", getline(1))
  239. norm! <<
  240. call assert_equal(repeat(" ", 10) . "word", getline(1))
  241. exe "norm! I "
  242. norm! <<
  243. call assert_equal(repeat(" ", 10) . "word", getline(1))
  244. call setline(1, repeat(" ", 7) . "word")
  245. norm! <<
  246. call assert_equal(repeat(" ", 5) . "word", getline(1))
  247. norm! <<
  248. call assert_equal(repeat(" ", 0) . "word", getline(1))
  249. norm! <<
  250. call assert_equal(repeat(" ", 0) . "word", getline(1))
  251. call setline(1, repeat(" ", 2) . "word")
  252. norm! <<
  253. call assert_equal(repeat(" ", 0) . "word", getline(1))
  254. " Shift by 'tabstop' right and left.
  255. set shiftwidth=0
  256. call setline(1, "word")
  257. exe "norm! I "
  258. norm! >>
  259. call assert_equal(repeat(" ", 7) . "word", getline(1))
  260. exe "norm! I "
  261. norm! >>
  262. call assert_equal(repeat(" ", 14) . "word", getline(1))
  263. exe "norm! I "
  264. norm! >>
  265. call assert_equal(repeat(" ", 21) . "word", getline(1))
  266. norm! >>
  267. call assert_equal(repeat(" ", 28) . "word", getline(1))
  268. norm! >>
  269. call assert_equal(repeat(" ", 35) . "word", getline(1))
  270. norm! <<
  271. call assert_equal(repeat(" ", 28) . "word", getline(1))
  272. norm! <<
  273. call assert_equal(repeat(" ", 21) . "word", getline(1))
  274. norm! <<
  275. call assert_equal(repeat(" ", 14) . "word", getline(1))
  276. exe "norm! I "
  277. norm! <<
  278. call assert_equal(repeat(" ", 14) . "word", getline(1))
  279. call setline(1, repeat(" ", 9) . "word")
  280. norm! <<
  281. call assert_equal(repeat(" ", 7) . "word", getline(1))
  282. norm! <<
  283. call assert_equal(repeat(" ", 0) . "word", getline(1))
  284. norm! <<
  285. call assert_equal(repeat(" ", 0) . "word", getline(1))
  286. call setline(1, repeat(" ", 2) . "word")
  287. norm! <<
  288. call assert_equal(repeat(" ", 0) . "word", getline(1))
  289. set expandtab& shiftround& shiftwidth& tabstop&
  290. bw!
  291. endfunc
  292. " Test the >> and << normal-mode commands with 'shiftround' and 'vartabstop'.
  293. "
  294. func Test_shift_norm_round_vartabs()
  295. CheckFeature vartabs
  296. set expandtab " Don't want to worry about tabs vs. spaces in
  297. " results.
  298. set shiftround
  299. set shiftwidth=0
  300. set vartabstop=19,17,11
  301. " Shift by 'vartabstop' right and left.
  302. call setline(1, "word")
  303. exe "norm! I "
  304. norm! >>
  305. call assert_equal(repeat(" ", 19) . "word", getline(1))
  306. exe "norm! I "
  307. norm! >>
  308. call assert_equal(repeat(" ", 36) . "word", getline(1))
  309. exe "norm! I "
  310. norm! >>
  311. call assert_equal(repeat(" ", 47) . "word", getline(1))
  312. exe "norm! I "
  313. norm! >>
  314. call assert_equal(repeat(" ", 58) . "word", getline(1))
  315. exe "norm! I "
  316. norm! <<
  317. call assert_equal(repeat(" ", 58) . "word", getline(1))
  318. norm! <<
  319. call assert_equal(repeat(" ", 47) . "word", getline(1))
  320. norm! <<
  321. call assert_equal(repeat(" ", 36) . "word", getline(1))
  322. norm! <<
  323. call assert_equal(repeat(" ", 19) . "word", getline(1))
  324. exe "norm! I "
  325. norm! <<
  326. call assert_equal(repeat(" ", 19) . "word", getline(1))
  327. norm! <<
  328. call assert_equal(repeat(" ", 0) . "word", getline(1))
  329. exe "norm! I "
  330. call assert_equal(repeat(" ", 2) . "word", getline(1))
  331. norm! <<
  332. call assert_equal(repeat(" ", 0) . "word", getline(1))
  333. norm! <<
  334. call assert_equal(repeat(" ", 0) . "word", getline(1))
  335. set expandtab& shiftround& shiftwidth& vartabstop&
  336. bw!
  337. endfunc
  338. " Test the V> and V< visual-mode commands.
  339. "
  340. " See ":help v_<" and ":help v_>". See also the last paragraph of "3. Simple
  341. " changes", ":help simple-change", immediately above "4. Complex changes",
  342. " ":help complex-change".
  343. "
  344. func Test_shift_vis()
  345. set expandtab " Don't want to worry about tabs vs. spaces in
  346. " results.
  347. set shiftwidth=5
  348. set tabstop=7
  349. call setline(1, " word")
  350. " Shift by 'shiftwidth' right and left.
  351. norm! V>
  352. call assert_equal(repeat(" ", 7) . "word", getline(1))
  353. norm! V2>
  354. call assert_equal(repeat(" ", 17) . "word", getline(1))
  355. norm! V3>
  356. call assert_equal(repeat(" ", 32) . "word", getline(1))
  357. norm! V<
  358. call assert_equal(repeat(" ", 27) . "word", getline(1))
  359. norm! V2<
  360. call assert_equal(repeat(" ", 17) . "word", getline(1))
  361. norm! V3<
  362. call assert_equal(repeat(" ", 2) . "word", getline(1))
  363. norm! V<
  364. call assert_equal(repeat(" ", 0) . "word", getline(1))
  365. norm! V3<
  366. call assert_equal(repeat(" ", 0) . "word", getline(1))
  367. " Shift by 'tabstop' right and left.
  368. set shiftwidth=0
  369. call setline(1, " word")
  370. norm! V>
  371. call assert_equal(repeat(" ", 9) . "word", getline(1))
  372. norm! V2>
  373. call assert_equal(repeat(" ", 23) . "word", getline(1))
  374. norm! V3>
  375. call assert_equal(repeat(" ", 44) . "word", getline(1))
  376. norm! V<
  377. call assert_equal(repeat(" ", 37) . "word", getline(1))
  378. norm! V2<
  379. call assert_equal(repeat(" ", 23) . "word", getline(1))
  380. norm! V3<
  381. call assert_equal(repeat(" ", 2) . "word", getline(1))
  382. norm! V<
  383. call assert_equal(repeat(" ", 0) . "word", getline(1))
  384. norm! V3<
  385. call assert_equal(repeat(" ", 0) . "word", getline(1))
  386. set expandtab& shiftwidth& tabstop&
  387. bw!
  388. endfunc
  389. " Test the V> and V< visual-mode commands, with 'vartabstop'.
  390. "
  391. " See ":help v_<" and ":help v_>". See also the last paragraph of "3. Simple
  392. " changes", ":help simple-change", immediately above "4. Complex changes",
  393. " ":help complex-change".
  394. "
  395. func Test_shift_vis_vartabs()
  396. CheckFeature vartabs
  397. set expandtab " Don't want to worry about tabs vs. spaces in
  398. " results.
  399. set shiftwidth=0
  400. set vartabstop=19,17,11
  401. " Shift by 'vartabstop' right and left.
  402. call setline(1, " word")
  403. norm! V>
  404. call assert_equal(repeat(" ", 21) . "word", getline(1))
  405. norm! V2>
  406. call assert_equal(repeat(" ", 49) . "word", getline(1))
  407. norm! V3>
  408. call assert_equal(repeat(" ", 82) . "word", getline(1))
  409. norm! V<
  410. call assert_equal(repeat(" ", 71) . "word", getline(1))
  411. norm! V2<
  412. call assert_equal(repeat(" ", 49) . "word", getline(1))
  413. norm! V3<
  414. call assert_equal(repeat(" ", 2) . "word", getline(1))
  415. norm! V<
  416. call assert_equal(repeat(" ", 0) . "word", getline(1))
  417. norm! V3<
  418. call assert_equal(repeat(" ", 0) . "word", getline(1))
  419. set expandtab& shiftwidth& vartabstop&
  420. bw!
  421. endfunc
  422. " Test the V> and V< visual-mode commands with 'shiftround'.
  423. "
  424. func Test_shift_vis_round()
  425. set expandtab " Don't want to worry about tabs vs. spaces in
  426. " results.
  427. set shiftround
  428. set shiftwidth=5
  429. set tabstop=7
  430. call setline(1, "word")
  431. " Shift by 'shiftwidth' right and left.
  432. exe "norm! I "
  433. norm! V>
  434. call assert_equal(repeat(" ", 5) . "word", getline(1))
  435. exe "norm! I "
  436. norm! V2>
  437. call assert_equal(repeat(" ", 15) . "word", getline(1))
  438. exe "norm! I "
  439. norm! V3>
  440. call assert_equal(repeat(" ", 30) . "word", getline(1))
  441. exe "norm! I "
  442. norm! V2<
  443. call assert_equal(repeat(" ", 25) . "word", getline(1))
  444. norm! V3<
  445. call assert_equal(repeat(" ", 10) . "word", getline(1))
  446. norm! V<
  447. call assert_equal(repeat(" ", 5) . "word", getline(1))
  448. norm! V<
  449. call assert_equal(repeat(" ", 0) . "word", getline(1))
  450. norm! V3<
  451. call assert_equal(repeat(" ", 0) . "word", getline(1))
  452. " Shift by 'tabstop' right and left.
  453. set shiftwidth=0
  454. call setline(1, "word")
  455. exe "norm! I "
  456. norm! V>
  457. call assert_equal(repeat(" ", 7) . "word", getline(1))
  458. exe "norm! I "
  459. norm! V2>
  460. call assert_equal(repeat(" ", 21) . "word", getline(1))
  461. exe "norm! I "
  462. norm! V3>
  463. call assert_equal(repeat(" ", 42) . "word", getline(1))
  464. exe "norm! I "
  465. norm! V<
  466. call assert_equal(repeat(" ", 42) . "word", getline(1))
  467. norm! V<
  468. call assert_equal(repeat(" ", 35) . "word", getline(1))
  469. norm! V2<
  470. call assert_equal(repeat(" ", 21) . "word", getline(1))
  471. norm! V3<
  472. call assert_equal(repeat(" ", 0) . "word", getline(1))
  473. norm! V<
  474. call assert_equal(repeat(" ", 0) . "word", getline(1))
  475. norm! V3<
  476. call assert_equal(repeat(" ", 0) . "word", getline(1))
  477. call setline(1, " word")
  478. norm! V<
  479. call assert_equal(repeat(" ", 0) . "word", getline(1))
  480. set expandtab& shiftround& shiftwidth& tabstop&
  481. bw!
  482. endfunc
  483. " Test the V> and V< visual-mode commands with 'shiftround' and 'vartabstop'.
  484. "
  485. func Test_shift_vis_round_vartabs()
  486. CheckFeature vartabs
  487. set expandtab " Don't want to worry about tabs vs. spaces in
  488. " results.
  489. set shiftround
  490. set shiftwidth=0
  491. set vartabstop=19,17,11
  492. " Shift by 'vartabstop' right and left.
  493. call setline(1, "word")
  494. exe "norm! I "
  495. norm! V>
  496. call assert_equal(repeat(" ", 19) . "word", getline(1))
  497. exe "norm! I "
  498. norm! V3>
  499. call assert_equal(repeat(" ", 58) . "word", getline(1))
  500. exe "norm! I "
  501. norm! V2<
  502. call assert_equal(repeat(" ", 47) . "word", getline(1))
  503. exe "norm! I "
  504. norm! V3<
  505. call assert_equal(repeat(" ", 19) . "word", getline(1))
  506. exe "norm! I "
  507. norm! V3<
  508. call assert_equal(repeat(" ", 0) . "word", getline(1))
  509. exe "norm! I "
  510. norm! V<
  511. call assert_equal(repeat(" ", 0) . "word", getline(1))
  512. set expandtab& shiftround& shiftwidth& vartabstop&
  513. bw!
  514. endfunc
  515. " Test the :> and :< ex-mode commands.
  516. "
  517. func Test_shift_ex()
  518. set expandtab " Don't want to worry about tabs vs. spaces in
  519. " results.
  520. set shiftwidth=5
  521. set tabstop=7
  522. call setline(1, " word")
  523. " Shift by 'shiftwidth' right and left.
  524. >
  525. call assert_equal(repeat(" ", 7) . "word", getline(1))
  526. >>
  527. call assert_equal(repeat(" ", 17) . "word", getline(1))
  528. >>>
  529. call assert_equal(repeat(" ", 32) . "word", getline(1))
  530. <<<<
  531. call assert_equal(repeat(" ", 12) . "word", getline(1))
  532. <
  533. call assert_equal(repeat(" ", 7) . "word", getline(1))
  534. <
  535. call assert_equal(repeat(" ", 2) . "word", getline(1))
  536. <
  537. call assert_equal(repeat(" ", 0) . "word", getline(1))
  538. " Shift by 'tabstop' right and left.
  539. set shiftwidth=0
  540. call setline(1, " word")
  541. >
  542. call assert_equal(repeat(" ", 9) . "word", getline(1))
  543. >>
  544. call assert_equal(repeat(" ", 23) . "word", getline(1))
  545. >>>
  546. call assert_equal(repeat(" ", 44) . "word", getline(1))
  547. <<<<
  548. call assert_equal(repeat(" ", 16) . "word", getline(1))
  549. <<
  550. call assert_equal(repeat(" ", 2) . "word", getline(1))
  551. <
  552. call assert_equal(repeat(" ", 0) . "word", getline(1))
  553. set expandtab& shiftwidth& tabstop&
  554. bw!
  555. endfunc
  556. " Test the :> and :< ex-mode commands, with vartabstop.
  557. "
  558. func Test_shift_ex_vartabs()
  559. CheckFeature vartabs
  560. set expandtab " Don't want to worry about tabs vs. spaces in
  561. " results.
  562. set shiftwidth=0
  563. set vartabstop=19,17,11
  564. " Shift by 'vartabstop' right and left.
  565. call setline(1, " word")
  566. >
  567. call assert_equal(repeat(" ", 21) . "word", getline(1))
  568. >>
  569. call assert_equal(repeat(" ", 49) . "word", getline(1))
  570. >>>
  571. call assert_equal(repeat(" ", 82) . "word", getline(1))
  572. <<<<
  573. call assert_equal(repeat(" ", 38) . "word", getline(1))
  574. <<
  575. call assert_equal(repeat(" ", 2) . "word", getline(1))
  576. <
  577. call assert_equal(repeat(" ", 0) . "word", getline(1))
  578. set expandtab& shiftwidth& vartabstop&
  579. bw!
  580. endfunc
  581. " Test the :> and :< ex-mode commands with 'shiftround'.
  582. "
  583. func Test_shift_ex_round()
  584. set expandtab " Don't want to worry about tabs vs. spaces in
  585. " results.
  586. set shiftround
  587. set shiftwidth=5
  588. set tabstop=7
  589. call setline(1, "word")
  590. " Shift by 'shiftwidth' right and left.
  591. exe "norm! I "
  592. >
  593. call assert_equal(repeat(" ", 5) . "word", getline(1))
  594. exe "norm! I "
  595. >>
  596. call assert_equal(repeat(" ", 15) . "word", getline(1))
  597. exe "norm! I "
  598. >>>
  599. call assert_equal(repeat(" ", 30) . "word", getline(1))
  600. exe "norm! I "
  601. <<<<
  602. call assert_equal(repeat(" ", 15) . "word", getline(1))
  603. exe "norm! I "
  604. <<
  605. call assert_equal(repeat(" ", 10) . "word", getline(1))
  606. <<
  607. call assert_equal(repeat(" ", 0) . "word", getline(1))
  608. >>
  609. <<<
  610. call assert_equal(repeat(" ", 0) . "word", getline(1))
  611. " Shift by 'tabstop' right and left.
  612. set shiftwidth=0
  613. call setline(1, "word")
  614. exe "norm! I "
  615. >
  616. call assert_equal(repeat(" ", 7) . "word", getline(1))
  617. exe "norm! I "
  618. >>
  619. call assert_equal(repeat(" ", 21) . "word", getline(1))
  620. exe "norm! I "
  621. >>>
  622. call assert_equal(repeat(" ", 42) . "word", getline(1))
  623. exe "norm! I "
  624. <<<<
  625. call assert_equal(repeat(" ", 21) . "word", getline(1))
  626. exe "norm! I "
  627. <<
  628. call assert_equal(repeat(" ", 14) . "word", getline(1))
  629. exe "norm! I "
  630. <<<
  631. call assert_equal(repeat(" ", 0) . "word", getline(1))
  632. >>
  633. <<<
  634. call assert_equal(repeat(" ", 0) . "word", getline(1))
  635. set expandtab& shiftround& shiftwidth& tabstop&
  636. bw!
  637. endfunc
  638. " Test the :> and :< ex-mode commands with 'shiftround' and 'vartabstop'.
  639. "
  640. func Test_shift_ex_round_vartabs()
  641. CheckFeature vartabs
  642. set expandtab " Don't want to worry about tabs vs. spaces in
  643. " results.
  644. set shiftround
  645. set shiftwidth=0
  646. set vartabstop=19,17,11
  647. " Shift by 'vartabstop' right and left.
  648. call setline(1, "word")
  649. exe "norm! I "
  650. >
  651. call assert_equal(repeat(" ", 19) . "word", getline(1))
  652. exe "norm! I "
  653. >>
  654. call assert_equal(repeat(" ", 47) . "word", getline(1))
  655. >>>
  656. call assert_equal(repeat(" ", 80) . "word", getline(1))
  657. <<<<
  658. call assert_equal(repeat(" ", 36) . "word", getline(1))
  659. exe "norm! I "
  660. <<
  661. call assert_equal(repeat(" ", 19) . "word", getline(1))
  662. exe "norm! I "
  663. <<
  664. call assert_equal(repeat(" ", 0) . "word", getline(1))
  665. <
  666. call assert_equal(repeat(" ", 0) . "word", getline(1))
  667. set expandtab& shiftround& shiftwidth& vartabstop&
  668. bw!
  669. endfunc
  670. " Test shifting lines with <C-T> and <C-D>.
  671. "
  672. func Test_shift_ins()
  673. set expandtab " Don't want to worry about tabs vs. spaces in
  674. " results.
  675. set shiftwidth=5
  676. set tabstop=7
  677. " Shift by 'shiftwidth' right and left.
  678. call setline(1, repeat(" ", 7) . "word")
  679. exe "norm! 9|i\<C-T>"
  680. call assert_equal(repeat(" ", 10) . "word", getline(1))
  681. exe "norm! A\<C-T>"
  682. call assert_equal(repeat(" ", 15) . "word", getline(1))
  683. exe "norm! I \<C-T>"
  684. call assert_equal(repeat(" ", 20) . "word", getline(1))
  685. exe "norm! I \<C-D>"
  686. call assert_equal(repeat(" ", 20) . "word", getline(1))
  687. exe "norm! I "
  688. exe "norm! 24|i\<C-D>"
  689. call assert_equal(repeat(" ", 20) . "word", getline(1))
  690. exe "norm! A\<C-D>"
  691. call assert_equal(repeat(" ", 15) . "word", getline(1))
  692. exe "norm! I "
  693. exe "norm! A\<C-D>\<C-D>"
  694. call assert_equal(repeat(" ", 10) . "word", getline(1))
  695. exe "norm! I\<C-D>\<C-D>\<C-D>"
  696. call assert_equal(repeat(" ", 0) . "word", getline(1))
  697. exe "norm! I\<C-D>"
  698. call assert_equal(repeat(" ", 0) . "word", getline(1))
  699. " Shift by 'tabstop' right and left.
  700. set shiftwidth=0
  701. call setline(1, "word")
  702. call setline(1, repeat(" ", 9) . "word")
  703. exe "norm! 11|i\<C-T>"
  704. call assert_equal(repeat(" ", 14) . "word", getline(1))
  705. exe "norm! A\<C-T>"
  706. call assert_equal(repeat(" ", 21) . "word", getline(1))
  707. exe "norm! I \<C-T>"
  708. call assert_equal(repeat(" ", 28) . "word", getline(1))
  709. exe "norm! I \<C-D>"
  710. call assert_equal(repeat(" ", 28) . "word", getline(1))
  711. exe "norm! I "
  712. exe "norm! 32|i\<C-D>"
  713. call assert_equal(repeat(" ", 28) . "word", getline(1))
  714. exe "norm! A\<C-D>"
  715. call assert_equal(repeat(" ", 21) . "word", getline(1))
  716. exe "norm! I "
  717. exe "norm! A\<C-D>\<C-D>"
  718. call assert_equal(repeat(" ", 14) . "word", getline(1))
  719. exe "norm! I\<C-D>\<C-D>\<C-D>"
  720. call assert_equal(repeat(" ", 0) . "word", getline(1))
  721. exe "norm! I\<C-D>"
  722. call assert_equal(repeat(" ", 0) . "word", getline(1))
  723. set expandtab& shiftwidth& tabstop&
  724. bw!
  725. endfunc
  726. " Test shifting lines with <C-T> and <C-D>, with 'vartabstop'.
  727. "
  728. func Test_shift_ins_vartabs()
  729. CheckFeature vartabs
  730. set expandtab " Don't want to worry about tabs vs. spaces in
  731. " results.
  732. set shiftwidth=0
  733. set vartabstop=19,17,11
  734. " Shift by 'vartabstop' right and left.
  735. call setline(1, "word")
  736. call setline(1, repeat(" ", 9) . "word")
  737. exe "norm! 11|i\<C-T>"
  738. call assert_equal(repeat(" ", 19) . "word", getline(1))
  739. exe "norm! A\<C-T>"
  740. call assert_equal(repeat(" ", 36) . "word", getline(1))
  741. exe "norm! I \<C-T>"
  742. call assert_equal(repeat(" ", 47) . "word", getline(1))
  743. exe "norm! I \<C-D>"
  744. call assert_equal(repeat(" ", 47) . "word", getline(1))
  745. exe "norm! I "
  746. exe "norm! 51|i\<C-D>"
  747. call assert_equal(repeat(" ", 47) . "word", getline(1))
  748. exe "norm! A\<C-D>"
  749. call assert_equal(repeat(" ", 36) . "word", getline(1))
  750. exe "norm! I "
  751. exe "norm! A\<C-D>\<C-D>"
  752. call assert_equal(repeat(" ", 19) . "word", getline(1))
  753. exe "norm! I\<C-D>\<C-D>\<C-D>"
  754. call assert_equal(repeat(" ", 0) . "word", getline(1))
  755. exe "norm! I\<C-D>"
  756. call assert_equal(repeat(" ", 0) . "word", getline(1))
  757. set expandtab& shiftwidth& vartabstop&
  758. bw!
  759. endfunc
  760. " vim: shiftwidth=2 sts=2 expandtab