github.com/eden-framework/sqlx@v0.0.2/datatypes/bool_test.go (about) 1 package datatypes 2 3 import ( 4 "encoding/json" 5 "testing" 6 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 }