Go · 957 bytes Raw Blame History
1 // SPDX-License-Identifier: AGPL-3.0-or-later
2
3 package pulls
4
5 import (
6 "reflect"
7 "testing"
8 )
9
10 func TestParseLinkedIssues(t *testing.T) {
11 t.Parallel()
12 cases := []struct {
13 name string
14 body string
15 want []int64
16 }{
17 {"closes", "closes #1", []int64{1}},
18 {"fixes_capitalized", "Fixes #42", []int64{42}},
19 {"resolves_past_tense", "Resolved #7", []int64{7}},
20 {"multiple", "Closes #1, fixes #2, resolves #3", []int64{1, 2, 3}},
21 {"dedup", "Fixes #5\nFixes #5 again", []int64{5}},
22 {"plain_hash_does_not_match", "see #99 — does not auto-close", nil},
23 {"keyword_in_prose_no_hash", "this closes the door on bug fixes", nil},
24 {"fixed_with_extra_whitespace", "Fixed #11", []int64{11}},
25 }
26 for _, c := range cases {
27 t.Run(c.name, func(t *testing.T) {
28 got := parseLinkedIssues(c.body)
29 if !reflect.DeepEqual(got, c.want) && !(len(got) == 0 && len(c.want) == 0) {
30 t.Errorf("body %q: got %v, want %v", c.body, got, c.want)
31 }
32 })
33 }
34 }
35