123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- // 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
- wantVal string
- }{
- {
- path: "../../../readme.txt",
- wantVal: "readme.txt",
- },
- {
- path: "a/../../../readme.txt",
- wantVal: "readme.txt",
- },
- {
- path: "/../a/b/../c/../readme.txt",
- wantVal: "a/readme.txt",
- },
- {
- path: "../../objects/info/..",
- wantVal: "objects",
- },
- {
- path: "/a/readme.txt",
- wantVal: "a/readme.txt",
- },
- {
- path: "/",
- wantVal: "",
- },
- {
- path: "/a/b/c/readme.txt",
- wantVal: "a/b/c/readme.txt",
- },
- // Windows-specific
- {
- path: `..\..\..\readme.txt`,
- wantVal: "readme.txt",
- },
- {
- path: `a\..\..\..\readme.txt`,
- wantVal: "readme.txt",
- },
- {
- path: `\..\a\b\..\c\..\readme.txt`,
- wantVal: "a/readme.txt",
- },
- {
- path: `\a\readme.txt`,
- wantVal: "a/readme.txt",
- },
- {
- path: `..\..\..\../README.md`,
- wantVal: "README.md",
- },
- {
- path: `\`,
- wantVal: "",
- },
- {
- path: `\a\b\c\readme.txt`,
- wantVal: `a/b/c/readme.txt`,
- },
- }
- for _, test := range tests {
- t.Run(test.path, func(t *testing.T) {
- assert.Equal(t, test.wantVal, Clean(test.path))
- })
- }
- }
|