aboutsummaryrefslogtreecommitdiffstats
path: root/commands/patch/apply_test.go
blob: 12a87c76cb57d2042d4850c877065c5b9ade7658 (plain) (blame)
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
package patch

import (
	"reflect"
	"testing"
)

func TestPatchApply_ProposeName(t *testing.T) {
	tests := []struct {
		name     string
		exist    []string
		subjects []string
		want     []string
	}{
		{
			name:  "base case",
			exist: nil,
			subjects: []string{
				"[PATCH aerc v3 3/3] notmuch: remove unused code",
				"[PATCH aerc v3 2/3] notmuch: replace notmuch library with internal bindings",
				"[PATCH aerc v3 1/3] notmuch: add notmuch bindings",
			},
			want: []string{"notmuch_v3"},
		},
		{
			name:  "distorted case",
			exist: nil,
			subjects: []string{
				"[PATCH vaerc v3 3/3] notmuch: remove unused code",
				"[PATCH aerc 3v 2/3] notmuch: replace notmuch library with internal bindings",
			},
			want: []string{"notmuch_v1", "notmuch_v3"},
		},
		{
			name:  "invalid patches",
			exist: nil,
			subjects: []string{
				"notmuch: remove unused code",
				": replace notmuch library with internal bindings",
			},
			want: nil,
		},
	}

	for _, test := range tests {
		got := proposePatchName(test.exist, test.subjects)
		if !reflect.DeepEqual(got, test.want) {
			t.Errorf("test '%s' failed to propose the correct "+
				"name: got '%v', but want '%v'", test.name,
				got, test.want)
		}
	}
}