fork of go-gitdiff with jj support
1package gitdiff
2
3import (
4 "testing"
5)
6
7func TestBase85Decode(t *testing.T) {
8 tests := map[string]struct {
9 Input string
10 Output []byte
11 Err bool
12 }{
13 "twoBytes": {
14 Input: "%KiWV",
15 Output: []byte{0xCA, 0xFE},
16 },
17 "fourBytes": {
18 Input: "007GV",
19 Output: []byte{0x0, 0x0, 0xCA, 0xFE},
20 },
21 "sixBytes": {
22 Input: "007GV%KiWV",
23 Output: []byte{0x0, 0x0, 0xCA, 0xFE, 0xCA, 0xFE},
24 },
25 "invalidCharacter": {
26 Input: "00'GV",
27 Err: true,
28 },
29 "underpaddedSequence": {
30 Input: "007G",
31 Err: true,
32 },
33 "dataUnderrun": {
34 Input: "007GV",
35 Output: make([]byte, 8),
36 Err: true,
37 },
38 }
39
40 for name, test := range tests {
41 t.Run(name, func(t *testing.T) {
42 dst := make([]byte, len(test.Output))
43 err := base85Decode(dst, []byte(test.Input))
44 if test.Err {
45 if err == nil {
46 t.Fatalf("expected error decoding base85 data, but got nil")
47 }
48 return
49 }
50 if err != nil {
51 t.Fatalf("unexpected error decoding base85 data: %v", err)
52 }
53 for i, b := range test.Output {
54 if dst[i] != b {
55 t.Errorf("incorrect byte at index %d: expected 0x%X, actual 0x%X", i, b, dst[i])
56 }
57 }
58 })
59 }
60}