diff src/testdir/test_expr.vim @ 9892:41c5d59e7e10 v7.4.2220

commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Aug 16 21:30:54 2016 +0200 patch 7.4.2220 Problem: printf() gives an error when the argument for %s is not a string. (Ozaki Kiichi) Solution: Behave like invoking string() on the argument. (Ken Takata)
author Christian Brabandt <cb@256bit.org>
date Tue, 16 Aug 2016 21:45:06 +0200
parents 560291211303
children b01afb4e8f66
line wrap: on
line diff
--- a/src/testdir/test_expr.vim
+++ b/src/testdir/test_expr.vim
@@ -136,6 +136,33 @@ function Test_printf_64bit()
   endif
 endfunc
 
+function Test_printf_spec_s()
+  " number
+  call assert_equal("1234567890", printf('%s', 1234567890))
+
+  " string
+  call assert_equal("abcdefgi", printf('%s', "abcdefgi"))
+
+  " float
+  if has('float')
+    call assert_equal("1.23", printf('%s', 1.23))
+  endif
+
+  " list
+  let value = [1, 'two', ['three', 4]]
+  call assert_equal(string(value), printf('%s', value))
+
+  " dict
+  let value = {'key1' : 'value1', 'key2' : ['list', 'value'], 'key3' : {'dict' : 'value'}}
+  call assert_equal(string(value), printf('%s', value))
+
+  " funcref
+  call assert_equal('printf', printf('%s', function('printf')))
+
+  " partial
+  call assert_equal(string(function('printf', ['%s'])), printf('%s', function('printf', ['%s'])))
+endfunc
+
 func Test_substitute_expr()
   let g:val = 'XXX'
   call assert_equal('XXX', substitute('yyy', 'y*', '\=g:val', ''))