diff src/testdir/test_float_func.vim @ 10555:fff45421182b v8.0.0167

patch 8.0.0167: str2nr()/str2float() fail with negative values commit https://github.com/vim/vim/commit/08243d26d22ad44a857d02c90071578577b8a55d Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jan 10 16:12:29 2017 +0100 patch 8.0.0167: str2nr()/str2float() fail with negative values Problem: str2nr() and str2float() do not always work with negative values. Solution: Be more flexible about handling signs. (LemonBoy, closes https://github.com/vim/vim/issues/1332) Add more tests.
author Christian Brabandt <cb@256bit.org>
date Tue, 10 Jan 2017 16:15:04 +0100
parents 6ddf322ff7cf
children 018b7ecc58db
line wrap: on
line diff
--- a/src/testdir/test_float_func.vim
+++ b/src/testdir/test_float_func.vim
@@ -165,9 +165,22 @@ endfunc
 
 func Test_str2float()
   call assert_equal('1.0', string(str2float('1')))
+  call assert_equal('1.0', string(str2float(' 1 ')))
+  call assert_equal('1.0', string(str2float(' 1.0 ')))
   call assert_equal('1.23', string(str2float('1.23')))
   call assert_equal('1.23', string(str2float('1.23abc')))
   call assert_equal('1.0e40', string(str2float('1e40')))
+
+  call assert_equal('1.0', string(str2float('+1')))
+  call assert_equal('1.0', string(str2float('+1')))
+  call assert_equal('1.0', string(str2float(' +1 ')))
+  call assert_equal('1.0', string(str2float(' + 1 ')))
+
+  call assert_equal('-1.0', string(str2float('-1')))
+  call assert_equal('-1.0', string(str2float('-1')))
+  call assert_equal('-1.0', string(str2float(' -1 ')))
+  call assert_equal('-1.0', string(str2float(' - 1 ')))
+
   call assert_equal('inf', string(str2float('1e1000')))
   call assert_equal('inf', string(str2float('inf')))
   call assert_equal('-inf', string(str2float('-inf')))