internal/control/commitrefs_test.go

5460cca8a555d6d23646aebf992a3bdd82c8fee3
gitbay/internal/control/commitrefs_test.go history · blame · raw

33 lines · 960 bytes

 1package control
 2
 3import (
 4	"slices"
 5	"testing"
 6)
 7
 8// The same keyword set has to work wherever the intent is written: a
 9// commit message, or a merge request title or body.
10func TestClosingRefs(t *testing.T) {
11	for _, tc := range []struct {
12		name string
13		text string
14		want []int64
15	}{
16		{"closes", "Closes #50", []int64{50}},
17		{"lowercase and fix", "fixes #7", []int64{7}},
18		{"resolved", "resolved: #12", []int64{12}},
19		{"several", "Closes #1\n\nAlso fixes #2 and resolves #3", []int64{1, 2, 3}},
20		{"repeats collapse", "closes #4, closes #4", []int64{4}},
21		{"bare references do not close", "see #9 for context", nil},
22		{"cross-repo stays display-only", "closes krz/other#3", nil},
23		{"keyword must be its own word", "unclosed #5", nil},
24	} {
25		t.Run(tc.name, func(t *testing.T) {
26			got := closingRefs(tc.text)
27			slices.Sort(got)
28			if !slices.Equal(got, tc.want) {
29				t.Errorf("closingRefs(%q) = %v, want %v", tc.text, got, tc.want)
30			}
31		})
32	}
33}