gunk-dev/the-valley

behind_test.go

source88a5a486b52fmain's published tip history
1.5 KiB
1package github
2
3import "testing"
4
5func TestParseBehindBy(t *testing.T) {
6 tests := []struct {
7 name string
8 in string
9 want int
10 }{
11 {"zero", "0", 0},
12 {"positive", "2", 2},
13 {"trailing newline", "5\n", 5},
14 {"surrounding whitespace", " 3 \n", 3},
15 {"empty", "", 0},
16 {"non-numeric", "null", 0},
17 }
18 for _, tt := range tests {
19 t.Run(tt.name, func(t *testing.T) {
20 if got := parseBehindBy(tt.in); got != tt.want {
21 t.Errorf("parseBehindBy(%q) = %d, want %d", tt.in, got, tt.want)
22 }
23 })
24 }
25}
26
27func TestParseRefsLine(t *testing.T) {
28 tests := []struct {
29 name string
30 in string
31 wantBase, wantHead, wantOwn string
32 wantOK bool
33 }{
34 {"same-repo", "main\tfeature\t", "main", "feature", "", true},
35 {"fork", "main\tfeature\tforkowner", "main", "feature", "forkowner", true},
36 {"trailing newline", "main\tfeature\t\n", "main", "feature", "", true},
37 {"missing head", "main\t\t", "", "", "", false},
38 {"missing base", "\tfeature\t", "", "", "", false},
39 {"blank", "", "", "", "", false},
40 {"single field", "main", "", "", "", false},
41 }
42 for _, tt := range tests {
43 t.Run(tt.name, func(t *testing.T) {
44 base, head, own, ok := parseRefsLine(tt.in)
45 if base != tt.wantBase || head != tt.wantHead || own != tt.wantOwn || ok != tt.wantOK {
46 t.Errorf("parseRefsLine(%q) = (%q,%q,%q,%v), want (%q,%q,%q,%v)",
47 tt.in, base, head, own, ok, tt.wantBase, tt.wantHead, tt.wantOwn, tt.wantOK)
48 }
49 })
50 }
51}