changeset 15172:de7e90fb445c v8.1.0596

patch 8.1.0596: not all parts of printf() are tested commit https://github.com/vim/vim/commit/21e551cce26ea6ff389b6c90f1945facf1a8a066 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Dec 15 16:08:56 2018 +0100 patch 8.1.0596: not all parts of printf() are tested Problem: Not all parts of printf() are tested. Solution: Add a few more test cases. (Dominique Pelle, closes https://github.com/vim/vim/issues/3691)
author Bram Moolenaar <Bram@vim.org>
date Sat, 15 Dec 2018 16:15:05 +0100
parents d8101121fd28
children 0bc21915ee7c
files src/testdir/test_expr.vim src/version.c
diffstat 2 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_expr.vim
+++ b/src/testdir/test_expr.vim
@@ -142,6 +142,22 @@ function Test_printf_misc()
   call assert_equal('173', printf('%O', 123))
   call assert_equal('7b', printf('%x', 123))
   call assert_equal('7B', printf('%X', 123))
+
+  call assert_equal('123', printf('%hd', 123))
+  call assert_equal('-123', printf('%hd', -123))
+  call assert_equal('-1', printf('%hd', 0xFFFF))
+  call assert_equal('-1', printf('%hd', 0x1FFFFF))
+
+  call assert_equal('123', printf('%hu', 123))
+  call assert_equal('65413', printf('%hu', -123))
+  call assert_equal('65535', printf('%hu', 0xFFFF))
+  call assert_equal('65535', printf('%hu', 0x1FFFFF))
+
+  call assert_equal('123', printf('%ld', 123))
+  call assert_equal('-123', printf('%ld', -123))
+  call assert_equal('65535', printf('%ld', 0xFFFF))
+  call assert_equal('131071', printf('%ld', 0x1FFFF))
+
   if has('ebcdic')
     call assert_equal('#', printf('%c', 123))
   else
@@ -185,6 +201,11 @@ function Test_printf_misc()
   call assert_equal('  123', printf('% *d', 5, 123))
   call assert_equal(' +123', printf('%+ *d', 5, 123))
 
+  call assert_equal('foobar', printf('%.*s',  9, 'foobar'))
+  call assert_equal('foo',    printf('%.*s',  3, 'foobar'))
+  call assert_equal('',       printf('%.*s',  0, 'foobar'))
+  call assert_equal('foobar', printf('%.*s', -1, 'foobar'))
+
   " Simple quote (thousand grouping char) is ignored.
   call assert_equal('+00123456', printf("%+'09d", 123456))
 
@@ -207,6 +228,11 @@ function Test_printf_misc()
   call assert_equal(' 00123', printf('%6.5d', 123))
   call assert_equal(' 0007b', printf('%6.5x', 123))
 
+  call assert_equal('123', printf('%.2d', 123))
+  call assert_equal('0123', printf('%.4d', 123))
+  call assert_equal('0000000123', printf('%.10d', 123))
+  call assert_equal('123', printf('%.0d', 123))
+
   call assert_equal('abc', printf('%2s', 'abc'))
   call assert_equal('abc', printf('%2S', 'abc'))
   call assert_equal('abc', printf('%.4s', 'abc'))
@@ -305,6 +331,11 @@ function Test_printf_float()
     call assert_equal('inf', printf('%s', 1.0/0.0))
     call assert_equal('-inf', printf('%s', -1.0/0.0))
 
+    " Test special case where max precision is truncated at 340.
+    call assert_equal('1.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', printf('%.330f', 1.0))
+    call assert_equal('1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', printf('%.340f', 1.0))
+    call assert_equal('1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', printf('%.350f', 1.0))
+
     " Float nan (not a number) has no sign.
     call assert_equal('nan', printf('%f', sqrt(-1.0)))
     call assert_equal('nan', printf('%f', 0.0/0.0))
--- a/src/version.c
+++ b/src/version.c
@@ -800,6 +800,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    596,
+/**/
     595,
 /**/
     594,