From 2887d66a939b3b8d7e84d9c71c0a86d5132b5e54 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Tue, 21 Sep 2021 16:29:44 +0200 Subject: change recipe into a generic slice patch/diff package --- slice/slice_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 slice/slice_test.go (limited to 'slice/slice_test.go') diff --git a/slice/slice_test.go b/slice/slice_test.go new file mode 100644 index 0000000..b73946e --- /dev/null +++ b/slice/slice_test.go @@ -0,0 +1,21 @@ +package slice + +import ( + "testing" + + "github.com/n-peugnet/dna-backup/testutils" +) + +func TestPatch(t *testing.T) { + source := Slice{1, 2, 3, 4} + target := Slice{2, 5, 3, 6, 4, 7, 8} + patch := DiffSlice(source, target) + testutils.AssertSame(t, []SliceDel{0}, patch.Del, "Patch del part") + testutils.AssertSame(t, []SliceIns{ + {1, Slice{5}}, + {3, Slice{6}}, + {5, Slice{7, 8}}, + }, patch.Ins, "Patch ins part") + actual := PatchSlice(source, patch) + testutils.AssertSame(t, target, actual, "Target obtained from patch application") +} -- cgit v1.2.3