Repository navigation
Expand file tree
/
Copy pathparse_test.go
More file actions
120 lines (115 loc) · 2.06 KB
/
Copy pathparse_test.go
File metadata and controls
120 lines (115 loc) · 2.06 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package roghfs
import (
"fmt"
"testing"
)
func Test_Roghfs_Parse_failure(t *testing.T) {
testCases := []struct {
str string
mat func(error) bool
}{
// Case 000
{
str: "",
mat: IsInvalidRepositoryUrl,
},
// Case 001
{
str: " ",
mat: IsInvalidRepositoryUrl,
},
// Case 002
{
str: "http://github.com/owner/name",
mat: IsInvalidRepositoryUrl,
},
// Case 003
{
str: "https://example.com/foo/bar",
mat: IsInvalidRepositoryUrl,
},
// Case 004
{
str: "https://github.com/owner",
mat: IsInvalidRepositoryUrl,
},
// Case 005
{
str: "https://github.com/owner/name/extra",
mat: IsInvalidRepositoryUrl,
},
// Case 006
{
str: "https://github.com//name",
mat: IsInvalidRepositoryUrl,
},
// Case 007
{
str: "https://github.com/owner/",
mat: IsInvalidRepositoryUrl,
},
// Case 008
{
str: "https://github.com/owner/name?foo=bar",
mat: IsInvalidRepositoryUrl,
},
// Case 009
{
str: "https://github.com/owner/name#frag",
mat: IsInvalidRepositoryUrl,
},
// Case 010
{
str: "https://github.com/alpha/one.git",
mat: IsInvalidRepositoryUrl,
},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("%03d", i), func(t *testing.T) {
_, _, err := Parse(tc.str)
if !tc.mat(err) {
t.Fatal("expected", true, "got", err)
}
})
}
}
func Test_Roghfs_Parse_success(t *testing.T) {
testCases := []struct {
str string
own string
rep string
}{
// Case 000
{
str: "https://github.com/alpha/one",
own: "alpha",
rep: "one",
},
// Case 001
{
str: "https://github.com/beta/two/",
own: "beta",
rep: "two",
},
// Case 002
{
str: " https://github.com/gamma/three ",
own: "gamma",
rep: "three",
},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("%03d", i), func(t *testing.T) {
own, rep, err := Parse(tc.str)
if err != nil {
t.Fatal("expected", nil, "got", err)
}
if own != tc.own {
t.Fatal("expected", tc.own, "got", own)
}
if rep != tc.rep {
t.Fatal("expected", tc.rep, "got", rep)
}
})
}
}