1" Test for gn command 2 3func Test_gn_command() 4 noa new 5 " replace a single char by itsself quoted: 6 call setline('.', 'abc x def x ghi x jkl') 7 let @/='x' 8 exe "norm! cgn'x'\<esc>.." 9 call assert_equal("abc 'x' def 'x' ghi 'x' jkl", getline('.')) 10 sil! %d_ 11 " simple search match 12 call setline('.', 'foobar') 13 let @/='foobar' 14 exe "norm! gncsearchmatch" 15 call assert_equal('searchmatch', getline('.')) 16 sil! %d _ 17 " replace a multi-line match 18 call setline('.', ['', 'one', 'two']) 19 let @/='one\_s*two\_s' 20 exe "norm! gnceins\<CR>zwei" 21 call assert_equal(['','eins','zwei'], getline(1,'$')) 22 sil! %d _ 23 " test count argument 24 call setline('.', ['', 'abcdx | abcdx | abcdx']) 25 let @/='[a]bcdx' 26 exe "norm! 2gnd" 27 call assert_equal(['','abcdx | | abcdx'], getline(1,'$')) 28 sil! %d _ 29 " join lines 30 call setline('.', ['join ', 'lines']) 31 let @/='$' 32 exe "norm! 0gnd" 33 call assert_equal(['join lines'], getline(1,'$')) 34 sil! %d _ 35 " zero-width match 36 call setline('.', ['', 'zero width pattern']) 37 let @/='\>\zs' 38 exe "norm! 0gnd" 39 call assert_equal(['', 'zerowidth pattern'], getline(1,'$')) 40 sil! %d _ 41 " delete first and last chars 42 call setline('.', ['delete first and last chars']) 43 let @/='^' 44 exe "norm! 0gnd$" 45 let @/='\zs' 46 exe "norm! gnd" 47 call assert_equal(['elete first and last char'], getline(1,'$')) 48 sil! %d _ 49 " using visual mode 50 call setline('.', ['', 'uniquepattern uniquepattern']) 51 exe "norm! /[u]niquepattern/s\<cr>vlgnd" 52 call assert_equal(['', ' uniquepattern'], getline(1,'$')) 53 sil! %d _ 54 " backwards search 55 call setline('.', ['my very excellent mother just served us nachos']) 56 let @/='mother' 57 exe "norm! $cgNmongoose" 58 call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$')) 59 sil! %d _ 60 " search for single char 61 call setline('.', ['','for (i=0; i<=10; i++)']) 62 let @/='i' 63 exe "norm! cgnj" 64 call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$')) 65 sil! %d _ 66 " search hex char 67 call setline('.', ['','Y']) 68 set noignorecase 69 let @/='\%x59' 70 exe "norm! gnd" 71 call assert_equal(['',''], getline(1,'$')) 72 sil! %d _ 73 " test repeating gdn 74 call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3']) 75 let @/='Johnny' 76 exe "norm! dgn." 77 call assert_equal(['','1', '', '2', '', '3'], getline(1,'$')) 78 sil! %d _ 79 " test repeating gUgn 80 call setline('.', ['', '1', 'Depp', '2', 'Depp', '3']) 81 let @/='Depp' 82 exe "norm! gUgn." 83 call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$')) 84 sil! %d _ 85 " test using look-ahead assertions 86 call setline('.', ['a:10', '', 'a:1', '', 'a:20']) 87 let @/='a:0\@!\zs\d\+' 88 exe "norm! 2nygno\<esc>p" 89 call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$')) 90 sil! %d _ 91endfu 92 93" vim: shiftwidth=2 sts=2 expandtab 94