MCPcopy
hub / github.com/pingcap/tidb / TestJSON

Function TestJSON

pkg/util/codec/codec_test.go:794–821  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

792}
793
794func TestJSON(t *testing.T) {
795 tbl := []string{
796 "1234.00",
797 `{"a": "b"}`,
798 }
799
800 originalDatums := make([]types.Datum, 0, len(tbl))
801 for _, jsonDatum := range tbl {
802 var d types.Datum
803 j, err := types.ParseBinaryJSONFromString(jsonDatum)
804 require.NoError(t, err)
805 d.SetMysqlJSON(j)
806 originalDatums = append(originalDatums, d)
807 }
808
809 buf := make([]byte, 0, 4096)
810 buf, err := encode(nil, buf, originalDatums, false)
811 require.NoError(t, err)
812
813 decodedDatums, err := Decode(buf, 2)
814 require.NoError(t, err)
815
816 for i := range decodedDatums {
817 lhs := originalDatums[i].GetMysqlJSON().String()
818 rhs := decodedDatums[i].GetMysqlJSON().String()
819 require.Equal(t, lhs, rhs)
820 }
821}
822
823func TestCut(t *testing.T) {
824 table := []struct {

Callers

nothing calls this directly

Calls 7

SetMysqlJSONMethod · 0.95
encodeFunction · 0.85
DecodeFunction · 0.85
GetMysqlJSONMethod · 0.80
StringMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected