github.com/kunlun-qilian/sqlx/v3@v3.0.0/datatypes/bool_test.go (about)

     1  package datatypes
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/kunlun-qilian/utils/json"
     7  	"github.com/onsi/gomega"
     8  )
     9  
    10  func TestBool(t *testing.T) {
    11  	t.Run("Marshal", func(t *testing.T) {
    12  		bytes, _ := json.Marshal(BOOL_TRUE)
    13  		gomega.NewWithT(t).Expect(string(bytes)).To(gomega.Equal("true"))
    14  
    15  		bytes, _ = json.Marshal(BOOL_FALSE)
    16  		gomega.NewWithT(t).Expect(string(bytes)).To(gomega.Equal("false"))
    17  
    18  		bytes, _ = json.Marshal(BOOL_UNKNOWN)
    19  		gomega.NewWithT(t).Expect(string(bytes)).To(gomega.Equal("null"))
    20  	})
    21  	t.Run("Unmarshal", func(t *testing.T) {
    22  		var b Bool
    23  
    24  		_ = json.Unmarshal([]byte("null"), &b)
    25  		gomega.NewWithT(t).Expect(b).To(gomega.Equal(BOOL_UNKNOWN))
    26  
    27  		_ = json.Unmarshal([]byte("true"), &b)
    28  		gomega.NewWithT(t).Expect(b).To(gomega.Equal(BOOL_TRUE))
    29  
    30  		_ = json.Unmarshal([]byte("false"), &b)
    31  		gomega.NewWithT(t).Expect(b).To(gomega.Equal(BOOL_FALSE))
    32  	})
    33  }