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

Function TestCodecKey

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

Source from the content-addressed store, hash-verified

35)
36
37func TestCodecKey(t *testing.T) {
38 table := []struct {
39 Input []types.Datum
40 Expect []types.Datum
41 }{
42 {
43 types.MakeDatums(int64(1)),
44 types.MakeDatums(int64(1)),
45 },
46
47 {
48 types.MakeDatums(float32(1), float64(3.15), []byte("123"), "123"),
49 types.MakeDatums(float64(1), float64(3.15), []byte("123"), []byte("123")),
50 },
51 {
52 types.MakeDatums(uint64(1), float64(3.15), []byte("123"), int64(-1)),
53 types.MakeDatums(uint64(1), float64(3.15), []byte("123"), int64(-1)),
54 },
55
56 {
57 types.MakeDatums(true, false),
58 types.MakeDatums(int64(1), int64(0)),
59 },
60
61 {
62 types.MakeDatums(nil),
63 types.MakeDatums(nil),
64 },
65
66 {
67 types.MakeDatums(types.NewBinaryLiteralFromUint(100, -1), types.NewBinaryLiteralFromUint(100, 4)),
68 types.MakeDatums(uint64(100), uint64(100)),
69 },
70
71 {
72 types.MakeDatums(types.Enum{Name: "a", Value: 1}, types.Set{Name: "a", Value: 1}),
73 types.MakeDatums(uint64(1), uint64(1)),
74 },
75 }
76 typeCtx := types.DefaultStmtNoWarningContext.WithLocation(time.Local)
77 for i, datums := range table {
78 comment := fmt.Sprintf("%d %v", i, datums)
79 b, err := EncodeKey(typeCtx.Location(), nil, datums.Input...)
80 require.NoError(t, err, comment)
81
82 args, err := Decode(b, 1)
83 require.NoError(t, err, comment)
84 require.Equal(t, datums.Expect, args, comment)
85
86 b, err = EncodeValue(typeCtx.Location(), nil, datums.Input...)
87 require.NoError(t, err, comment)
88
89 size, err := estimateValuesSize(typeCtx, datums.Input)
90 require.NoError(t, err, comment)
91 require.Len(t, b, size, comment)
92
93 args, err = Decode(b, 1)
94 require.NoError(t, err, comment)

Callers

nothing calls this directly

Calls 12

SetRawMethod · 0.95
MakeDatumsFunction · 0.92
NewBinaryLiteralFromUintFunction · 0.92
EncodeKeyFunction · 0.85
DecodeFunction · 0.85
estimateValuesSizeFunction · 0.85
WithLocationMethod · 0.80
EncodeValueFunction · 0.70
LocationMethod · 0.65
EqualMethod · 0.65
LenMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected