annotate src/testdir/test_gn.vim @ 9647:847518911c0b v7.4.2100

commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 24 17:33:05 2016 +0200 patch 7.4.2100 Problem: "cgn" and "dgn" do not work correctly with a single character match and the replacement includes the searched pattern. (John Beckett) Solution: If the match is found in the wrong column try in the next column. Turn the test into new style. (Christian Brabandt)
author Christian Brabandt <cb@256bit.org>
date Sun, 24 Jul 2016 17:45:05 +0200
parents
children 3ee84d270ea7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9647
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for gn command
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 func Test_gn_command()
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 noa new
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 " replace a single char by itsself quoted:
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 call setline('.', 'abc x def x ghi x jkl')
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 let @/='x'
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 exe "norm! cgn'x'\<esc>.."
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 call assert_equal("abc 'x' def 'x' ghi 'x' jkl", getline('.'))
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 sil! %d_
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 " simple search match
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 call setline('.', 'foobar')
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 let @/='foobar'
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 exe "norm! gncsearchmatch"
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 call assert_equal('searchmatch', getline('.'))
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 sil! %d _
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 " replace a multi-line match
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 call setline('.', ['', 'one', 'two'])
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 let @/='one\_s*two\_s'
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 exe "norm! gnceins\<CR>zwei"
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 call assert_equal(['','eins','zwei'], getline(1,'$'))
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 sil! %d _
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 " test count argument
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 call setline('.', ['', 'abcdx | abcdx | abcdx'])
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 let @/='[a]bcdx'
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 exe "norm! 2gnd"
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 call assert_equal(['','abcdx | | abcdx'], getline(1,'$'))
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 sil! %d _
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 " join lines
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 call setline('.', ['join ', 'lines'])
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 let @/='$'
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 exe "norm! 0gnd"
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 call assert_equal(['join lines'], getline(1,'$'))
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 sil! %d _
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 " zero-width match
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 call setline('.', ['', 'zero width pattern'])
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 let @/='\>\zs'
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 exe "norm! 0gnd"
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 call assert_equal(['', 'zerowidth pattern'], getline(1,'$'))
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 sil! %d _
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 " delete first and last chars
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 call setline('.', ['delete first and last chars'])
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 let @/='^'
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 exe "norm! 0gnd$"
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 let @/='\zs'
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 exe "norm! gnd"
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 call assert_equal(['elete first and last char'], getline(1,'$'))
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 sil! %d _
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 " using visual mode
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 call setline('.', ['', 'uniquepattern uniquepattern'])
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 exe "norm! /[u]niquepattern/s\<cr>vlgnd"
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 call assert_equal(['', ' uniquepattern'], getline(1,'$'))
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 sil! %d _
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 " backwards search
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 call setline('.', ['my very excellent mother just served us nachos'])
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 let @/='mother'
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 exe "norm! $cgNmongoose"
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$'))
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 sil! %d _
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 " search for single char
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 call setline('.', ['','for (i=0; i<=10; i++)'])
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 let @/='i'
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 exe "norm! cgnj"
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$'))
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 sil! %d _
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 " search hex char
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 call setline('.', ['','Y'])
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 set noignorecase
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 let @/='\%x59'
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 exe "norm! gnd"
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 call assert_equal(['',''], getline(1,'$'))
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 sil! %d _
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 " test repeating gdn
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3'])
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 let @/='Johnny'
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 exe "norm! dgn."
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 call assert_equal(['','1', '', '2', '', '3'], getline(1,'$'))
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 sil! %d _
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 " test repeating gUgn
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 call setline('.', ['', '1', 'Depp', '2', 'Depp', '3'])
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 let @/='Depp'
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 exe "norm! gUgn."
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$'))
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 sil! %d _
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 " test using look-ahead assertions
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 call setline('.', ['a:10', '', 'a:1', '', 'a:20'])
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 let @/='a:0\@!\zs\d\+'
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 exe "norm! 2nygno\<esc>p"
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$'))
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 sil! %d _
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 endfu
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92
847518911c0b commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 " vim: tabstop=2 shiftwidth=0 expandtab