Debian Codegraph @

commands/patch/apply_test.go

raw
1 package patch
2
3 import (
4 "reflect"
5 "testing"
6 )
7
8 func TestPatchApply_ProposeName(t *testing.T) {
9 tests := []struct {
10 name string
11 exist []string
12 subjects []string
13 want []string
14 }{
15 {
16 name: "base case",
17 exist: nil,
18 subjects: []string{
19 "[PATCH aerc v3 3/3] notmuch: remove unused code",
20 "[PATCH aerc v3 2/3] notmuch: replace notmuch library with internal bindings",
21 "[PATCH aerc v3 1/3] notmuch: add notmuch bindings",
22 },
23 want: []string{"notmuch_v3"},
24 },
25 {
26 name: "distorted case",
27 exist: nil,
28 subjects: []string{
29 "[PATCH vaerc v3 3/3] notmuch: remove unused code",
30 "[PATCH aerc 3v 2/3] notmuch: replace notmuch library with internal bindings",
31 },
32 want: []string{"notmuch_v1", "notmuch_v3"},
33 },
34 {
35 name: "invalid patches",
36 exist: nil,
37 subjects: []string{
38 "notmuch: remove unused code",
39 ": replace notmuch library with internal bindings",
40 },
41 want: nil,
42 },
43 }
44
45 for _, test := range tests {
46 got := proposePatchName(test.exist, test.subjects)
47 if !reflect.DeepEqual(got, test.want) {
48 t.Errorf("test '%s' failed to propose the correct "+
49 "name: got '%v', but want '%v'", test.name,
50 got, test.want)
51 }
52 }
53 }