gunk-dev/the-valley

knot_test.go

sourcecaaa5bee5e11main's published tip history
1.2 KiB
1package valley
2
3import "testing"
4
5// TestParseKnotRef: --issue takes a knot only in the knot ID form, alone or
6// behind a project; anything else, a GitHub issue number included, is left
7// to GitHub.
8func TestParseKnotRef(t *testing.T) {
9 for _, tc := range []struct {
10 in string
11 want KnotRef
12 ok bool
13 }{
14 {"oc-897917f", KnotRef{ID: "oc-897917f"}, true},
15 {"bd-086ef7b", KnotRef{ID: "bd-086ef7b"}, true},
16 {"ida-0123abc", KnotRef{ID: "ida-0123abc"}, true},
17 {"qn-fedcba9", KnotRef{ID: "qn-fedcba9"}, true},
18 {"the-valley:oc-897917f", KnotRef{Project: "the-valley", ID: "oc-897917f"}, true},
19 {"42", KnotRef{}, false},
20 {"oc-897917", KnotRef{}, false}, // six digits
21 {"oc-897917fa", KnotRef{}, false}, // eight
22 {"oc-897917F", KnotRef{}, false}, // not lowercase hex
23 {"oc-89791zz", KnotRef{}, false},
24 {"xx-897917f", KnotRef{}, false},
25 {":oc-897917f", KnotRef{}, false},
26 {"a b:oc-897917f", KnotRef{}, false},
27 } {
28 got, ok := ParseKnotRef(tc.in)
29 if got != tc.want || ok != tc.ok {
30 t.Errorf("ParseKnotRef(%q) = %+v, %v; want %+v, %v", tc.in, got, ok, tc.want, tc.ok)
31 }
32 if ok && got.String() != tc.in {
33 t.Errorf("%+v.String() = %q, want %q", got, got.String(), tc.in)
34 }
35 }
36}