pathutil_test.go 848 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package pathutil
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestClean(t *testing.T) {
  10. tests := []struct {
  11. path string
  12. expVal string
  13. }{
  14. {
  15. path: "../../../readme.txt",
  16. expVal: "readme.txt",
  17. },
  18. {
  19. path: "a/../../../readme.txt",
  20. expVal: "readme.txt",
  21. },
  22. {
  23. path: "/../a/b/../c/../readme.txt",
  24. expVal: "a/readme.txt",
  25. },
  26. {
  27. path: "/a/readme.txt",
  28. expVal: "a/readme.txt",
  29. },
  30. {
  31. path: "/",
  32. expVal: "",
  33. },
  34. {
  35. path: "/a/b/c/readme.txt",
  36. expVal: "a/b/c/readme.txt",
  37. },
  38. }
  39. for _, test := range tests {
  40. t.Run("", func(t *testing.T) {
  41. assert.Equal(t, test.expVal, Clean(test.path))
  42. })
  43. }
  44. }