2022-04-15 09:42:07 +02:00
|
|
|
package clean
|
2021-12-14 20:01:39 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPath(t *testing.T) {
|
|
|
|
t.Run("ValidPath", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism", Path("/go/src/github.com/photoprism/photoprism"))
|
|
|
|
})
|
|
|
|
t.Run("ValidFile", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "filename.TXT", Path("filename.TXT"))
|
|
|
|
})
|
|
|
|
t.Run("The quick brown fox.", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "The quick brown fox.", Path("The quick brown fox."))
|
|
|
|
})
|
|
|
|
t.Run("filename.txt", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "filename.txt", Path("filename.txt"))
|
|
|
|
})
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "", Path(""))
|
|
|
|
})
|
|
|
|
t.Run("Dot", func(t *testing.T) {
|
|
|
|
assert.Equal(t, ".", Path("."))
|
|
|
|
})
|
|
|
|
t.Run("DotDot", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "", Path(".."))
|
|
|
|
})
|
|
|
|
t.Run("DotDotDot", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "", Path("..."))
|
|
|
|
})
|
|
|
|
t.Run("Replace", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "", Path("${https://<host>:<port>/<path>}"))
|
|
|
|
})
|
2023-06-26 15:57:56 +02:00
|
|
|
t.Run("Control Character", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "filename.", Path("filename."+string(rune(127))))
|
|
|
|
})
|
|
|
|
t.Run("Special Chars", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "filename.", Path("filename.?**"))
|
|
|
|
})
|
2023-09-20 17:13:25 +02:00
|
|
|
t.Run("IncludesHash", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "1970-05 (Tray #005) to 3-78 Person-Abbrev Place", Path("1970-05 (Tray #005) to 3-78 Person-Abbrev Place"))
|
|
|
|
})
|
|
|
|
t.Run("StartsWithHash", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "#2020", Path("#2020"))
|
|
|
|
})
|
2021-12-14 20:01:39 +01:00
|
|
|
}
|
2022-09-30 00:42:19 +02:00
|
|
|
|
|
|
|
func TestUserPath(t *testing.T) {
|
|
|
|
t.Run("ValidPath", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "go/src/github.com/photoprism/photoprism", UserPath("/go/src/github.com/photoprism/photoprism"))
|
|
|
|
})
|
|
|
|
t.Run("ValidFile", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "filename.TXT", UserPath("filename.TXT"))
|
|
|
|
})
|
|
|
|
t.Run("The quick brown fox.", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "The quick brown fox", UserPath("The quick brown fox."))
|
|
|
|
})
|
|
|
|
t.Run("filename.txt", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "filename.txt", UserPath("filename.txt"))
|
|
|
|
})
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "", UserPath(""))
|
|
|
|
})
|
|
|
|
t.Run("Dot", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "", UserPath("."))
|
|
|
|
})
|
|
|
|
t.Run("DotDot", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "", UserPath(".."))
|
|
|
|
})
|
|
|
|
t.Run("DotDotDot", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "", UserPath("..."))
|
|
|
|
})
|
|
|
|
t.Run("Replace", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "", UserPath("${https://<host>:<port>/<path>}"))
|
|
|
|
})
|
2023-09-20 17:13:25 +02:00
|
|
|
t.Run("IncludesHash", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "1970-05 (Tray #005) to 3-78 Person-Abbrev Place", UserPath("1970-05 (Tray #005) to 3-78 Person-Abbrev Place"))
|
|
|
|
})
|
|
|
|
t.Run("StartsWithHash", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "#2020", UserPath("#2020"))
|
|
|
|
})
|
2022-09-30 00:42:19 +02:00
|
|
|
t.Run("Unclean", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "foo/bar/baz", UserPath("/foo/bar/baz/"))
|
|
|
|
assert.Equal(t, "dirty/path", UserPath("/dirty/path/"))
|
|
|
|
assert.Equal(t, "dev.txt", UserPath("dev.txt"))
|
|
|
|
assert.Equal(t, "", UserPath("../hello/foo/bar/../todo.txt"))
|
|
|
|
assert.Equal(t, "hello/foo/bar/todo.txt", UserPath(". ./hello/foo/bar/./todo.txt"))
|
|
|
|
assert.Equal(t, "", UserPath("./hello/foo/./bar/. ./todo.txt"))
|
|
|
|
assert.Equal(t, "", UserPath(".."))
|
|
|
|
assert.Equal(t, "", UserPath("."))
|
|
|
|
assert.Equal(t, "", UserPath("/"))
|
|
|
|
assert.Equal(t, "", UserPath(""))
|
|
|
|
})
|
|
|
|
}
|