Mercurial > vim
changeset 21425:a6c316ef161a v8.2.1263
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Commit: https://github.com/vim/vim/commit/c71f36a889897aca4ac2ad3828926e3801728336
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jul 21 21:31:00 2020 +0200
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Problem: Vim9: comperators use 'ignorecase' in Vim9 script.
Solution: Ignore 'ignorecase'. Use true and false instead of 1 and 0.
(closes #6497)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 21 Jul 2020 21:45:06 +0200 |
parents | 8835316c02ba |
children | bb6e617589d0 |
files | src/eval.c src/testdir/test_vim9_expr.vim src/typval.c src/version.c src/vim9execute.c |
diffstat | 5 files changed, 43 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/eval.c +++ b/src/eval.c @@ -2413,13 +2413,11 @@ eval3(char_u **arg, typval_T *rettv, eva static int eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg) { - typval_T var2; char_u *p; int getnext; int i; exptype_T type = EXPR_UNKNOWN; int len = 2; - int ic; /* * Get the first variable. @@ -2472,6 +2470,10 @@ eval4(char_u **arg, typval_T *rettv, eva */ if (type != EXPR_UNKNOWN) { + typval_T var2; + int ic; + int vim9script = in_vim9script(); + if (getnext) *arg = eval_next_line(evalarg); @@ -2487,9 +2489,9 @@ eval4(char_u **arg, typval_T *rettv, eva ic = FALSE; ++len; } - // nothing appended: use 'ignorecase' + // nothing appended: use 'ignorecase' if not in Vim script else - ic = p_ic; + ic = vim9script ? FALSE : p_ic; /* * Get the second variable. @@ -2504,8 +2506,7 @@ eval4(char_u **arg, typval_T *rettv, eva { int ret; - if (in_vim9script() && check_compare_types( - type, rettv, &var2) == FAIL) + if (vim9script && check_compare_types(type, rettv, &var2) == FAIL) { ret = FAIL; clear_tv(rettv);
--- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -651,7 +651,7 @@ def Test_expr4_vimscript() vim9script let var = 0 < 1 - assert_equal(1, var) + assert_equal(true, var) END CheckScriptSuccess(lines) @@ -659,7 +659,7 @@ def Test_expr4_vimscript() vim9script let var = 123 != 123 - assert_equal(0, var) + assert_equal(false, var) END CheckScriptSuccess(lines) @@ -667,7 +667,7 @@ def Test_expr4_vimscript() vim9script let var = 123 == 123 - assert_equal(1, var) + assert_equal(true, var) END CheckScriptSuccess(lines) @@ -676,7 +676,7 @@ def Test_expr4_vimscript() let list = [1, 2, 3] let var = list is list - assert_equal(1, var) + assert_equal(true, var) END CheckScriptSuccess(lines) @@ -685,7 +685,7 @@ def Test_expr4_vimscript() let myblob = 0z1234 let var = myblob isnot 0z11 - assert_equal(1, var) + assert_equal(true, var) END CheckScriptSuccess(lines) @@ -707,6 +707,25 @@ def Test_expr4_vimscript() echo 123 is 123 END CheckScriptFailure(lines, 'Cannot use "is" with number') + + # check 'ignorecase' not being used + lines =<< trim END + vim9script + set ignorecase + assert_equal(false, 'abc' == 'ABC') + assert_equal(false, 'abc' ==# 'ABC') + assert_equal(true, 'abc' ==? 'ABC') + + assert_equal(true, 'abc' != 'ABC') + assert_equal(true, 'abc' !=# 'ABC') + assert_equal(false, 'abc' !=? 'ABC') + + assert_equal(false, 'abc' =~ 'ABC') + assert_equal(false, 'abc' =~# 'ABC') + assert_equal(true, 'abc' =~? 'ABC') + set noignorecase + END + CheckScriptSuccess(lines) enddef func Test_expr4_fails()
--- a/src/typval.c +++ b/src/typval.c @@ -790,8 +790,16 @@ typval_compare( } } clear_tv(typ1); - typ1->v_type = VAR_NUMBER; - typ1->vval.v_number = n1; + if (in_vim9script()) + { + typ1->v_type = VAR_BOOL; + typ1->vval.v_number = n1 ? VVAL_TRUE : VVAL_FALSE; + } + else + { + typ1->v_type = VAR_NUMBER; + typ1->vval.v_number = n1; + } return OK; }