From d6e27f90b9ce19852d14e74c9e8a883f6c2207d7 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Sun, 23 Oct 2016 13:41:51 -0700 Subject: vim-patch:7.4.1730 Problem: It is not easy to get a character out of a string. Solution: Add strgetchar() and strcharpart(). https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187 --- src/nvim/testdir/test_alot.vim | 1 + src/nvim/testdir/test_expr.vim | 48 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/nvim/testdir/test_expr.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim index 036a4c0470..90194fefce 100644 --- a/src/nvim/testdir/test_alot.vim +++ b/src/nvim/testdir/test_alot.vim @@ -4,6 +4,7 @@ source test_assign.vim source test_cursor_func.vim source test_ex_undo.vim +source test_expr.vim source test_feedkeys.vim source test_cmdline.vim source test_menu.vim diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim new file mode 100644 index 0000000000..5c70dcb25e --- /dev/null +++ b/src/nvim/testdir/test_expr.vim @@ -0,0 +1,48 @@ +" Tests for expressions. + +func Test_strgetchar() + call assert_equal(char2nr('a'), strgetchar('axb', 0)) + call assert_equal(char2nr('x'), strgetchar('axb', 1)) + call assert_equal(char2nr('b'), strgetchar('axb', 2)) + + call assert_equal(-1, strgetchar('axb', -1)) + call assert_equal(-1, strgetchar('axb', 3)) + call assert_equal(-1, strgetchar('', 0)) + + if !has('multi_byte') + return + endif + + call assert_equal(char2nr('á'), strgetchar('áxb', 0)) + call assert_equal(char2nr('x'), strgetchar('áxb', 1)) + + call assert_equal(char2nr('a'), strgetchar('àxb', 0)) + call assert_equal(char2nr(''), strgetchar('àxb', 1)) + call assert_equal(char2nr('x'), strgetchar('àxb', 2)) +endfunc + +func Test_strcharpart() + call assert_equal('a', strcharpart('axb', 0, 1)) + call assert_equal('x', strcharpart('axb', 1, 1)) + call assert_equal('b', strcharpart('axb', 2, 1)) + call assert_equal('xb', strcharpart('axb', 1)) + + call assert_equal('', strcharpart('axb', 1, 0)) + call assert_equal('', strcharpart('axb', 1, -1)) + call assert_equal('', strcharpart('axb', -1, 1)) + call assert_equal('', strcharpart('axb', -2, 2)) + + call assert_equal('a', strcharpart('axb', -1, 2)) + + if !has('multi_byte') + return + endif + + call assert_equal('áxb', strcharpart('áxb', 0)) + call assert_equal('á', strcharpart('áxb', 0, 1)) + call assert_equal('x', strcharpart('áxb', 1, 1)) + + call assert_equal('a', strcharpart('àxb', 0, 1)) + call assert_equal('', strcharpart('àxb', 1, 1)) + call assert_equal('x', strcharpart('àxb', 2, 1)) +endfunc -- cgit From 763422b0365cd9270dc495f31e75e75913516088 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Sun, 23 Oct 2016 16:59:24 -0700 Subject: vim-patch:7.4.1734 Problem: Test fails when not using utf-8. Solution: Split test in regularand utf-8 part. https://github.com/vim/vim/commit/0f518a8f4d4be4cac10389680f6bd5e3781f94b0 --- src/nvim/testdir/test_alot.vim | 1 + src/nvim/testdir/test_expr.vim | 23 ----------------------- src/nvim/testdir/test_expr_utf8.vim | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 src/nvim/testdir/test_expr_utf8.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim index 90194fefce..87c1cd2c58 100644 --- a/src/nvim/testdir/test_alot.vim +++ b/src/nvim/testdir/test_alot.vim @@ -5,6 +5,7 @@ source test_assign.vim source test_cursor_func.vim source test_ex_undo.vim source test_expr.vim +source test_expr_utf8.vim source test_feedkeys.vim source test_cmdline.vim source test_menu.vim diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 5c70dcb25e..7ea4ebc7df 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -8,17 +8,6 @@ func Test_strgetchar() call assert_equal(-1, strgetchar('axb', -1)) call assert_equal(-1, strgetchar('axb', 3)) call assert_equal(-1, strgetchar('', 0)) - - if !has('multi_byte') - return - endif - - call assert_equal(char2nr('á'), strgetchar('áxb', 0)) - call assert_equal(char2nr('x'), strgetchar('áxb', 1)) - - call assert_equal(char2nr('a'), strgetchar('àxb', 0)) - call assert_equal(char2nr(''), strgetchar('àxb', 1)) - call assert_equal(char2nr('x'), strgetchar('àxb', 2)) endfunc func Test_strcharpart() @@ -33,16 +22,4 @@ func Test_strcharpart() call assert_equal('', strcharpart('axb', -2, 2)) call assert_equal('a', strcharpart('axb', -1, 2)) - - if !has('multi_byte') - return - endif - - call assert_equal('áxb', strcharpart('áxb', 0)) - call assert_equal('á', strcharpart('áxb', 0, 1)) - call assert_equal('x', strcharpart('áxb', 1, 1)) - - call assert_equal('a', strcharpart('àxb', 0, 1)) - call assert_equal('', strcharpart('àxb', 1, 1)) - call assert_equal('x', strcharpart('àxb', 2, 1)) endfunc diff --git a/src/nvim/testdir/test_expr_utf8.vim b/src/nvim/testdir/test_expr_utf8.vim new file mode 100644 index 0000000000..85cddbb13a --- /dev/null +++ b/src/nvim/testdir/test_expr_utf8.vim @@ -0,0 +1,33 @@ +" Tests for expressions using utf-8. +if !has('multi_byte') + finish +endif +scriptencoding utf-8 + +func Test_strgetchar() + call assert_equal(char2nr('a'), strgetchar('axb', 0)) + call assert_equal(char2nr('x'), strgetchar('axb', 1)) + call assert_equal(char2nr('b'), strgetchar('axb', 2)) + + call assert_equal(-1, strgetchar('axb', -1)) + call assert_equal(-1, strgetchar('axb', 3)) + call assert_equal(-1, strgetchar('', 0)) + + call assert_equal(char2nr('a'), strgetchar('àxb', 0)) + call assert_equal(char2nr('̀'), strgetchar('àxb', 1)) + call assert_equal(char2nr('x'), strgetchar('àxb', 2)) + + call assert_equal(char2nr('あ'), strgetchar('あaい', 0)) + call assert_equal(char2nr('a'), strgetchar('あaい', 1)) + call assert_equal(char2nr('い'), strgetchar('あaい', 2)) +endfunc + +func Test_strcharpart() + call assert_equal('áxb', strcharpart('áxb', 0)) + call assert_equal('á', strcharpart('áxb', 0, 1)) + call assert_equal('x', strcharpart('áxb', 1, 1)) + + call assert_equal('a', strcharpart('àxb', 0, 1)) + call assert_equal('̀', strcharpart('àxb', 1, 1)) + call assert_equal('x', strcharpart('àxb', 2, 1)) +endfunc -- cgit From 9e5dca84902eb620d856b1e9bd994218f4423708 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Sun, 23 Oct 2016 17:04:26 -0700 Subject: vim-patch:7.4.1741 Problem: Not testing utf-8 characters. Solution: Move the right asserts to the test_expr_utf8 test. https://github.com/vim/vim/commit/b22bd46b9681d73d095f2eadff8163d3a6cf416b --- src/nvim/testdir/test_expr_utf8.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_expr_utf8.vim b/src/nvim/testdir/test_expr_utf8.vim index 85cddbb13a..00d5d9a63a 100644 --- a/src/nvim/testdir/test_expr_utf8.vim +++ b/src/nvim/testdir/test_expr_utf8.vim @@ -5,9 +5,8 @@ endif scriptencoding utf-8 func Test_strgetchar() - call assert_equal(char2nr('a'), strgetchar('axb', 0)) - call assert_equal(char2nr('x'), strgetchar('axb', 1)) - call assert_equal(char2nr('b'), strgetchar('axb', 2)) + call assert_equal(char2nr('á'), strgetchar('áxb', 0)) + call assert_equal(char2nr('x'), strgetchar('áxb', 1)) call assert_equal(-1, strgetchar('axb', -1)) call assert_equal(-1, strgetchar('axb', 3)) -- cgit From 6bc0d9b8c75b5bef61a951e56deb2b28f50182d8 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Sun, 23 Oct 2016 17:38:28 -0700 Subject: vim-patch:7.4.1779 Problem: Using negative index in strcharpart(). (Yegappan Lakshmanan) Solution: Assume single byte when using a negative iindex. https://github.com/vim/vim/commit/73dfe917ba6357413aaf98a021c91add5ac6e9bc --- src/nvim/testdir/test_expr_utf8.vim | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_expr_utf8.vim b/src/nvim/testdir/test_expr_utf8.vim index 00d5d9a63a..7bdcb4f65f 100644 --- a/src/nvim/testdir/test_expr_utf8.vim +++ b/src/nvim/testdir/test_expr_utf8.vim @@ -4,29 +4,35 @@ if !has('multi_byte') endif scriptencoding utf-8 -func Test_strgetchar() +func Test_strgetchar_utf8() call assert_equal(char2nr('á'), strgetchar('áxb', 0)) call assert_equal(char2nr('x'), strgetchar('áxb', 1)) - call assert_equal(-1, strgetchar('axb', -1)) - call assert_equal(-1, strgetchar('axb', 3)) - call assert_equal(-1, strgetchar('', 0)) - - call assert_equal(char2nr('a'), strgetchar('àxb', 0)) + call assert_equal(char2nr('a'), strgetchar('àxb', 0)) call assert_equal(char2nr('̀'), strgetchar('àxb', 1)) - call assert_equal(char2nr('x'), strgetchar('àxb', 2)) + call assert_equal(char2nr('x'), strgetchar('àxb', 2)) call assert_equal(char2nr('あ'), strgetchar('あaい', 0)) call assert_equal(char2nr('a'), strgetchar('あaい', 1)) call assert_equal(char2nr('い'), strgetchar('あaい', 2)) endfunc -func Test_strcharpart() +func Test_strcharpart_utf8() call assert_equal('áxb', strcharpart('áxb', 0)) call assert_equal('á', strcharpart('áxb', 0, 1)) call assert_equal('x', strcharpart('áxb', 1, 1)) - call assert_equal('a', strcharpart('àxb', 0, 1)) + call assert_equal('いうeお', strcharpart('あいうeお', 1)) + call assert_equal('い', strcharpart('あいうeお', 1, 1)) + call assert_equal('いう', strcharpart('あいうeお', 1, 2)) + call assert_equal('いうe', strcharpart('あいうeお', 1, 3)) + call assert_equal('いうeお', strcharpart('あいうeお', 1, 4)) + call assert_equal('eお', strcharpart('あいうeお', 3)) + call assert_equal('e', strcharpart('あいうeお', 3, 1)) + + call assert_equal('あ', strcharpart('あいうeお', -3, 4)) + + call assert_equal('a', strcharpart('àxb', 0, 1)) call assert_equal('̀', strcharpart('àxb', 1, 1)) - call assert_equal('x', strcharpart('àxb', 2, 1)) + call assert_equal('x', strcharpart('àxb', 2, 1)) endfunc -- cgit