github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/msgfmt/jsonfmt/level_0/float_test.go (about)

     1  package test
     2  
     3  import (
     4  	"testing"
     5  	"github.com/stretchr/testify/require"
     6  	"github.com/v2pro/plz/msgfmt/jsonfmt"
     7  	"github.com/v2pro/plz/reflect2"
     8  )
     9  
    10  func Test_float64(t *testing.T) {
    11  	should := require.New(t)
    12  	encoder := jsonfmt.EncoderOf(reflect2.TypeOf(float64(1)))
    13  	should.Equal("222", string(encoder.Encode(nil,nil, reflect2.PtrOf(float64(222)))))
    14  	should.Equal("1.2345", string(encoder.Encode(nil,nil, reflect2.PtrOf(float64(1.2345)))))
    15  	should.Equal("1.23456", string(encoder.Encode(nil,nil, reflect2.PtrOf(float64(1.23456)))))
    16  	should.Equal("1.234567", string(encoder.Encode(nil,nil, reflect2.PtrOf(float64(1.234567)))))
    17  	should.Equal("1.001", string(encoder.Encode(nil,nil, reflect2.PtrOf(float64(1.001)))))
    18  }
    19  
    20  func Test_float32(t *testing.T) {
    21  	should := require.New(t)
    22  	encoder := jsonfmt.EncoderOf(reflect2.TypeOf(float32(1)))
    23  	should.Equal("222", string(encoder.Encode(nil,nil, reflect2.PtrOf(float32(222)))))
    24  	should.Equal("1.2345", string(encoder.Encode(nil,nil, reflect2.PtrOf(float32(1.2345)))))
    25  	should.Equal("1.23456", string(encoder.Encode(nil,nil, reflect2.PtrOf(float32(1.23456)))))
    26  	should.Equal("1.234567", string(encoder.Encode(nil,nil, reflect2.PtrOf(float32(1.234567)))))
    27  	should.Equal("1.001", string(encoder.Encode(nil,nil, reflect2.PtrOf(float32(1.001)))))
    28  }