]> granicus.if.org Git - vim/commitdiff
patch 7.4.2100 v7.4.2100
authorBram Moolenaar <Bram@vim.org>
Sun, 24 Jul 2016 15:33:05 +0000 (17:33 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 24 Jul 2016 15:33:05 +0000 (17:33 +0200)
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)

src/Makefile
src/search.c
src/testdir/Make_all.mak
src/testdir/test53.in
src/testdir/test53.ok
src/testdir/test_gn.vim [new file with mode: 0644]
src/version.c

index 9ca5b1d5067961aa22ff11ee4cb8048d237312eb..001f87a3f19d3734623a0073e0a7444880d8c837 100644 (file)
@@ -2076,6 +2076,7 @@ test_arglist \
        test_filter_map \
        test_fnamemodify \
        test_glob2regpat \
+       test_gn \
        test_goto \
        test_hardcopy \
        test_help_tagjump \
index 5fc6820320973c60d0c490173ca64e7f7c13624c..1f1ba6a3fd3b6d5e654975bf9d6f0fa5c610d114 100644 (file)
@@ -4719,7 +4719,7 @@ current_search(
 }
 
 /*
- * Check if the pattern is one character or zero-width.
+ * Check if the pattern is one character long or zero-width.
  * If move is TRUE, check from the beginning of the buffer, else from the
  * current cursor position.
  * Returns TRUE, FALSE or -1 for failure.
@@ -4734,10 +4734,15 @@ is_one_char(char_u *pattern, int move)
     int                save_called_emsg = called_emsg;
     int                flag = 0;
 
+    if (pattern == NULL)
+       pattern = spats[last_idx].pat;
+
     if (search_regcomp(pattern, RE_SEARCH, RE_SEARCH,
                                              SEARCH_KEEP, &regmatch) == FAIL)
        return -1;
 
+    /* init startcol correctly */
+    regmatch.startpos[0].col = -1;
     /* move to match */
     if (move)
        clearpos(&pos)
@@ -4748,22 +4753,30 @@ is_one_char(char_u *pattern, int move)
        flag = SEARCH_START;
     }
 
-    if (searchit(curwin, curbuf, &pos, FORWARD, spats[last_idx].pat, 1,
+    if (searchit(curwin, curbuf, &pos, FORWARD, pattern, 1,
                              SEARCH_KEEP + flag, RE_SEARCH, 0, NULL) != FAIL)
     {
        /* Zero-width pattern should match somewhere, then we can check if
         * start and end are in the same position. */
        called_emsg = FALSE;
-       nmatched = vim_regexec_multi(&regmatch, curwin, curbuf,
-                                                 pos.lnum, (colnr_T)0, NULL);
+       do
+       {
+           regmatch.startpos[0].col++;
+           nmatched = vim_regexec_multi(&regmatch, curwin, curbuf,
+                                           pos.lnum, regmatch.startpos[0].col, NULL);
+           if (!nmatched)
+               break;
+       } while (regmatch.startpos[0].col < pos.col);
 
        if (!called_emsg)
+       {
            result = (nmatched != 0
                && regmatch.startpos[0].lnum == regmatch.endpos[0].lnum
                && regmatch.startpos[0].col == regmatch.endpos[0].col);
-
-       if (!result && inc(&pos) >= 0 && pos.col == regmatch.endpos[0].col)
-           result = TRUE;
+           /* one char width */
+           if (!result && inc(&pos) >= 0 && pos.col == regmatch.endpos[0].col)
+               result = TRUE;
+       }
     }
 
     called_emsg |= save_called_emsg;
index 4e4f43b026203e2ea8dee2bf0b8c5cce9880a825..193679810f6a91a53573d48ff03a9450b91759bf 100644 (file)
@@ -171,6 +171,7 @@ NEW_TESTS = test_arglist.res \
            test_cscope.res \
            test_digraph.res \
            test_farsi.res \
+           test_gn.res \
            test_hardcopy.res \
            test_history.res \
            test_increment.res \
index 7c35b2e8537e1e61170a2549a1dbfad59b9b957a..b5f97f2821209eed52f35ab8ee6db68f06d82d06 100644 (file)
@@ -4,8 +4,6 @@ Note that the end-of-line moves the cursor to the next test line.
 
 Also test match() and matchstr()
 
-Also test the gn command and repeating it.
-
 STARTTEST
 :so small.vim
 /^start:/
@@ -53,35 +51,6 @@ dit
 :put =match('abc', '\zs', 2, 1) " 2
 :put =match('abc', '\zs', 3, 1) " 3
 :put =match('abc', '\zs', 4, 1) " -1
-/^foobar
-gncsearchmatch\e/one\_s*two\_s
-:1
-gnd
-/[a]bcdx
-:1
-2gnd/join
-/$
-0gnd
-/\>\zs
-0gnd/^
-gnd$h/\zs
-gnd/[u]niquepattern/s
-vlgnd
-/mother
-:set selection=exclusive
-$cgNmongoose\e/i
-cgnj\e
-:" Make sure there is no other match y uppercase.
-/\16x59
-gggnd
-:" test repeating dgn
-/^Johnny
-ggdgn.
-:" test repeating gUgn
-/^Depp
-gggUgn.
-gg/a:0\@!\zs\d\+
-nygno\ep
 :/^start:/,/^end:/wq! test.out
 ENDTEST
 
@@ -103,32 +72,4 @@ innertext object
 </b>
 </begin>
 SEARCH:
-foobar
-one
-two
-abcdx | abcdx | abcdx
-join 
-lines
-zero width pattern
-delete first and last chars
-uniquepattern uniquepattern
-my very excellent mother just served us nachos
-for (i=0; i<=10; i++)
-a:10
-
-a:1
-
-a:20
-Y
-text
-Y
---1
-Johnny
---2
-Johnny
---3
-Depp
---4
-Depp
---5
 end:
index 05206972a49cd46c9a13b298cb9f2f9378cc8284..d57d86bbb063609c2bc3feb77a5ae3ab78376c2f 100644 (file)
@@ -42,30 +42,4 @@ a
 3
 -1
 SEARCH:
-searchmatch
-abcdx |  | abcdx
-join lines
-zerowidth pattern
-elete first and last char
- uniquepattern
-my very excellent mongoose just served us nachos
-for (j=0; i<=10; i++)
-a:10
-
-a:1
-1
-
-a:20
-
-text
-Y
---1
-
---2
-
---3
-DEPP
---4
-DEPP
---5
 end:
diff --git a/src/testdir/test_gn.vim b/src/testdir/test_gn.vim
new file mode 100644 (file)
index 0000000..3eca99b
--- /dev/null
@@ -0,0 +1,93 @@
+" Test for gn command
+
+func Test_gn_command()
+  noa new
+  " replace a single char by itsself quoted:
+  call setline('.', 'abc x def x ghi x jkl')
+  let @/='x'
+  exe "norm! cgn'x'\<esc>.."
+  call assert_equal("abc 'x' def 'x' ghi 'x' jkl", getline('.'))
+  sil! %d_
+  " simple search match
+  call setline('.', 'foobar')
+  let @/='foobar'
+  exe "norm! gncsearchmatch"
+  call assert_equal('searchmatch', getline('.'))
+  sil! %d _
+  " replace a multi-line match
+  call setline('.', ['', 'one', 'two'])
+  let @/='one\_s*two\_s'
+  exe "norm! gnceins\<CR>zwei"
+  call assert_equal(['','eins','zwei'], getline(1,'$'))
+  sil! %d _
+  " test count argument
+  call setline('.', ['', 'abcdx | abcdx | abcdx'])
+  let @/='[a]bcdx'
+  exe "norm! 2gnd"
+  call assert_equal(['','abcdx |  | abcdx'], getline(1,'$'))
+  sil! %d _
+  " join lines
+  call setline('.', ['join ', 'lines'])
+  let @/='$'
+  exe "norm! 0gnd"
+  call assert_equal(['join lines'], getline(1,'$'))
+  sil! %d _
+  " zero-width match
+  call setline('.', ['', 'zero width pattern'])
+  let @/='\>\zs'
+  exe "norm! 0gnd"
+  call assert_equal(['', 'zerowidth pattern'], getline(1,'$'))
+  sil! %d _
+  " delete first and last chars
+  call setline('.', ['delete first and last chars'])
+  let @/='^'
+  exe "norm! 0gnd$"
+  let @/='\zs'
+  exe "norm! gnd"
+  call assert_equal(['elete first and last char'], getline(1,'$'))
+  sil! %d _
+  " using visual mode
+  call setline('.', ['', 'uniquepattern uniquepattern'])
+  exe "norm! /[u]niquepattern/s\<cr>vlgnd"
+  call assert_equal(['', ' uniquepattern'], getline(1,'$'))
+  sil! %d _
+  " backwards search
+  call setline('.', ['my very excellent mother just served us nachos'])
+  let @/='mother'
+  exe "norm! $cgNmongoose"
+  call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$'))
+  sil! %d _
+  " search for single char
+  call setline('.', ['','for (i=0; i<=10; i++)'])
+  let @/='i'
+  exe "norm! cgnj"
+  call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$'))
+  sil! %d _
+  " search hex char
+  call setline('.', ['','Y'])
+  set noignorecase
+  let @/='\%x59'
+  exe "norm! gnd"
+  call assert_equal(['',''], getline(1,'$'))
+  sil! %d _
+  " test repeating gdn
+  call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3'])
+  let @/='Johnny'
+  exe "norm! dgn."
+  call assert_equal(['','1', '', '2', '', '3'], getline(1,'$'))
+  sil! %d _
+  " test repeating gUgn
+  call setline('.', ['', '1', 'Depp', '2', 'Depp', '3'])
+  let @/='Depp'
+  exe "norm! gUgn."
+  call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$'))
+  sil! %d _
+  " test using look-ahead assertions
+  call setline('.', ['a:10', '', 'a:1', '', 'a:20'])
+  let @/='a:0\@!\zs\d\+'
+  exe "norm! 2nygno\<esc>p"
+  call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$'))
+  sil! %d _
+endfu
+
+" vim: tabstop=2 shiftwidth=0 expandtab
index b15681b6aa14e3d4d6721f2f3f9884b511e98bec..233b6b54bad103e9325c034a47440f1b166a88d2 100644 (file)
@@ -758,6 +758,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2100,
 /**/
     2099,
 /**/