]> granicus.if.org Git - vim/commitdiff
patch 8.2.0307: Python 3 vim.eval not well tested v8.2.0307
authorBram Moolenaar <Bram@vim.org>
Sun, 23 Feb 2020 14:10:16 +0000 (15:10 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 23 Feb 2020 14:10:16 +0000 (15:10 +0100)
Problem:    Python 3 vim.eval not well tested.
Solution:   Add a test. (Dominique Pelle, closes #5680)

src/testdir/test_python3.vim
src/version.c

index 2f5e0571aa953a2e4696a660048697884a18f7d9..61be9a1e9fb233c5041f508b261cd09fa8fde6eb 100644 (file)
@@ -188,6 +188,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.140000",    execute('py3 print(vim.eval("1.01+2.13"))'))
+    call assert_equal("\n0.000000",    execute('py3 print(vim.eval("0.0/(1.0/0.0)"))'))
+    call assert_equal("\n0.000000",    execute('py3 print(vim.eval("0.0/(1.0/0.0)"))'))
+    call assert_equal("\n-0.000000",   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+")', 'vim.error: invalid expression')
+endfunc
+
 " Test range objects, see :help python-range
 func Test_python3_range()
   new
index 49cdcc5da7d07a7b97fd3cf23174605361c4136b..373eb163cbb0ba832b4e89392ec16c90c70e8df6 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    307,
 /**/
     306,
 /**/