vim-patch:8.2.0307: Python 3 vim.eval not well tested

Problem:    Python 3 vim.eval not well tested.
Solution:   Add a test. (Dominique Pelle, closes vim/vim#5680)

026270c01d

Amend float values to pass on Ubuntu.
Comment out failing cases (ie. v:none, blob).

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
Jan Edmund Lazo
2025-08-03 23:08:15 -04:00
parent 2a267d1cbf
commit d632ffa243

View File

@@ -191,6 +191,31 @@ func Test_unicode()
set encoding=utf8
endfunc
" Test vim.eval() with various types.
func Test_python3_vim_val()
call assert_equal("\n8", execute('py3 print(vim.eval("3+5"))'))
if has('float')
call assert_equal("\n3.1399999999999997", execute('py3 print(vim.eval("1.01+2.13"))'))
call assert_equal("\n0.0", execute('py3 print(vim.eval("0.0/(1.0/0.0)"))'))
call assert_equal("\n0.0", execute('py3 print(vim.eval("0.0/(1.0/0.0)"))'))
call assert_equal("\n-0.0", execute('py3 print(vim.eval("0.0/(-1.0/0.0)"))'))
" Commented out: output of infinity and nan depend on platforms.
" call assert_equal("\ninf", execute('py3 print(vim.eval("1.0/0.0"))'))
" call assert_equal("\n-inf", execute('py3 print(vim.eval("-1.0/0.0"))'))
" call assert_equal("\n-nan", execute('py3 print(vim.eval("0.0/0.0"))'))
endif
call assert_equal("\nabc", execute('py3 print(vim.eval("\"abc\""))'))
call assert_equal("\n['1', '2']", execute('py3 print(vim.eval("[1, 2]"))'))
call assert_equal("\n{'1': '2'}", execute('py3 print(vim.eval("{1:2}"))'))
call assert_equal("\nTrue", execute('py3 print(vim.eval("v:true"))'))
call assert_equal("\nFalse", execute('py3 print(vim.eval("v:false"))'))
call assert_equal("\nNone", execute('py3 print(vim.eval("v:null"))'))
" call assert_equal("\nNone", execute('py3 print(vim.eval("v:none"))'))
" call assert_equal("\nb'\\xab\\x12'", execute('py3 print(vim.eval("0zab12"))'))
call assert_fails('py3 vim.eval("1+")', 'E5108:')
endfunc
" Test for resetting options with local values to global values
func Test_python3_opt_reset_local_to_global()
throw 'Skipped: Nvim does not support vim.bindeval()'