(t *testing.T)
| 35 | ) |
| 36 | |
| 37 | func 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) |
nothing calls this directly
no test coverage detected