From c47d2184b2e6a1e7dbd139ca47bb3aebcfeb754f Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Thu, 23 Sep 2021 12:03:50 +0200 Subject: add String to Delta struct and use it in logs Also switch to external package for slice_test as it was already a case of "black box testing". --- slice/slice.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'slice/slice.go') diff --git a/slice/slice.go b/slice/slice.go index 05441c8..e5b959e 100644 --- a/slice/slice.go +++ b/slice/slice.go @@ -1,6 +1,9 @@ package slice -import "reflect" +import ( + "fmt" + "reflect" +) type Slice []interface{} @@ -11,11 +14,24 @@ type Ins struct { Value []interface{} } +type insData struct { + idx int + count int +} + type Delta struct { Del []Del Ins []Ins } +func (d Delta) String() string { + data := make([]insData, len(d.Ins)) + for i, ins := range d.Ins { + data[i] = insData{ins.Idx, len(ins.Value)} + } + return fmt.Sprintf("{Del: %d Ins: %+v}", d.Del, data) +} + func Patch(source Slice, delta Delta) (target Slice) { // apply Del part from patch to source into temp size := len(source) - len(delta.Del) -- cgit v1.2.3