comparison src/testdir/test_gn.vim @ 14000:96933f0ecbd1 v8.1.0018

patch 8.1.0018: using "gn" may select wrong text when wrapping commit https://github.com/vim/vim/commit/bdb657924d73c98b0ab28411749571e893b699a9 Author: Bram Moolenaar <Bram@vim.org> Date: Tue May 22 17:50:42 2018 +0200 patch 8.1.0018: using "gn" may select wrong text when wrapping Problem: Using "gn" may select wrong text when wrapping. Solution: Avoid wrapping when searching forward. (Christian Brabandt)
author Christian Brabandt <cb@256bit.org>
date Tue, 22 May 2018 18:00:07 +0200
parents 1fad9675d8fd
children db5d2429bda3
comparison
equal deleted inserted replaced
13999:f4d1227b4b20 14000:96933f0ecbd1
2 2
3 func Test_gn_command() 3 func Test_gn_command()
4 noautocmd new 4 noautocmd new
5 " replace a single char by itsself quoted: 5 " replace a single char by itsself quoted:
6 call setline('.', 'abc x def x ghi x jkl') 6 call setline('.', 'abc x def x ghi x jkl')
7 let @/='x' 7 let @/ = 'x'
8 exe "norm! cgn'x'\<esc>.." 8 exe "norm! cgn'x'\<esc>.."
9 call assert_equal("abc 'x' def 'x' ghi 'x' jkl", getline('.')) 9 call assert_equal("abc 'x' def 'x' ghi 'x' jkl", getline('.'))
10 sil! %d_ 10 sil! %d_
11 11
12 " simple search match 12 " simple search match
13 call setline('.', 'foobar') 13 call setline('.', 'foobar')
14 let @/='foobar' 14 let @/ = 'foobar'
15 exe "norm! gncsearchmatch" 15 exe "norm! gncsearchmatch"
16 call assert_equal('searchmatch', getline('.')) 16 call assert_equal('searchmatch', getline('.'))
17 sil! %d _ 17 sil! %d _
18 18
19 " replace a multi-line match 19 " replace a multi-line match
20 call setline('.', ['', 'one', 'two']) 20 call setline('.', ['', 'one', 'two'])
21 let @/='one\_s*two\_s' 21 let @/ = 'one\_s*two\_s'
22 exe "norm! gnceins\<CR>zwei" 22 exe "norm! gnceins\<CR>zwei"
23 call assert_equal(['','eins','zwei'], getline(1,'$')) 23 call assert_equal(['','eins','zwei'], getline(1,'$'))
24 sil! %d _ 24 sil! %d _
25 25
26 " test count argument 26 " test count argument
27 call setline('.', ['', 'abcdx | abcdx | abcdx']) 27 call setline('.', ['', 'abcdx | abcdx | abcdx'])
28 let @/='[a]bcdx' 28 let @/ = '[a]bcdx'
29 exe "norm! 2gnd" 29 exe "norm! 2gnd"
30 call assert_equal(['','abcdx | | abcdx'], getline(1,'$')) 30 call assert_equal(['','abcdx | | abcdx'], getline(1,'$'))
31 sil! %d _ 31 sil! %d _
32 32
33 " join lines 33 " join lines
34 call setline('.', ['join ', 'lines']) 34 call setline('.', ['join ', 'lines'])
35 let @/='$' 35 let @/ = '$'
36 exe "norm! 0gnd" 36 exe "norm! 0gnd"
37 call assert_equal(['join lines'], getline(1,'$')) 37 call assert_equal(['join lines'], getline(1,'$'))
38 sil! %d _ 38 sil! %d _
39 39
40 " zero-width match 40 " zero-width match
41 call setline('.', ['', 'zero width pattern']) 41 call setline('.', ['', 'zero width pattern'])
42 let @/='\>\zs' 42 let @/ = '\>\zs'
43 exe "norm! 0gnd" 43 exe "norm! 0gnd"
44 call assert_equal(['', 'zerowidth pattern'], getline(1,'$')) 44 call assert_equal(['', 'zerowidth pattern'], getline(1,'$'))
45 sil! %d _ 45 sil! %d _
46 46
47 " delete first and last chars 47 " delete first and last chars
48 call setline('.', ['delete first and last chars']) 48 call setline('.', ['delete first and last chars'])
49 let @/='^' 49 let @/ = '^'
50 exe "norm! 0gnd$" 50 exe "norm! 0gnd$"
51 let @/='\zs' 51 let @/ = '\zs'
52 exe "norm! gnd" 52 exe "norm! gnd"
53 call assert_equal(['elete first and last char'], getline(1,'$')) 53 call assert_equal(['elete first and last char'], getline(1,'$'))
54 sil! %d _ 54 sil! %d _
55 55
56 " using visual mode 56 " using visual mode
59 call assert_equal(['', ' uniquepattern'], getline(1,'$')) 59 call assert_equal(['', ' uniquepattern'], getline(1,'$'))
60 sil! %d _ 60 sil! %d _
61 61
62 " backwards search 62 " backwards search
63 call setline('.', ['my very excellent mother just served us nachos']) 63 call setline('.', ['my very excellent mother just served us nachos'])
64 let @/='mother' 64 let @/ = 'mother'
65 exe "norm! $cgNmongoose" 65 exe "norm! $cgNmongoose"
66 call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$')) 66 call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$'))
67 sil! %d _ 67 sil! %d _
68 68
69 " search for single char 69 " search for single char
70 call setline('.', ['','for (i=0; i<=10; i++)']) 70 call setline('.', ['','for (i=0; i<=10; i++)'])
71 let @/='i' 71 let @/ = 'i'
72 exe "norm! cgnj" 72 exe "norm! cgnj"
73 call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$')) 73 call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$'))
74 sil! %d _ 74 sil! %d _
75 75
76 " search hex char 76 " search hex char
77 call setline('.', ['','Y']) 77 call setline('.', ['','Y'])
78 set noignorecase 78 set noignorecase
79 let @/='\%x59' 79 let @/ = '\%x59'
80 exe "norm! gnd" 80 exe "norm! gnd"
81 call assert_equal(['',''], getline(1,'$')) 81 call assert_equal(['',''], getline(1,'$'))
82 sil! %d _ 82 sil! %d _
83 83
84 " test repeating gdn 84 " test repeating gdn
85 call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3']) 85 call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3'])
86 let @/='Johnny' 86 let @/ = 'Johnny'
87 exe "norm! dgn." 87 exe "norm! dgn."
88 call assert_equal(['','1', '', '2', '', '3'], getline(1,'$')) 88 call assert_equal(['','1', '', '2', '', '3'], getline(1,'$'))
89 sil! %d _ 89 sil! %d _
90 90
91 " test repeating gUgn 91 " test repeating gUgn
92 call setline('.', ['', '1', 'Depp', '2', 'Depp', '3']) 92 call setline('.', ['', '1', 'Depp', '2', 'Depp', '3'])
93 let @/='Depp' 93 let @/ = 'Depp'
94 exe "norm! gUgn." 94 exe "norm! gUgn."
95 call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$')) 95 call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$'))
96 sil! %d _ 96 sil! %d _
97 97
98 " test using look-ahead assertions 98 " test using look-ahead assertions
99 call setline('.', ['a:10', '', 'a:1', '', 'a:20']) 99 call setline('.', ['a:10', '', 'a:1', '', 'a:20'])
100 let @/='a:0\@!\zs\d\+' 100 let @/ = 'a:0\@!\zs\d\+'
101 exe "norm! 2nygno\<esc>p" 101 exe "norm! 2nygno\<esc>p"
102 call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$')) 102 call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$'))
103 sil! %d _ 103 sil! %d _
104 104
105 " test using nowrapscan 105 " test using nowrapscan
111 sil! %d_ 111 sil! %d_
112 112
113 " search upwards with nowrapscan set 113 " search upwards with nowrapscan set
114 call setline('.', ['foo', 'bar', 'foo', 'baz']) 114 call setline('.', ['foo', 'bar', 'foo', 'baz'])
115 set nowrapscan 115 set nowrapscan
116 let @/='foo' 116 let @/ = 'foo'
117 $ 117 $
118 norm! dgN 118 norm! dgN
119 call assert_equal(['foo', 'bar', '', 'baz'], getline(1,'$')) 119 call assert_equal(['foo', 'bar', '', 'baz'], getline(1,'$'))
120 sil! %d_
121
122 " search using the \zs atom
123 call setline(1, [' nnoremap', '' , 'nnoremap'])
124 set wrapscan&vim
125 let @/ = '\_s\zsnnoremap'
126 $
127 norm! cgnmatch
128 call assert_equal([' nnoremap', '', 'match'], getline(1,'$'))
120 sil! %d_ 129 sil! %d_
121 130
122 set wrapscan&vim 131 set wrapscan&vim
123 endfu 132 endfu
124 133