From 1b29f83c7f9f8afa4f1ab247513bcacc2507156f Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Wed, 22 Sep 2021 14:37:55 +0200 Subject: fix slice.Patch with empty delta --- slice/slice.go | 1 + slice/slice_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+) (limited to 'slice') diff --git a/slice/slice.go b/slice/slice.go index 6d7cf10..05441c8 100644 --- a/slice/slice.go +++ b/slice/slice.go @@ -46,6 +46,7 @@ func Patch(source Slice, delta Delta) (target Slice) { fill += len(ins.Value) prev = ins.Idx + len(ins.Value) } + copy(target[fill:], temp[tpos:]) return } diff --git a/slice/slice_test.go b/slice/slice_test.go index f6aecbc..0cf1c40 100644 --- a/slice/slice_test.go +++ b/slice/slice_test.go @@ -19,3 +19,13 @@ func TestPatch(t *testing.T) { actual := Patch(source, patch) testutils.AssertSame(t, target, actual, "Target obtained from patch application") } + +func TestEmptyPatch(t *testing.T) { + source := Slice{1, 2, 3, 4} + target := Slice{1, 2, 3, 4} + patch := Diff(source, target) + testutils.AssertSame(t, *new([]Del), patch.Del, "Patch del part") + testutils.AssertSame(t, *new([]Ins), patch.Ins, "Patch ins part") + actual := Patch(source, patch) + testutils.AssertSame(t, target, actual, "Target obtained from patch application") +} -- cgit v1.2.3