11
"github.com/stretchr/testify/assert"
14
func TestFileURLToPath(t *testing.T) {
28
url: "http://test.io",
38
url: "file:///C:/path",
44
for n, c := range cases {
45
if c.windows && runtime.GOOS != "windows" {
48
u, _ := url.Parse(c.url)
49
p, err := FileURLToPath(u)
51
assert.Error(t, err, "case %d: should return error", n)
53
assert.NoError(t, err, "case %d: should not return error", n)
54
assert.Equal(t, c.expected, p, "case %d: should be equal", n)
59
func TestMisc_IsReadmeFileName(t *testing.T) {
60
trueTestCases := []string{
67
falseTestCases := []string{
73
"abcdefghijklmnopqrstuvwxyz",
78
for _, testCase := range trueTestCases {
79
assert.True(t, IsReadmeFileName(testCase))
81
for _, testCase := range falseTestCases {
82
assert.False(t, IsReadmeFileName(testCase))
85
type extensionTestcase struct {
91
exts := []string{".md", ".txt", ""}
92
testCasesExtensions := []extensionTestcase{
133
for _, testCase := range testCasesExtensions {
134
idx, ok := IsReadmeFileExtension(testCase.name, exts...)
135
assert.Equal(t, testCase.expected, ok)
136
assert.Equal(t, testCase.idx, idx)
140
func TestCleanPath(t *testing.T) {
147
{[]string{`..`}, `.`},
148
{[]string{`a`}, `a`},
149
{[]string{`/a/`}, `a`},
150
{[]string{`../a/`, `../b`, `c/..`, `d`}, `a/b/d`},
151
{[]string{`a\..\b`}, `a\..\b`},
152
{[]string{`a`, ``, `b`}, `a/b`},
153
{[]string{`a`, `..`, `b`}, `a/b`},
154
{[]string{`lfs`, `repo/..`, `user/../path`}, `lfs/path`},
156
for _, c := range cases {
157
assert.Equal(t, c.expected, PathJoinRel(c.elems...), "case: %v", c.elems)
166
{[]string{`..`}, `.`},
167
{[]string{`a`}, `a`},
168
{[]string{`/a/`}, `a`},
169
{[]string{`../a/`, `../b`, `c/..`, `d`}, `a/b/d`},
170
{[]string{`a\..\b`}, `b`},
171
{[]string{`a`, ``, `b`}, `a/b`},
172
{[]string{`a`, `..`, `b`}, `a/b`},
173
{[]string{`lfs`, `repo/..`, `user/../path`}, `lfs/path`},
175
for _, c := range cases {
176
assert.Equal(t, c.expected, PathJoinRelX(c.elems...), "case: %v", c.elems)
185
{[]string{`C:\..`}, `C:\`},
186
{[]string{`C:\a`}, `C:\a`},
187
{[]string{`C:\a/`}, `C:\a`},
188
{[]string{`C:\..\a\`, `../b`, `c\..`, `d`}, `C:\a\b\d`},
189
{[]string{`C:\a/..\b`}, `C:\b`},
190
{[]string{`C:\a`, ``, `b`}, `C:\a\b`},
191
{[]string{`C:\a`, `..`, `b`}, `C:\a\b`},
192
{[]string{`C:\lfs`, `repo/..`, `user/../path`}, `C:\lfs\path`},
199
{[]string{`/..`}, `/`},
200
{[]string{`/a`}, `/a`},
201
{[]string{`/a/`}, `/a`},
202
{[]string{`/../a/`, `../b`, `c/..`, `d`}, `/a/b/d`},
203
{[]string{`/a\..\b`}, `/b`},
204
{[]string{`/a`, ``, `b`}, `/a/b`},
205
{[]string{`/a`, `..`, `b`}, `/a/b`},
206
{[]string{`/lfs`, `repo/..`, `user/../path`}, `/lfs/path`},
209
for _, c := range cases {
210
assert.Equal(t, c.expected, FilePathJoinAbs(c.elems[0], c.elems[1:]...), "case: %v", c.elems)