-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdelta_apply_test.go
63 lines (59 loc) · 1.35 KB
/
delta_apply_test.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// -----------------------------------------------------------------------------
// github.com/balacode/go-delta go-delta/[delta_apply_test.go]
// (c) balarabe@protonmail.com License: MIT
// -----------------------------------------------------------------------------
package delta
import (
"bytes"
"testing"
)
// go test --run Test_Delta_Apply_
func Test_Delta_Apply_(t *testing.T) {
if PrintTestNames {
printTestName()
}
test := func(src []byte, d Delta, expect []byte) {
result, err := d.Apply(src)
if err != nil {
t.Errorf("\n encountered error: %s\n", err)
return
}
if !bytes.Equal(result, expect) {
t.Errorf("\n expect:\n\t%v\n\t'%s'\n result:\n\t%v\n\t'%s'\n",
expect, expect, result, result)
}
}
test(
// source:
nil,
//
// delta:
Delta{
sourceHash: nil,
targetHash: makeHash(ab("abc")),
parts: []deltaPart{
{sourceLoc: -1, size: 3, data: ab("abc")},
},
},
// expect:
ab("abc"),
)
test(
// source:
ab("abc"),
//
// delta:
Delta{
sourceHash: makeHash(ab("abc")),
sourceSize: 3,
targetHash: makeHash(ab("abc")),
targetSize: 3,
parts: []deltaPart{
{sourceLoc: -1, size: 3, data: ab("abc")},
},
},
// expect:
ab("abc"),
)
} // Test_Delta_Apply_
// end