From a714bd5da4ab64e737658247b0db7a00e1fea557 Mon Sep 17 00:00:00 2001 From: illia-li Date: Sat, 21 Sep 2024 16:45:53 -0400 Subject: [PATCH] resolve conversations for serialization.Set --- marshal/tests/funcs/equal.go | 71 +++++++++++++++ marshal/tests/funcs/new.go | 23 +++++ marshal/tests/funcs/utils.go | 19 ---- marshal/tests/mod/all.go | 24 +++-- marshal/tests/mod/custom.go | 16 +--- marshal/tests/mod/custom_refs.go | 11 +-- marshal/tests/mod/refs.go | 12 +-- marshal/tests/serialization/set.go | 131 ++++++++++++--------------- marshal/tests/serialization/utils.go | 23 ----- marshal/tests/utils/selected.go | 24 ----- marshal/tests/utils/string.go | 7 +- marshal/tests/utils/string_vals.go | 26 ++---- marshal/tests/utils/utils.go | 17 ---- marshal_3_smallint_test.go | 86 ++++++++---------- 14 files changed, 224 insertions(+), 266 deletions(-) create mode 100644 marshal/tests/funcs/equal.go create mode 100644 marshal/tests/funcs/new.go delete mode 100644 marshal/tests/funcs/utils.go delete mode 100644 marshal/tests/serialization/utils.go delete mode 100644 marshal/tests/utils/selected.go diff --git a/marshal/tests/funcs/equal.go b/marshal/tests/funcs/equal.go new file mode 100644 index 000000000..35244bbf1 --- /dev/null +++ b/marshal/tests/funcs/equal.go @@ -0,0 +1,71 @@ +package funcs + +import ( + "bytes" + "fmt" + "gopkg.in/inf.v0" + "math/big" + "reflect" + "unsafe" + + "github.com/gocql/gocql/marshal/tests/mod" +) + +func EqualData(in1, in2 []byte) bool { + if in1 == nil || in2 == nil { + return in1 == nil && in2 == nil + } + return bytes.Equal(in1, in2) +} + +func EqualVals(in1, in2 interface{}) bool { + rin1 := reflect.ValueOf(in1) + rin2 := reflect.ValueOf(in2) + if rin1.Kind() == reflect.Ptr && (rin1.IsNil() || rin2.IsNil()) { + return rin1.IsNil() && rin2.IsNil() + } + + switch vin1 := in1.(type) { + case float32: + vin2 := in2.(float32) + return *(*[4]byte)(unsafe.Pointer(&vin1)) == *(*[4]byte)(unsafe.Pointer(&vin2)) + case *float32: + vin2 := in2.(*float32) + return *(*[4]byte)(unsafe.Pointer(vin1)) == *(*[4]byte)(unsafe.Pointer(vin2)) + case *mod.Float32: + vin2 := in2.(*mod.Float32) + return *(*[4]byte)(unsafe.Pointer(vin1)) == *(*[4]byte)(unsafe.Pointer(vin2)) + case mod.Float32: + vin2 := in2.(mod.Float32) + return *(*[4]byte)(unsafe.Pointer(&vin1)) == *(*[4]byte)(unsafe.Pointer(&vin2)) + case float64: + vin2 := in2.(float64) + return *(*[8]byte)(unsafe.Pointer(&vin1)) == *(*[8]byte)(unsafe.Pointer(&vin2)) + case *float64: + vin2 := in2.(*float64) + return *(*[8]byte)(unsafe.Pointer(vin1)) == *(*[8]byte)(unsafe.Pointer(vin2)) + case *mod.Float64: + vin2 := in2.(*mod.Float64) + return *(*[8]byte)(unsafe.Pointer(vin1)) == *(*[8]byte)(unsafe.Pointer(vin2)) + case mod.Float64: + vin2 := in2.(mod.Float64) + return *(*[8]byte)(unsafe.Pointer(&vin1)) == *(*[8]byte)(unsafe.Pointer(&vin2)) + case big.Int: + vin2 := in2.(big.Int) + return vin1.Cmp(&vin2) == 0 + case *big.Int: + vin2 := in2.(*big.Int) + return vin1.Cmp(vin2) == 0 + case inf.Dec: + vin2 := in2.(inf.Dec) + return vin1.Cmp(&vin2) == 0 + case *inf.Dec: + vin2 := in2.(*inf.Dec) + return vin1.Cmp(vin2) == 0 + case fmt.Stringer: + vin2 := in2.(fmt.Stringer) + return vin1.String() == vin2.String() + default: + return reflect.DeepEqual(in1, in2) + } +} diff --git a/marshal/tests/funcs/new.go b/marshal/tests/funcs/new.go new file mode 100644 index 000000000..3dba7a202 --- /dev/null +++ b/marshal/tests/funcs/new.go @@ -0,0 +1,23 @@ +package funcs + +import ( + "reflect" +) + +func New(in interface{}) interface{} { + return getNew(reflect.ValueOf(in)) +} + +func getNew(orig reflect.Value) reflect.Value { + if orig.Kind() != reflect.Ptr { + return reflect.Zero(orig.Type()) + } + if orig.IsNil() { + return reflect.Zero(orig.Type()) + } else if orig.IsZero() { + return reflect.Zero(orig.Type()) + } + newVal := reflect.New(orig.Type().Elem()) + newVal.Elem().Set(getNew(orig.Elem())) + return newVal +} diff --git a/marshal/tests/funcs/utils.go b/marshal/tests/funcs/utils.go deleted file mode 100644 index a23152e6d..000000000 --- a/marshal/tests/funcs/utils.go +++ /dev/null @@ -1,19 +0,0 @@ -package funcs - -import ( - "fmt" - "reflect" -) - -var ( - ExcludedMarshal = func(interface{}) ([]byte, error) { return nil, fmt.Errorf("run on ExcludedMarshal func") } - ExcludedUnmarshal = func([]byte, interface{}) error { return fmt.Errorf("run on ExcludedUnmarshal func") } -) - -func IsExcludedMarshal(f func(interface{}) ([]byte, error)) bool { - return reflect.ValueOf(f).Pointer() == reflect.ValueOf(ExcludedMarshal).Pointer() -} - -func IsExcludedUnmarshal(f func([]byte, interface{}) error) bool { - return reflect.ValueOf(f).Pointer() == reflect.ValueOf(ExcludedUnmarshal).Pointer() -} diff --git a/marshal/tests/mod/all.go b/marshal/tests/mod/all.go index 4dadc7617..17411ed55 100644 --- a/marshal/tests/mod/all.go +++ b/marshal/tests/mod/all.go @@ -1,18 +1,22 @@ package mod +var All = Mods{IntoCustom, IntoRef, IntoCustomRef} + type Mods []Mod // Mod - value modifiers. -// Designed for test case generators, such as gen.Group, marshal.Group and unmarshal.Group. -type Mod interface { - Name() string - Apply([]interface{}) []interface{} +type Mod func(vals ...interface{}) []interface{} + +func To(vals ...interface{}) Vals { + return vals } -var ( - IntoCustom intoCustom - IntoRef intoRef - IntoCustomRef intoCustomRef +type Vals []interface{} - All = Mods{IntoCustom, IntoRef, IntoCustomRef} -) +func (v Vals) AddVariants(mods ...Mod) Vals { + out := append(make([]interface{}, 0), v...) + for _, mod := range mods { + out = append(out, mod(v...)...) + } + return out +} diff --git a/marshal/tests/mod/custom.go b/marshal/tests/mod/custom.go index f93a50086..b24b964b2 100644 --- a/marshal/tests/mod/custom.go +++ b/marshal/tests/mod/custom.go @@ -44,19 +44,13 @@ type ( MapUDT map[string]interface{} ) -type intoCustom struct{} - -func (m intoCustom) Name() string { - return "custom" -} - -func (m intoCustom) Apply(vals []interface{}) []interface{} { +var IntoCustom Mod = func(vals ...interface{}) []interface{} { out := make([]interface{}, 0) for i := range vals { if vals[i] == nil { continue } - ct := m.apply(vals[i]) + ct := intoCustom(vals[i]) if ct != nil { out = append(out, ct) } @@ -64,7 +58,7 @@ func (m intoCustom) Apply(vals []interface{}) []interface{} { return out } -func (m intoCustom) apply(i interface{}) interface{} { +func intoCustom(i interface{}) interface{} { switch v := i.(type) { case bool: return Bool(v) @@ -131,11 +125,11 @@ func (m intoCustom) apply(i interface{}) interface{} { case [1]interface{}: return ArrAny(v) default: - return m.applyRef(i) + return intoCustomR(i) } } -func (m intoCustom) applyRef(i interface{}) interface{} { +func intoCustomR(i interface{}) interface{} { switch v := i.(type) { case *bool: return (*Bool)(v) diff --git a/marshal/tests/mod/custom_refs.go b/marshal/tests/mod/custom_refs.go index ce857c34d..4c99c2cbd 100644 --- a/marshal/tests/mod/custom_refs.go +++ b/marshal/tests/mod/custom_refs.go @@ -1,12 +1,5 @@ package mod -type intoCustomRef struct{} - -func (m intoCustomRef) Name() string { - return "*custom" -} - -func (m intoCustomRef) Apply(vals []interface{}) []interface{} { - custom := intoCustom{}.Apply(vals) - return intoRef{}.Apply(custom) +var IntoCustomRef Mod = func(vals ...interface{}) []interface{} { + return IntoRef(IntoCustom(vals...)...) } diff --git a/marshal/tests/mod/refs.go b/marshal/tests/mod/refs.go index ab8be1b60..38ca1398c 100644 --- a/marshal/tests/mod/refs.go +++ b/marshal/tests/mod/refs.go @@ -2,23 +2,17 @@ package mod import "reflect" -type intoRef struct{} - -func (m intoRef) Name() string { - return "*type" -} - -func (m intoRef) Apply(vals []interface{}) []interface{} { +var IntoRef Mod = func(vals ...interface{}) []interface{} { out := make([]interface{}, 0) for i := range vals { if vals[i] != nil { - out = append(out, m.apply(vals[i])) + out = append(out, intoRef(vals[i])) } } return out } -func (m intoRef) apply(val interface{}) interface{} { +func intoRef(val interface{}) interface{} { inV := reflect.ValueOf(val) out := reflect.New(reflect.TypeOf(val)) out.Elem().Set(inV) diff --git a/marshal/tests/serialization/set.go b/marshal/tests/serialization/set.go index 02ab0541c..cce3998ba 100644 --- a/marshal/tests/serialization/set.go +++ b/marshal/tests/serialization/set.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/gocql/gocql/marshal/tests/funcs" - "github.com/gocql/gocql/marshal/tests/mod" "github.com/gocql/gocql/marshal/tests/utils" ) @@ -25,97 +24,81 @@ type Set struct { IssueUnmarshal string } -func (s Set) AddModified(mods ...mod.Mod) Set { - out := s - for _, m := range mods { - out.Values = append(out.Values, m.Apply(s.Values)...) +func (s Set) Run(name string, t *testing.T, marshal func(interface{}) ([]byte, error), unmarshal func([]byte, interface{}) error) { + if name == "" { + name = utils.ValueToName(s.Values[0]) } - return out -} -func (s Set) Run(name string, t *testing.T, marshal func(interface{}) ([]byte, error), unmarshal func([]byte, interface{}) error) { - t.Logf("test set %s started", name) - for i := range s.Values { - val := s.Values[i] + t.Run(name, func(t *testing.T) { + for i := range s.Values { + val := s.Values[i] - if !funcs.IsExcludedMarshal(marshal) { - s.runMarshal(t, marshal, val) - } + t.Run(fmt.Sprintf("%T", val), func(t *testing.T) { + if marshal != nil { + s.runMarshal(t, marshal, val) + } - if !funcs.IsExcludedUnmarshal(unmarshal) { - s.runUnmarshal(t, unmarshal, val) + if unmarshal != nil { + s.runUnmarshal(t, unmarshal, val) + } + }) } - } - t.Logf("test set %s finished", name) + }) } func (s Set) runMarshal(t *testing.T, f func(interface{}) ([]byte, error), val interface{}) { - if s.IssueMarshal != "" { - t.Logf("\nmarshal test skipped bacause there is unsolved issue:\n%s", s.IssueMarshal) - return - } + t.Run("marshal", func(tt *testing.T) { + if s.IssueMarshal != "" { + tt.Skipf("skipped bacause there is unsolved issue: %s", s.IssueMarshal) + } - received, err := func() (d []byte, err error) { - defer func() { - if r := recover(); r != nil { - err = utils.PanicErr{Err: r.(error), Stack: debug.Stack()} - } + result, err := func() (d []byte, err error) { + defer func() { + if r := recover(); r != nil { + err = utils.PanicErr{Err: r.(error), Stack: debug.Stack()} + } + }() + return f(val) }() - return f(val) - }() - info := "" - if inStr := valStr(val); len(inStr)+len(s.Data)+len(received) < utils.PrintLimit*3 { - info = fmt.Sprintf("\n marshal in:%s\nexpected data:%s\nreceived data:%s", valStr(val), dataStr(s.Data), dataStr(received)) - } + if err != nil { + tt.Fatalf("marshal unexpectedly failed with error: %w", err) + } - switch { - case err != nil: - t.Errorf("for (%T) was error:%s", val, err) - case !funcs.EqualData(s.Data, received): - t.Errorf("for (%T) expected and received data are not equal%s", val, info) - default: - t.Logf("for (%T) test done%s", val, info) - } + if !funcs.EqualData(s.Data, result) { + tt.Errorf("expect %s but got %s", utils.StringData(s.Data), utils.StringData(result)) + } + }) } -func (s Set) runUnmarshal(t *testing.T, f func([]byte, interface{}) error, val interface{}) { - if s.IssueUnmarshal != "" { - t.Logf("\nunmarshal test skipped bacause there is unsolved issue:\n%s", s.IssueUnmarshal) - return - } +func (s Set) runUnmarshal(t *testing.T, f func([]byte, interface{}) error, expected interface{}) { + t.Run("unmarshal", func(tt *testing.T) { + if s.IssueUnmarshal != "" { + t.Skipf("skipped bacause there is unsolved issue: %s", s.IssueUnmarshal) + } - inputVal := funcs.New(val) - inValStr := valStr(inputVal) - inValPtr := ptrStr(inputVal) + result := funcs.New(expected) + inValPtr := utils.StringPointer(result) - err := func() (err error) { - defer func() { - if r := recover(); r != nil { - err = utils.PanicErr{Err: r.(error), Stack: debug.Stack()} - } + err := func() (err error) { + defer func() { + if r := recover(); r != nil { + err = utils.PanicErr{Err: r.(error), Stack: debug.Stack()} + } + }() + return f(bytes.Clone(s.Data), result) }() - return f(bytes.Clone(s.Data), inputVal) - }() - if err != nil { - t.Errorf("for (%T) was error:%s", val, err) - return - } - outValStr := valStr(deRef(inputVal)) - if outValPtr := ptrStr(inputVal); inValPtr != "" && outValPtr != "" && inValPtr != outValPtr { - t.Errorf("for (%T) unmarshal function rewrites existing pointer", val) - return - } + if err != nil { + tt.Fatalf("unmarshal unexpectedly failed with error: %w", err) + } - result := "" - if expectedStr := valStr(val); len(expectedStr)+len(inValStr)+len(outValStr) < utils.PrintLimit*3 { - result = fmt.Sprintf("\n expected:%s\nunmarshal in:%s\nunmarshal out:%s", expectedStr, inValStr, outValStr) - } + if outValPtr := utils.StringPointer(result); inValPtr != "" && outValPtr != "" && inValPtr != outValPtr { + tt.Fatalf("for (%T) unmarshal function rewrites existing pointer", expected) + } - if !funcs.EqualVals(val, deRef(inputVal)) { - t.Errorf("for (%T) expected and received values are not equal%s", val, result) - } else { - t.Logf("for (%T) test done%s", val, result) - } + if !funcs.EqualVals(expected, utils.DeReference(result)) { + tt.Errorf("expect %s but got %s", utils.StringValue(expected), utils.StringValue(result)) + } + }) } diff --git a/marshal/tests/serialization/utils.go b/marshal/tests/serialization/utils.go deleted file mode 100644 index 1e158afdb..000000000 --- a/marshal/tests/serialization/utils.go +++ /dev/null @@ -1,23 +0,0 @@ -package serialization - -import ( - "github.com/gocql/gocql/marshal/tests/utils" -) - -func deRef(in interface{}) interface{} { - return utils.DeReference(in) -} - -func dataStr(p []byte) string { - return utils.StringData(p) -} - -func valStr(in interface{}) string { - out := utils.StringValue(in) - if len(out) > utils.PrintLimit { - return out[:utils.PrintLimit] - } - return out -} - -func ptrStr(in interface{}) string { return utils.StringPointer(in) } diff --git a/marshal/tests/utils/selected.go b/marshal/tests/utils/selected.go deleted file mode 100644 index c7f63780c..000000000 --- a/marshal/tests/utils/selected.go +++ /dev/null @@ -1,24 +0,0 @@ -package utils - -type Selected []bool - -func (l *Selected) Len() int { - return len(*l) -} - -func (l *Selected) IsSelected(id int) bool { - return (*l)[id] -} - -func (l *Selected) SetSelected(id int) { - (*l)[id] = true -} - -func (l *Selected) AllSelected(ids []int) bool { - for _, id := range ids { - if l.IsSelected(id) { - return true - } - } - return false -} diff --git a/marshal/tests/utils/string.go b/marshal/tests/utils/string.go index 524633077..3e039d5d7 100644 --- a/marshal/tests/utils/string.go +++ b/marshal/tests/utils/string.go @@ -5,8 +5,7 @@ import ( "reflect" ) -const SoloRunMsg = "SoloRun is true, please remove it after finished tuning" -const PrintLimit = 100 +const printLimit = 100 func StringPointer(i interface{}) string { rv := reflect.ValueOf(i) @@ -23,8 +22,8 @@ func StringPointer(i interface{}) string { } func StringData(p []byte) string { - if p == nil { - return "[nil]" + if len(p) > printLimit { + p = p[:printLimit] } return fmt.Sprintf("[%x]", p) } diff --git a/marshal/tests/utils/string_vals.go b/marshal/tests/utils/string_vals.go index da0256afa..86d7d4063 100644 --- a/marshal/tests/utils/string_vals.go +++ b/marshal/tests/utils/string_vals.go @@ -8,28 +8,20 @@ import ( "time" ) -func ValueNames(vals []interface{}) []string { - names := make([]string, 0, len(vals)) - if len(vals) == 1 { - names = append(names, fmt.Sprintf("(%T)", vals[0])) - } else { - for i := range vals { - names = append(names, valStrLim(100, vals[i])) - } +func ValueToName(in interface{}) string { + valStr := stringValue(in) + if len(valStr) > printLimit { + valStr = valStr[:printLimit] } - return names + return fmt.Sprintf("%s", valStr) } func StringValue(in interface{}) string { - return fmt.Sprintf("(%T)(%s)", in, stringValue(in)) -} - -func valStrLim(lim int, in interface{}) string { - out := StringValue(in) - if len(out) > lim { - return out[:lim] + valStr := stringValue(in) + if len(valStr) > printLimit { + valStr = valStr[:printLimit] } - return out + return fmt.Sprintf("(%T)(%s)", in, valStr) } func stringValue(in interface{}) string { diff --git a/marshal/tests/utils/utils.go b/marshal/tests/utils/utils.go index a08e741d6..dcdd5d024 100644 --- a/marshal/tests/utils/utils.go +++ b/marshal/tests/utils/utils.go @@ -7,20 +7,3 @@ import ( func DeReference(in interface{}) interface{} { return reflect.Indirect(reflect.ValueOf(in)).Interface() } - -func AppendNotNil(ins []interface{}, in interface{}) []interface{} { - if in != nil { - ins = append(ins, in) - } - return delNils(ins) -} - -func delNils(in []interface{}) []interface{} { - out := make([]interface{}, 0) - for i := range in { - if in[i] != nil { - out = append(out, in[i]) - } - } - return out -} diff --git a/marshal_3_smallint_test.go b/marshal_3_smallint_test.go index 80ec30ec7..36c4b7b12 100644 --- a/marshal_3_smallint_test.go +++ b/marshal_3_smallint_test.go @@ -3,7 +3,6 @@ package gocql import ( "testing" - "github.com/gocql/gocql/marshal/tests/funcs" "github.com/gocql/gocql/marshal/tests/mod" "github.com/gocql/gocql/marshal/tests/serialization" ) @@ -21,89 +20,78 @@ func TestMarshalSmallint(t *testing.T) { serialization.Set{ Data: []byte("\x00\x00"), - Values: []interface{}{"0"}, - }.AddModified(mod.IntoRef).Run("[0000]str", t, marshal, unmarshal) + Values: mod.To("0").AddVariants(mod.IntoRef), + }.Run("0_str", t, marshal, unmarshal) serialization.Set{ Data: []byte("\x7f\xff"), - Values: []interface{}{"32767"}, - }.AddModified(mod.IntoRef).Run("[7fff]str", t, marshal, unmarshal) + Values: mod.To("32767").AddVariants(mod.IntoRef), + }.Run("32767_str", t, marshal, unmarshal) serialization.Set{ Data: []byte("\x80\x00"), - Values: []interface{}{"-32768"}, - }.AddModified(mod.IntoRef).Run("[8000]str", t, marshal, unmarshal) + Values: mod.To("-32768").AddVariants(mod.IntoRef), + }.Run("-32768_str", t, marshal, unmarshal) serialization.Set{ Data: nil, - Values: []interface{}{ + Values: mod.To( (*int8)(nil), (*int16)(nil), (*int32)(nil), (*int64)(nil), (*int)(nil), - (*uint8)(nil), (*uint16)(nil), (*uint32)(nil), (*uint64)(nil), (*uint)(nil)}, - }.AddModified(mod.IntoCustom).Run("[nil]refs", t, marshal, unmarshal) + (*uint8)(nil), (*uint16)(nil), (*uint32)(nil), (*uint64)(nil), (*uint)(nil), + ).AddVariants(mod.IntoCustom), + }.Run("[nil]refs", t, marshal, unmarshal) serialization.Set{ Data: nil, - Values: []interface{}{ + Values: mod.To( int8(0), int16(0), int32(0), int64(0), int(0), uint8(0), uint16(0), uint32(0), uint64(0), uint(0), - }, - }.AddModified(mod.IntoCustom).Run("unmarshal nil data", t, funcs.ExcludedMarshal, unmarshal) + ).AddVariants(mod.IntoCustom), + }.Run("unmarshal nil data", t, nil, unmarshal) serialization.Set{ Data: make([]byte, 0), - Values: []interface{}{ + Values: mod.To( int8(0), int16(0), int32(0), int64(0), int(0), uint8(0), uint16(0), uint32(0), uint64(0), uint(0), - }, - }.AddModified(mod.All...).Run("unmarshal zero data", t, funcs.ExcludedMarshal, unmarshal) + ).AddVariants(mod.All...), + }.Run("unmarshal zero data", t, nil, unmarshal) serialization.Set{ Data: []byte("\x00\x00"), - Values: []interface{}{ + Values: mod.To( int8(0), int16(0), int32(0), int64(0), int(0), uint8(0), uint16(0), uint32(0), uint64(0), uint(0), - }, - }.AddModified(mod.All...).Run("zeros", t, marshal, unmarshal) + ).AddVariants(mod.All...), + }.Run("zeros", t, marshal, unmarshal) serialization.Set{ - Data: []byte("\x7f\xff"), - Values: []interface{}{ - int16(32767), int32(32767), int64(32767), int(32767), - }, - }.AddModified(mod.All...).Run("32767", t, marshal, unmarshal) + Data: []byte("\x7f\xff"), + Values: mod.To(int16(32767), int32(32767), int64(32767), int(32767)).AddVariants(mod.All...), + }.Run("", t, marshal, unmarshal) serialization.Set{ - Data: []byte("\x00\x7f"), - Values: []interface{}{ - int8(127), int16(127), int32(127), int64(127), int(127), - }, - }.AddModified(mod.All...).Run("127", t, marshal, unmarshal) + Data: []byte("\x00\x7f"), + Values: mod.To(int8(127), int16(127), int32(127), int64(127), int(127)).AddVariants(mod.All...), + }.Run("", t, marshal, unmarshal) serialization.Set{ - Data: []byte("\xff\x80"), - Values: []interface{}{ - int8(-128), int16(-128), int32(-128), int64(-128), int(-128), - }, - }.AddModified(mod.All...).Run("-128", t, marshal, unmarshal) + Data: []byte("\xff\x80"), + Values: mod.To(int8(-128), int16(-128), int32(-128), int64(-128), int(-128)).AddVariants(mod.All...), + }.Run("", t, marshal, unmarshal) serialization.Set{ - Data: []byte("\x80\x00"), - Values: []interface{}{ - int16(-32768), int32(-32768), int64(-32768), int(-32768), - }, - }.AddModified(mod.All...).Run("-32768", t, marshal, unmarshal) + Data: []byte("\x80\x00"), + Values: mod.To(int16(-32768), int32(-32768), int64(-32768), int(-32768)).AddVariants(mod.All...), + }.Run("", t, marshal, unmarshal) serialization.Set{ - Data: []byte("\x00\xff"), - Values: []interface{}{ - uint8(255), uint16(255), uint32(255), uint64(255), uint(255), - }, - }.AddModified(mod.All...).Run("255", t, marshal, unmarshal) + Data: []byte("\x00\xff"), + Values: mod.To(uint8(255), uint16(255), uint32(255), uint64(255), uint(255)).AddVariants(mod.All...), + }.Run("", t, marshal, unmarshal) serialization.Set{ - Data: []byte("\xff\xff"), - Values: []interface{}{ - uint16(65535), uint32(65535), uint64(65535), uint(65535), - }, - }.AddModified(mod.All...).Run("65535", t, marshal, unmarshal) + Data: []byte("\xff\xff"), + Values: mod.To(uint16(65535), uint32(65535), uint64(65535), uint(65535)).AddVariants(mod.All...), + }.Run("65535", t, marshal, unmarshal) }