1
0
forked from aniani/vim

patch 8.2.3315: cannot use single quote in a float number for readability

Problem:    Cannot use single quote in a float number for readability.
Solution:   Support single quotes like in numbers. (closes #8713)
This commit is contained in:
Bram Moolenaar
2021-08-08 15:43:34 +02:00
parent 267359902c
commit 2950065e18
7 changed files with 72 additions and 10 deletions

View File

@@ -239,13 +239,28 @@ func Test_str2float()
call assert_equal('nan', string(str2float('NaN')))
call assert_equal('nan', string(str2float(' nan ')))
call assert_equal(1.2, str2float(1.2))
call assert_equal('123456.789', string(str2float("123'456.789", 1)))
call assert_equal('123456.789', string(str2float("12'34'56.789", 1)))
call assert_equal('123456.789', string(str2float("1'2'3'4'5'6.789", 1)))
call assert_equal('1.0', string(str2float("1''2.3", 1)))
call assert_equal('123456.7', string(str2float("123'456.7'89", 1)))
call assert_equal(1.2, str2float(1.2, 0))
call CheckDefAndScriptFailure2(['str2float(1.2)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1')
call assert_fails("call str2float([])", 'E730:')
call assert_fails("call str2float({})", 'E731:')
call assert_fails("call str2float(function('string'))", 'E729:')
endfunc
def Test_float_quotes()
call assert_equal('123456.789', string(123'456.789))
call assert_equal('123456.789', string(12'34'56.789))
call assert_equal('123456.789', string(1'2'3'4'5'6.789))
call assert_fails("echo string(1''2.3)", 'E116:')
call assert_fails("echo string(123'456.7'89)", 'E116:')
enddef
func Test_float2nr()
call assert_equal(1, float2nr(1.234))
call assert_equal(123, float2nr(1.234e2))