mirror of
https://github.com/neovim/neovim.git
synced 2026-08-29 18:41:48 +00:00
vim-patch:8.2.1794: no falsy Coalescing operator
Problem: No falsy Coalescing operator.
Solution: Add the "??" operator. Fix mistake with function argument count.
92f26c256e
Cherry-pick tv2bool() into eval/typval.c.
Cherry-pick *??* tag from Vim runtime.
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -39,6 +39,28 @@ func Test_version()
|
||||
call assert_false(has('patch-9.9.1'))
|
||||
endfunc
|
||||
|
||||
func Test_op_falsy()
|
||||
call assert_equal(v:true, v:true ?? 456)
|
||||
call assert_equal(123, 123 ?? 456)
|
||||
call assert_equal('yes', 'yes' ?? 456)
|
||||
call assert_equal(0z00, 0z00 ?? 456)
|
||||
call assert_equal([1], [1] ?? 456)
|
||||
call assert_equal(#{one: 1}, #{one: 1} ?? 456)
|
||||
if has('float')
|
||||
call assert_equal(0.1, 0.1 ?? 456)
|
||||
endif
|
||||
|
||||
call assert_equal(456, v:false ?? 456)
|
||||
call assert_equal(456, 0 ?? 456)
|
||||
call assert_equal(456, '' ?? 456)
|
||||
call assert_equal(456, 0z ?? 456)
|
||||
call assert_equal(456, [] ?? 456)
|
||||
call assert_equal(456, {} ?? 456)
|
||||
if has('float')
|
||||
call assert_equal(456, 0.0 ?? 456)
|
||||
endif
|
||||
endfunc
|
||||
|
||||
func Test_dict()
|
||||
let d = {'': 'empty', 'a': 'a', 0: 'zero'}
|
||||
call assert_equal('empty', d[''])
|
||||
|
||||
Reference in New Issue
Block a user