Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
9646:c9c6aaff0184 | 9647:847518911c0b |
---|---|
1 " Test for gn command | |
2 | |
3 func 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 _ | |
91 endfu | |
92 | |
93 " vim: tabstop=2 shiftwidth=0 expandtab |