-
Notifications
You must be signed in to change notification settings - Fork 2
/
github_test.go
65 lines (58 loc) · 1.6 KB
/
github_test.go
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
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"testing"
)
func TestCleanupPatchTitle(t *testing.T) {
tests := []struct {
In, Out string
}{
{"", ""},
{"testing", "testing"},
{"I am a sentence.", "I-am-a-sentence"},
{`I have "quotes"`, "I-have-quotes"},
}
for _, x := range tests {
got := cleanupPatchTitle(x.In)
if got != x.Out {
t.Errorf("On %v, expected %v, got %v",
x.In, x.Out, got)
}
}
}
func TestReferencesFromGithub(t *testing.T) {
empty := []githubCBRef{}
tests := []struct {
Msg string
Res []githubCBRef
}{
{"", empty},
{"Cbugg: bug-134", []githubCBRef{{"bug-134", false}}},
{"Cbugg: close bug-134", []githubCBRef{{"bug-134", true}}},
{"Cbugg: closed bug-134", []githubCBRef{{"bug-134", true}}},
{"Did some stuff\n\nCbugg: bug-134", []githubCBRef{{"bug-134", false}}},
{"Did some stuff\n\n Cbugg: bug-134", []githubCBRef{{"bug-134", false}}},
{"Did some stuff\n\n cbugg: bug-134", []githubCBRef{{"bug-134", false}}},
{"Cbugg: close bug-134 bug-135", []githubCBRef{{"bug-134", true},
{"bug-135", true}}},
{"Cbugg: close bug-134\ncbugg: bug-135",
[]githubCBRef{{"bug-134", true}, {"bug-135", false}}},
}
for _, x := range tests {
got := extractRefsFromGithub(x.Msg)
if len(got) != len(x.Res) {
t.Errorf("On %v, expected %v, got %v",
x.Msg, x.Res, got)
continue
}
for i := range x.Res {
if got[i].bugid != x.Res[i].bugid {
t.Errorf("Expected bugid %v, got %v on %v",
x.Res[i].bugid, got[i].bugid, x.Msg)
}
if got[i].closed != x.Res[i].closed {
t.Errorf("Expected closed=%v, got %v on %v",
x.Res[i].closed, got[i].closed, x.Msg)
}
}
}
}