From 7d2d4b1918fe2a413d5b5618bacfc78ccaae5414 Mon Sep 17 00:00:00 2001 From: Jurica Bradaric Date: Sat, 30 Jan 2016 20:55:38 +0100 Subject: [PATCH 1/7] vim-patch:7.4.771 Problem: Search does not handle multi-byte character at the start position correctly. Solution: Take byte size of character into account. (Yukihiro Nakadaira) https://github.com/vim/vim/commit/5f1e68b7bc241118e5dd8fc781147fdda881ada8 --- src/nvim/search.c | 22 +++++++++++++--------- src/nvim/version.c | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/nvim/search.c b/src/nvim/search.c index d393ee7d02..f2420e282c 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -497,6 +497,7 @@ int searchit( pos_T start_pos; int at_first_line; int extra_col; + int start_char_len; int match_ok; long nmatched; int submatch = 0; @@ -519,16 +520,21 @@ int searchit( // When not accepting a match at the start position set "extra_col" to a // non-zero value. Don't do that when starting at MAXCOL, since MAXCOL + 1 // is zero. - if ((options & SEARCH_START) || pos->col == MAXCOL) { - extra_col = 0; - } else if (dir != BACKWARD && has_mbyte + if (pos->col == MAXCOL) { + start_char_len = 0; + } else if (has_mbyte && pos->lnum >= 1 && pos->lnum <= buf->b_ml.ml_line_count && pos->col < MAXCOL - 2) { // Watch out for the "col" being MAXCOL - 2, used in a closed fold. ptr = ml_get_buf(buf, pos->lnum, FALSE) + pos->col; - extra_col = *ptr == NUL ? 1 : (*mb_ptr2len)(ptr); + start_char_len = *ptr == NUL ? 1 : (*mb_ptr2len)(ptr); } else { - extra_col = 1; + start_char_len = 1; + } + if (dir == FORWARD) { + extra_col = (options & SEARCH_START) ? 0 : start_char_len; + } else { + extra_col = (options & SEARCH_START) ? start_char_len : 0; } start_pos = *pos; /* remember start pos for detecting no match */ @@ -679,15 +685,13 @@ int searchit( || (lnum + regmatch.endpos[0].lnum == start_pos.lnum && (int)regmatch.endpos[0].col - 1 - + extra_col - <= (int)start_pos.col)) + < (int)start_pos.col + extra_col)) : (lnum + regmatch.startpos[0].lnum < start_pos.lnum || (lnum + regmatch.startpos[0].lnum == start_pos.lnum && (int)regmatch.startpos[0].col - + extra_col - <= (int)start_pos.col)))) { + < (int)start_pos.col + extra_col)))) { match_ok = TRUE; matchpos = regmatch.startpos[0]; endpos = regmatch.endpos[0]; diff --git a/src/nvim/version.c b/src/nvim/version.c index 30f104562f..feda3edde0 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -363,7 +363,7 @@ static int included_patches[] = { 774, 773, // 772 NA - // 771, + 771, // 770 NA // 769, // 768, From 02cf813eff2282cdfce9cc9a9b997c1e16e38343 Mon Sep 17 00:00:00 2001 From: Jurica Bradaric Date: Sat, 30 Jan 2016 21:36:33 +0100 Subject: [PATCH 2/7] Add test files for patch 7.4.771. vim-patch:efcabd6892ad89a4585fb77aa94c3b1802b784ab --- test/functional/legacy/search_mbyte_spec.lua | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/functional/legacy/search_mbyte_spec.lua diff --git a/test/functional/legacy/search_mbyte_spec.lua b/test/functional/legacy/search_mbyte_spec.lua new file mode 100644 index 0000000000..58c064161b --- /dev/null +++ b/test/functional/legacy/search_mbyte_spec.lua @@ -0,0 +1,31 @@ +-- Test for search('multi-byte char', 'bce') + +local helpers = require('test.functional.helpers') +local feed, insert, source = helpers.feed, helpers.insert, helpers.source +local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect + +describe('search_mbyte', function() + setup(clear) + + it('is working', function() + insert([=[ + Results: + + Test bce: + A]=]) + + execute('source small.vim') + execute('source mbyte.vim') + execute('set encoding=utf-8') + execute('/^Test bce:/+1') + execute([[$put =search('A', 'bce', line('.'))]]) + + -- Assert buffer contents. + expect([=[ + Results: + + Test bce: + A + 4]=]) + end) +end) From cabf079ae4adb1770322be8da6f89e6d6a284086 Mon Sep 17 00:00:00 2001 From: Jurica Bradaric Date: Mon, 1 Feb 2016 07:34:25 +0100 Subject: [PATCH 3/7] search: Fix linter errors. --- src/nvim/search.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nvim/search.c b/src/nvim/search.c index f2420e282c..379c33438b 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -523,10 +523,10 @@ int searchit( if (pos->col == MAXCOL) { start_char_len = 0; } else if (has_mbyte - && pos->lnum >= 1 && pos->lnum <= buf->b_ml.ml_line_count - && pos->col < MAXCOL - 2) { + && pos->lnum >= 1 && pos->lnum <= buf->b_ml.ml_line_count + && pos->col < MAXCOL - 2) { // Watch out for the "col" being MAXCOL - 2, used in a closed fold. - ptr = ml_get_buf(buf, pos->lnum, FALSE) + pos->col; + ptr = ml_get_buf(buf, pos->lnum, false) + pos->col; start_char_len = *ptr == NUL ? 1 : (*mb_ptr2len)(ptr); } else { start_char_len = 1; @@ -692,7 +692,7 @@ int searchit( == start_pos.lnum && (int)regmatch.startpos[0].col < (int)start_pos.col + extra_col)))) { - match_ok = TRUE; + match_ok = true; matchpos = regmatch.startpos[0]; endpos = regmatch.endpos[0]; submatch = first_submatch(®match); From 696adeb0f652e32d5865e606117c3408ead6c97c Mon Sep 17 00:00:00 2001 From: Jurica Bradaric Date: Mon, 1 Feb 2016 08:52:24 +0100 Subject: [PATCH 4/7] Use before_each instead of setup in the test. --- test/functional/legacy/search_mbyte_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/legacy/search_mbyte_spec.lua b/test/functional/legacy/search_mbyte_spec.lua index 58c064161b..832fc1c831 100644 --- a/test/functional/legacy/search_mbyte_spec.lua +++ b/test/functional/legacy/search_mbyte_spec.lua @@ -5,7 +5,7 @@ local feed, insert, source = helpers.feed, helpers.insert, helpers.source local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect describe('search_mbyte', function() - setup(clear) + before_each(clear) it('is working', function() insert([=[ From 63a12e1e2d0ed3c057f491e57b88e096b9d03215 Mon Sep 17 00:00:00 2001 From: Jurica Bradaric Date: Mon, 1 Feb 2016 08:53:59 +0100 Subject: [PATCH 5/7] Remove unused variables from the test. --- test/functional/legacy/search_mbyte_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/legacy/search_mbyte_spec.lua b/test/functional/legacy/search_mbyte_spec.lua index 832fc1c831..d807e69b68 100644 --- a/test/functional/legacy/search_mbyte_spec.lua +++ b/test/functional/legacy/search_mbyte_spec.lua @@ -1,7 +1,7 @@ -- Test for search('multi-byte char', 'bce') local helpers = require('test.functional.helpers') -local feed, insert, source = helpers.feed, helpers.insert, helpers.source +local insert = helpers.insert local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect describe('search_mbyte', function() From 815ba27f753fdf86151d5b64f3edee3c63ce0632 Mon Sep 17 00:00:00 2001 From: Jurica Bradaric Date: Mon, 1 Feb 2016 09:09:08 +0100 Subject: [PATCH 6/7] legacy2luatest: Use before_each instead of setup. This will avoid confusion if additional `it()` blocks are added. (`setup()` only runs once per `describe()` block, whereas `before_each()` runs before each `it()`). --- scripts/legacy2luatest.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/legacy2luatest.pl b/scripts/legacy2luatest.pl index ebd8dad1e1..8155353fc7 100755 --- a/scripts/legacy2luatest.pl +++ b/scripts/legacy2luatest.pl @@ -287,7 +287,7 @@ local feed, insert, source = helpers.feed, helpers.insert, helpers.source local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect describe('$test_name', function() - setup(clear) + before_each(clear) it('is working', function() @{[join "\n", map { /^$/ ? '' : ' ' . $_ } @{$test_body_lines}]} From 69234f4a76ca334d670bbf1830c5d70f40d0beb8 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 15 Feb 2016 01:46:04 -0500 Subject: [PATCH 7/7] test: search_mbyte_spec: minor cleanup mbyte.vim, small.vim are not relevant to migrated legacy tests. --- test/functional/legacy/search_mbyte_spec.lua | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/functional/legacy/search_mbyte_spec.lua b/test/functional/legacy/search_mbyte_spec.lua index d807e69b68..075b24b897 100644 --- a/test/functional/legacy/search_mbyte_spec.lua +++ b/test/functional/legacy/search_mbyte_spec.lua @@ -1,5 +1,3 @@ --- Test for search('multi-byte char', 'bce') - local helpers = require('test.functional.helpers') local insert = helpers.insert local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect @@ -7,16 +5,13 @@ local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect describe('search_mbyte', function() before_each(clear) - it('is working', function() + it("search('multi-byte char', 'bce')", function() insert([=[ Results: Test bce: A]=]) - execute('source small.vim') - execute('source mbyte.vim') - execute('set encoding=utf-8') execute('/^Test bce:/+1') execute([[$put =search('A', 'bce', line('.'))]])