0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

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 #1332)
            Add more tests.
This commit is contained in:
Bram Moolenaar
2017-01-10 16:12:29 +01:00
parent 03c60c1573
commit 08243d26d2
6 changed files with 47 additions and 3 deletions

View File

@@ -0,0 +1,18 @@
" Tests for various functions.
func Test_str2nr()
call assert_equal(0, str2nr(''))
call assert_equal(1, str2nr('1'))
call assert_equal(1, str2nr(' 1 '))
call assert_equal(1, str2nr('+1'))
call assert_equal(1, str2nr('+ 1'))
call assert_equal(1, str2nr(' + 1 '))
call assert_equal(-1, str2nr('-1'))
call assert_equal(-1, str2nr('- 1'))
call assert_equal(-1, str2nr(' - 1 '))
call assert_equal(123456789, str2nr('123456789'))
call assert_equal(-123456789, str2nr('-123456789'))
endfunc