1" Test for gn command 2 3func Test_gn_command() 4 noautocmd 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 12 " simple search match 13 call setline('.', 'foobar') 14 let @/='foobar' 15 exe "norm! gncsearchmatch" 16 call assert_equal('searchmatch', getline('.')) 17 sil! %d _ 18 19 " replace a multi-line match 20 call setline('.', ['', 'one', 'two']) 21 let @/='one\_s*two\_s' 22 exe "norm! gnceins\<CR>zwei" 23 call assert_equal(['','eins','zwei'], getline(1,'$')) 24 sil! %d _ 25 26 " test count argument 27 call setline('.', ['', 'abcdx | abcdx | abcdx']) 28 let @/='[a]bcdx' 29 exe "norm! 2gnd" 30 call assert_equal(['','abcdx | | abcdx'], getline(1,'$')) 31 sil! %d _ 32 33 " join lines 34 call setline('.', ['join ', 'lines']) 35 let @/='$' 36 exe "norm! 0gnd" 37 call assert_equal(['join lines'], getline(1,'$')) 38 sil! %d _ 39 40 " zero-width match 41 call setline('.', ['', 'zero width pattern']) 42 let @/='\>\zs' 43 exe "norm! 0gnd" 44 call assert_equal(['', 'zerowidth pattern'], getline(1,'$')) 45 sil! %d _ 46 47 " delete first and last chars 48 call setline('.', ['delete first and last chars']) 49 let @/='^' 50 exe "norm! 0gnd$" 51 let @/='\zs' 52 exe "norm! gnd" 53 call assert_equal(['elete first and last char'], getline(1,'$')) 54 sil! %d _ 55 56 " using visual mode 57 call setline('.', ['', 'uniquepattern uniquepattern']) 58 exe "norm! /[u]niquepattern/s\<cr>vlgnd" 59 call assert_equal(['', ' uniquepattern'], getline(1,'$')) 60 sil! %d _ 61 62 " backwards search 63 call setline('.', ['my very excellent mother just served us nachos']) 64 let @/='mother' 65 exe "norm! $cgNmongoose" 66 call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$')) 67 sil! %d _ 68 69 " search for single char 70 call setline('.', ['','for (i=0; i<=10; i++)']) 71 let @/='i' 72 exe "norm! cgnj" 73 call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$')) 74 sil! %d _ 75 76 " search hex char 77 call setline('.', ['','Y']) 78 set noignorecase 79 let @/='\%x59' 80 exe "norm! gnd" 81 call assert_equal(['',''], getline(1,'$')) 82 sil! %d _ 83 84 " test repeating gdn 85 call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3']) 86 let @/='Johnny' 87 exe "norm! dgn." 88 call assert_equal(['','1', '', '2', '', '3'], getline(1,'$')) 89 sil! %d _ 90 91 " test repeating gUgn 92 call setline('.', ['', '1', 'Depp', '2', 'Depp', '3']) 93 let @/='Depp' 94 exe "norm! gUgn." 95 call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$')) 96 sil! %d _ 97 98 " test using look-ahead assertions 99 call setline('.', ['a:10', '', 'a:1', '', 'a:20']) 100 let @/='a:0\@!\zs\d\+' 101 exe "norm! 2nygno\<esc>p" 102 call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$')) 103 sil! %d _ 104 105 " test using nowrapscan 106 set nowrapscan 107 call setline(1, 'foo bar baz') 108 exe "norm! /bar/e\<cr>" 109 exe "norm! gnd" 110 call assert_equal(['foo baz'], getline(1,'$')) 111 sil! %d_ 112 113 " search upwards with nowrapscan set 114 call setline('.', ['foo', 'bar', 'foo', 'baz']) 115 set nowrapscan 116 let @/='foo' 117 $ 118 norm! dgN 119 call assert_equal(['foo', 'bar', '', 'baz'], getline(1,'$')) 120 sil! %d_ 121 122 set wrapscan&vim 123endfu 124 125" vim: shiftwidth=2 sts=2 expandtab 126