gojay

high performance JSON encoder/decoder with stream API for Golang
git clone git://git.lair.cx/gojay
Log | Files | Refs | README | LICENSE

commit 75fff352c961091226ab3c6876e46631ecd63e53
parent 1ae4a105b6c379370fa6abaaecdcc621b57f79d5
Author: francoispqt <francois@parquet.ninja>
Date:   Wed, 25 Jul 2018 00:12:15 +0800

add sql null decode tests

Diffstat:
Adecode_sqlnull_test.go | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+), 0 deletions(-)

diff --git a/decode_sqlnull_test.go b/decode_sqlnull_test.go @@ -0,0 +1,53 @@ +package gojay + +import ( + "database/sql" + "strings" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestDecodeSQLNullString(t *testing.T) { + testCases := []struct { + name string + json string + expectedNullString sql.NullString + }{ + { + name: "basic", + json: `"test"`, + expectedNullString: sql.NullString{String: "test", Valid: true}, + }, + } + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T) { + nullString := sql.NullString{} + dec := NewDecoder(strings.NewReader(testCase.json)) + dec.DecodeSQLNullString(&nullString) + assert.Equal(t, testCase.expectedNullString, nullString) + }) + } +} + +func TestDecodeSQLNullInt64(t *testing.T) { + testCases := []struct { + name string + json string + expectedNullInt64 sql.NullInt64 + }{ + { + name: "basic", + json: `1`, + expectedNullInt64: sql.NullInt64{Int64: 1, Valid: true}, + }, + } + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T) { + nullInt64 := sql.NullInt64{} + dec := NewDecoder(strings.NewReader(testCase.json)) + dec.DecodeSQLNullInt64(&nullInt64) + assert.Equal(t, testCase.expectedNullInt64, nullInt64) + }) + } +}