aboutsummaryrefslogtreecommitdiff
path: root/slice/slice_test.go
blob: 0cf1c406750358e69cd3603c33db79f5b03c3803 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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 := Diff(source, target)
	testutils.AssertSame(t, []Del{0}, patch.Del, "Patch del part")
	testutils.AssertSame(t, []Ins{
		{1, Slice{5}},
		{3, Slice{6}},
		{5, Slice{7, 8}},
	}, patch.Ins, "Patch ins part")
	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")
}