@@ -76,6 +76,13 @@ function runtime_float()
7676 cfmt ( " %10.4f" , _erfinv ( rand () ) )
7777 end
7878end
79+ function runtime_float_spec ()
80+ set_seed! ( 10 )
81+ fs = Format. FmtSpec (" %10.4f" )
82+ for i in 1 : 200000
83+ cfmt ( fs, _erfinv ( rand () ) )
84+ end
85+ end
7986function runtime_float_bypass ()
8087 f = generate_formatter ( " %10.4f" )
8188 set_seed! ( 10 )
8794println ()
8895println ( " float64 @sprintf speed" )
8996@time native_float ()
90- println ( " float64 sprintf speed" )
97+ println ( " float64 cfmt speed" )
9198@time runtime_float ()
92- println ( " float64 sprintf speed, bypass repeated lookup" )
99+ println ( " float64 cfmt spec speed" )
100+ @time runtime_float_spec ()
101+ println ( " float64 cfmt speed, bypass repeated lookup" )
93102@time runtime_float_bypass ()
94103
95104@testset " test commas..." begin
@@ -103,6 +112,10 @@ println( "float64 sprintf speed, bypass repeated lookup")
103112 @test cfmt ( " %'s" , 1234567.0 ) == " 1.234567e6"
104113end
105114
115+ @testset " Test bug introduced by stdlib/Printf rewrite" begin
116+ @test cfmt ( " %4.2s" , " a" ) == " a"
117+ end
118+
106119@testset " test format..." begin
107120 @test format ( 10 ) == " 10"
108121 @test format ( 10.0 ) == " 10"
165178 # same with unspecified width
166179 @test format ( 12345678 , commas= true , parens= true )== " 12,345,678 "
167180 @test format ( - 12345678 , commas= true , parens= true )== " (12,345,678)"
181+ end
168182
183+ @testset " autoscale" begin
169184 @test format ( 1.2e9 , autoscale = :metric ) == " 1.2G"
170185 @test format ( 1.2e6 , autoscale = :metric ) == " 1.2M"
171186 @test format ( 1.2e3 , autoscale = :metric ) == " 1.2k"
181196 @test format ( 0x100000 , autoscale = :binary ) == " 1Mi"
182197 @test format ( 0x800 , autoscale = :binary ) == " 2Ki"
183198 @test format ( 0x400 , autoscale = :binary ) == " 1Ki"
199+ end
184200
201+ @testset " suffix" begin
185202 @test format ( 100.00 , precision= 2 , suffix= " %" ) == " 100.00%"
186203 @test format ( 100 , precision= 2 , suffix= " %" ) == " 100%"
187204 @test format ( 100 , precision= 2 , suffix= " %" , conversion= " f" ) == " 100.00%"
0 commit comments