0
0
mirror of https://github.com/vim/vim.git synced 2025-10-03 05:14:07 -04:00

patch 8.2.2658: :for cannot loop over a string

Problem:    :for cannot loop over a string.
Solution:   Accept a string argument and iterate over its characters.
This commit is contained in:
Bram Moolenaar
2021-03-26 20:41:29 +01:00
parent 522eefd9a2
commit 74e54fcb44
9 changed files with 164 additions and 33 deletions

View File

@@ -7484,6 +7484,26 @@ func Test_trinary_expression()
call assert_equal(v:false, eval(string(v:false)))
endfunction
func Test_for_over_string()
let res = ''
for c in 'aéc̀d'
let res ..= c .. '-'
endfor
call assert_equal('a-é-c̀-d-', res)
let res = ''
for c in ''
let res ..= c .. '-'
endfor
call assert_equal('', res)
let res = ''
for c in test_null_string()
let res ..= c .. '-'
endfor
call assert_equal('', res)
endfunc
"-------------------------------------------------------------------------------
" Modelines {{{1
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker