aboutsummaryrefslogtreecommitdiff
path: root/internal/pathutil/pathutil_test.go
blob: eb8cc176302dbca67e8bacda8f06c53224ccbae1 (plain)
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
// Copyright 2020 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package pathutil

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestClean(t *testing.T) {
	tests := []struct {
		path   string
		expVal string
	}{
		{
			path:   "../../../readme.txt",
			expVal: "readme.txt",
		},
		{
			path:   "a/../../../readme.txt",
			expVal: "readme.txt",
		},
		{
			path:   "/../a/b/../c/../readme.txt",
			expVal: "a/readme.txt",
		},
		{
			path:   "/a/readme.txt",
			expVal: "a/readme.txt",
		},
		{
			path:   "/",
			expVal: "",
		},

		{
			path:   "/a/b/c/readme.txt",
			expVal: "a/b/c/readme.txt",
		},
	}
	for _, test := range tests {
		t.Run("", func(t *testing.T) {
			assert.Equal(t, test.expVal, Clean(test.path))
		})
	}
}