vim-patch:8.2.2969: subtracting from number option fails when result is zero

Problem:    Subtracting from number option fails when result is zero. (Ingo
            Karkat)
Solution:   Reset the string value when using the numeric value.
            (closes vim/vim#8351)
a42e6e0082

Cherry-pick Test_compound_assignment_operators() changes from patch 8.2.1593
This commit is contained in:
zeertzjq 2022-07-25 18:11:37 +08:00
parent 963ea726da
commit d8df9afad6
2 changed files with 16 additions and 6 deletions

View File

@ -663,6 +663,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo
case '%':
n = num_modulus(numval, n); break;
}
s = NULL;
} else if (opt_type == gov_string && stringval != NULL && s != NULL) {
// string
char *const oldstringval = stringval;

View File

@ -1661,16 +1661,25 @@ func Test_compound_assignment_operators()
call assert_equal(6, &scrolljump)
let &scrolljump %= 5
call assert_equal(1, &scrolljump)
call assert_fails('let &scrolljump .= "j"', 'E734')
call assert_fails('let &scrolljump .= "j"', 'E734:')
set scrolljump&vim
let &foldlevelstart = 2
let &foldlevelstart -= 1
call assert_equal(1, &foldlevelstart)
let &foldlevelstart -= 1
call assert_equal(0, &foldlevelstart)
let &foldlevelstart = 2
let &foldlevelstart -= 2
call assert_equal(0, &foldlevelstart)
" Test for register
let @/ = 1
call assert_fails('let @/ += 1', 'E734')
call assert_fails('let @/ -= 1', 'E734')
call assert_fails('let @/ *= 1', 'E734')
call assert_fails('let @/ /= 1', 'E734')
call assert_fails('let @/ %= 1', 'E734')
call assert_fails('let @/ += 1', 'E734:')
call assert_fails('let @/ -= 1', 'E734:')
call assert_fails('let @/ *= 1', 'E734:')
call assert_fails('let @/ /= 1', 'E734:')
call assert_fails('let @/ %= 1', 'E734:')
let @/ .= 's'
call assert_equal('1s', @/)
let @/ = ''