Mercurial > vim
comparison src/testdir/test_gn.vim @ 11488:9473793c7bb5 v8.0.0627
patch 8.0.0627: "gn" selects only one character with 'nowrapscan'
commit https://github.com/vim/vim/commit/add8dce38de65a0c64e8f54d6bdcadb45a8de2cf
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jun 5 19:56:04 2017 +0200
patch 8.0.0627: "gn" selects only one character with 'nowrapscan'
Problem: When 'wrapscan' is off "gn" does not select the whole pattern when
it's the last one in the text. (KeyboardFire)
Solution: Check if the search fails. (Christian Brabandt, closes #1683)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 05 Jun 2017 20:00:04 +0200 |
parents | 3ee84d270ea7 |
children | 6d3584b60170 |
comparison
equal
deleted
inserted
replaced
11487:b3d343436f92 | 11488:9473793c7bb5 |
---|---|
1 " Test for gn command | 1 " Test for gn command |
2 | 2 |
3 func Test_gn_command() | 3 func Test_gn_command() |
4 noa new | 4 set belloff=all |
5 noautocmd new | |
5 " replace a single char by itsself quoted: | 6 " replace a single char by itsself quoted: |
6 call setline('.', 'abc x def x ghi x jkl') | 7 call setline('.', 'abc x def x ghi x jkl') |
7 let @/='x' | 8 let @/='x' |
8 exe "norm! cgn'x'\<esc>.." | 9 exe "norm! cgn'x'\<esc>.." |
9 call assert_equal("abc 'x' def 'x' ghi 'x' jkl", getline('.')) | 10 call assert_equal("abc 'x' def 'x' ghi 'x' jkl", getline('.')) |
10 sil! %d_ | 11 sil! %d_ |
12 | |
11 " simple search match | 13 " simple search match |
12 call setline('.', 'foobar') | 14 call setline('.', 'foobar') |
13 let @/='foobar' | 15 let @/='foobar' |
14 exe "norm! gncsearchmatch" | 16 exe "norm! gncsearchmatch" |
15 call assert_equal('searchmatch', getline('.')) | 17 call assert_equal('searchmatch', getline('.')) |
16 sil! %d _ | 18 sil! %d _ |
19 | |
17 " replace a multi-line match | 20 " replace a multi-line match |
18 call setline('.', ['', 'one', 'two']) | 21 call setline('.', ['', 'one', 'two']) |
19 let @/='one\_s*two\_s' | 22 let @/='one\_s*two\_s' |
20 exe "norm! gnceins\<CR>zwei" | 23 exe "norm! gnceins\<CR>zwei" |
21 call assert_equal(['','eins','zwei'], getline(1,'$')) | 24 call assert_equal(['','eins','zwei'], getline(1,'$')) |
22 sil! %d _ | 25 sil! %d _ |
26 | |
23 " test count argument | 27 " test count argument |
24 call setline('.', ['', 'abcdx | abcdx | abcdx']) | 28 call setline('.', ['', 'abcdx | abcdx | abcdx']) |
25 let @/='[a]bcdx' | 29 let @/='[a]bcdx' |
26 exe "norm! 2gnd" | 30 exe "norm! 2gnd" |
27 call assert_equal(['','abcdx | | abcdx'], getline(1,'$')) | 31 call assert_equal(['','abcdx | | abcdx'], getline(1,'$')) |
28 sil! %d _ | 32 sil! %d _ |
33 | |
29 " join lines | 34 " join lines |
30 call setline('.', ['join ', 'lines']) | 35 call setline('.', ['join ', 'lines']) |
31 let @/='$' | 36 let @/='$' |
32 exe "norm! 0gnd" | 37 exe "norm! 0gnd" |
33 call assert_equal(['join lines'], getline(1,'$')) | 38 call assert_equal(['join lines'], getline(1,'$')) |
34 sil! %d _ | 39 sil! %d _ |
40 | |
35 " zero-width match | 41 " zero-width match |
36 call setline('.', ['', 'zero width pattern']) | 42 call setline('.', ['', 'zero width pattern']) |
37 let @/='\>\zs' | 43 let @/='\>\zs' |
38 exe "norm! 0gnd" | 44 exe "norm! 0gnd" |
39 call assert_equal(['', 'zerowidth pattern'], getline(1,'$')) | 45 call assert_equal(['', 'zerowidth pattern'], getline(1,'$')) |
40 sil! %d _ | 46 sil! %d _ |
47 | |
41 " delete first and last chars | 48 " delete first and last chars |
42 call setline('.', ['delete first and last chars']) | 49 call setline('.', ['delete first and last chars']) |
43 let @/='^' | 50 let @/='^' |
44 exe "norm! 0gnd$" | 51 exe "norm! 0gnd$" |
45 let @/='\zs' | 52 let @/='\zs' |
46 exe "norm! gnd" | 53 exe "norm! gnd" |
47 call assert_equal(['elete first and last char'], getline(1,'$')) | 54 call assert_equal(['elete first and last char'], getline(1,'$')) |
48 sil! %d _ | 55 sil! %d _ |
56 | |
49 " using visual mode | 57 " using visual mode |
50 call setline('.', ['', 'uniquepattern uniquepattern']) | 58 call setline('.', ['', 'uniquepattern uniquepattern']) |
51 exe "norm! /[u]niquepattern/s\<cr>vlgnd" | 59 exe "norm! /[u]niquepattern/s\<cr>vlgnd" |
52 call assert_equal(['', ' uniquepattern'], getline(1,'$')) | 60 call assert_equal(['', ' uniquepattern'], getline(1,'$')) |
53 sil! %d _ | 61 sil! %d _ |
62 | |
54 " backwards search | 63 " backwards search |
55 call setline('.', ['my very excellent mother just served us nachos']) | 64 call setline('.', ['my very excellent mother just served us nachos']) |
56 let @/='mother' | 65 let @/='mother' |
57 exe "norm! $cgNmongoose" | 66 exe "norm! $cgNmongoose" |
58 call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$')) | 67 call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$')) |
59 sil! %d _ | 68 sil! %d _ |
69 | |
60 " search for single char | 70 " search for single char |
61 call setline('.', ['','for (i=0; i<=10; i++)']) | 71 call setline('.', ['','for (i=0; i<=10; i++)']) |
62 let @/='i' | 72 let @/='i' |
63 exe "norm! cgnj" | 73 exe "norm! cgnj" |
64 call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$')) | 74 call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$')) |
65 sil! %d _ | 75 sil! %d _ |
76 | |
66 " search hex char | 77 " search hex char |
67 call setline('.', ['','Y']) | 78 call setline('.', ['','Y']) |
68 set noignorecase | 79 set noignorecase |
69 let @/='\%x59' | 80 let @/='\%x59' |
70 exe "norm! gnd" | 81 exe "norm! gnd" |
71 call assert_equal(['',''], getline(1,'$')) | 82 call assert_equal(['',''], getline(1,'$')) |
72 sil! %d _ | 83 sil! %d _ |
84 | |
73 " test repeating gdn | 85 " test repeating gdn |
74 call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3']) | 86 call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3']) |
75 let @/='Johnny' | 87 let @/='Johnny' |
76 exe "norm! dgn." | 88 exe "norm! dgn." |
77 call assert_equal(['','1', '', '2', '', '3'], getline(1,'$')) | 89 call assert_equal(['','1', '', '2', '', '3'], getline(1,'$')) |
78 sil! %d _ | 90 sil! %d _ |
91 | |
79 " test repeating gUgn | 92 " test repeating gUgn |
80 call setline('.', ['', '1', 'Depp', '2', 'Depp', '3']) | 93 call setline('.', ['', '1', 'Depp', '2', 'Depp', '3']) |
81 let @/='Depp' | 94 let @/='Depp' |
82 exe "norm! gUgn." | 95 exe "norm! gUgn." |
83 call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$')) | 96 call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$')) |
84 sil! %d _ | 97 sil! %d _ |
98 | |
85 " test using look-ahead assertions | 99 " test using look-ahead assertions |
86 call setline('.', ['a:10', '', 'a:1', '', 'a:20']) | 100 call setline('.', ['a:10', '', 'a:1', '', 'a:20']) |
87 let @/='a:0\@!\zs\d\+' | 101 let @/='a:0\@!\zs\d\+' |
88 exe "norm! 2nygno\<esc>p" | 102 exe "norm! 2nygno\<esc>p" |
89 call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$')) | 103 call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$')) |
90 sil! %d _ | 104 sil! %d _ |
105 | |
106 " test using nowrapscan | |
107 set nowrapscan | |
108 call setline(1, 'foo bar baz') | |
109 exe "norm! /bar/e\<cr>" | |
110 exe "norm! gnd" | |
111 call assert_equal(['foo baz'], getline(1,'$')) | |
112 sil! %d_ | |
113 | |
114 set wrapscan&vim | |
115 set belloff&vim | |
91 endfu | 116 endfu |
92 | 117 |
93 " vim: shiftwidth=2 sts=2 expandtab | 118 " vim: shiftwidth=2 sts=2 expandtab |