2020-04-06 22:09:45 +02:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2023-10-20 16:02:52 +02:00
|
|
|
func TestBasePrefix(t *testing.T) {
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "", BasePrefix("", true))
|
|
|
|
assert.Equal(t, "", BasePrefix("", false))
|
|
|
|
})
|
2020-05-08 12:01:22 +02:00
|
|
|
t.Run("Screenshot 2019-05-21 at 10.45.52.png", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
regular := BasePrefix("Screenshot 2019-05-21 at 10.45.52.png", false)
|
2020-05-08 12:01:22 +02:00
|
|
|
assert.Equal(t, "Screenshot 2019-05-21 at 10.45.52", regular)
|
2020-07-14 11:00:49 +02:00
|
|
|
stripped := BasePrefix("Screenshot 2019-05-21 at 10.45.52.png", true)
|
2020-05-18 15:45:55 +02:00
|
|
|
assert.Equal(t, "Screenshot 2019-05-21 at 10.45.52", stripped)
|
2020-04-14 14:28:47 +02:00
|
|
|
})
|
2020-05-08 12:01:22 +02:00
|
|
|
t.Run("Test.jpg", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := BasePrefix("/testdata/Test.jpg", true)
|
2020-04-14 14:28:47 +02:00
|
|
|
assert.Equal(t, "Test", result)
|
|
|
|
})
|
2020-07-11 16:46:29 +02:00
|
|
|
t.Run("Test.jpg.json", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := BasePrefix("/testdata/Test.jpg.json", true)
|
2020-07-11 16:46:29 +02:00
|
|
|
assert.Equal(t, "Test", result)
|
|
|
|
})
|
2020-04-14 14:28:47 +02:00
|
|
|
t.Run("Test copy 3.jpg", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := BasePrefix("/testdata/Test copy 3.jpg", true)
|
2020-04-14 14:28:47 +02:00
|
|
|
assert.Equal(t, "Test", result)
|
|
|
|
})
|
|
|
|
t.Run("Test (3).jpg", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := BasePrefix("/testdata/Test (3).jpg", true)
|
2020-04-14 14:28:47 +02:00
|
|
|
assert.Equal(t, "Test", result)
|
|
|
|
})
|
|
|
|
t.Run("Test.jpg", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := BasePrefix("/testdata/Test.jpg", false)
|
2020-04-14 14:28:47 +02:00
|
|
|
assert.Equal(t, "Test", result)
|
|
|
|
})
|
|
|
|
t.Run("Test.3453453.jpg", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
regular := BasePrefix("/testdata/Test.3453453.jpg", false)
|
2020-05-08 12:01:22 +02:00
|
|
|
assert.Equal(t, "Test.3453453", regular)
|
|
|
|
|
2020-07-14 11:00:49 +02:00
|
|
|
stripped := BasePrefix("/testdata/Test.3453453.jpg", true)
|
2020-05-08 12:01:22 +02:00
|
|
|
assert.Equal(t, "Test", stripped)
|
|
|
|
})
|
|
|
|
t.Run("/foo/bar.0000.ZIP", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
regular := BasePrefix("/foo/bar.0000.ZIP", false)
|
2020-05-08 12:01:22 +02:00
|
|
|
assert.Equal(t, "bar.0000", regular)
|
|
|
|
|
2020-07-14 11:00:49 +02:00
|
|
|
stripped := BasePrefix("/foo/bar.0000.ZIP", true)
|
2020-05-18 15:45:55 +02:00
|
|
|
assert.Equal(t, "bar.0000", stripped)
|
|
|
|
})
|
|
|
|
t.Run("/foo/bar.00001.ZIP", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
regular := BasePrefix("/foo/bar.00001.ZIP", false)
|
2020-05-18 15:45:55 +02:00
|
|
|
assert.Equal(t, "bar.00001", regular)
|
|
|
|
|
2020-07-14 11:00:49 +02:00
|
|
|
stripped := BasePrefix("/foo/bar.00001.ZIP", true)
|
2020-05-08 12:01:22 +02:00
|
|
|
assert.Equal(t, "bar", stripped)
|
2020-04-14 14:28:47 +02:00
|
|
|
})
|
|
|
|
t.Run("Test copy 3.jpg", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := BasePrefix("/testdata/Test copy 3.jpg", false)
|
2020-04-14 14:28:47 +02:00
|
|
|
assert.Equal(t, "Test copy 3", result)
|
|
|
|
})
|
|
|
|
t.Run("Test (3).jpg", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := BasePrefix("/testdata/Test (3).jpg", false)
|
2020-04-14 14:28:47 +02:00
|
|
|
assert.Equal(t, "Test (3)", result)
|
|
|
|
})
|
2020-06-01 09:45:24 +02:00
|
|
|
t.Run("20180506_091537_DSC02122.JPG", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := BasePrefix("20180506_091537_DSC02122.JPG", true)
|
2020-06-01 09:45:24 +02:00
|
|
|
assert.Equal(t, "20180506_091537_DSC02122", result)
|
|
|
|
})
|
|
|
|
t.Run("20180506_091537_DSC02122 (+3.3).JPG", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := BasePrefix("20180506_091537_DSC02122 (+3.3).JPG", true)
|
2020-06-01 09:45:24 +02:00
|
|
|
assert.Equal(t, "20180506_091537_DSC02122", result)
|
|
|
|
})
|
|
|
|
t.Run("20180506_091537_DSC02122 (-2.7).JPG", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := BasePrefix("20180506_091537_DSC02122 (-2.7).JPG", true)
|
2020-06-01 09:45:24 +02:00
|
|
|
assert.Equal(t, "20180506_091537_DSC02122", result)
|
|
|
|
})
|
|
|
|
t.Run("20180506_091537_DSC02122(+3.3).JPG", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := BasePrefix("20180506_091537_DSC02122(+3.3).JPG", true)
|
2020-06-01 09:45:24 +02:00
|
|
|
assert.Equal(t, "20180506_091537_DSC02122", result)
|
|
|
|
})
|
|
|
|
t.Run("20180506_091537_DSC02122(-2.7).JPG", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := BasePrefix("20180506_091537_DSC02122(-2.7).JPG", true)
|
2020-06-01 09:45:24 +02:00
|
|
|
assert.Equal(t, "20180506_091537_DSC02122", result)
|
|
|
|
})
|
2020-08-18 00:45:53 +02:00
|
|
|
t.Run("1996 001.jpg", func(t *testing.T) {
|
|
|
|
result := BasePrefix("1996 001.jpg", true)
|
|
|
|
assert.Equal(t, "1996 001", result)
|
|
|
|
})
|
2020-04-06 22:09:45 +02:00
|
|
|
}
|
|
|
|
|
2023-10-20 16:02:52 +02:00
|
|
|
func TestRelPrefix(t *testing.T) {
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "", RelPrefix("", "", true))
|
|
|
|
assert.Equal(t, "", RelPrefix("", "", false))
|
|
|
|
})
|
2020-05-31 14:42:41 +02:00
|
|
|
t.Run("/foo/bar.0000.ZIP", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
regular := RelPrefix("/foo/bar.0000.ZIP", "/bar", false)
|
2020-05-31 14:42:41 +02:00
|
|
|
assert.Equal(t, "/foo/bar.0000", regular)
|
|
|
|
|
2020-07-14 11:00:49 +02:00
|
|
|
stripped := RelPrefix("/foo/bar.0000.ZIP", "/bar", true)
|
2020-05-31 14:42:41 +02:00
|
|
|
assert.Equal(t, "/foo/bar.0000", stripped)
|
|
|
|
})
|
|
|
|
t.Run("/foo/bar.00001.ZIP", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
regular := RelPrefix("/foo/bar.00001.ZIP", "/bar", false)
|
2020-05-31 14:42:41 +02:00
|
|
|
assert.Equal(t, "/foo/bar.00001", regular)
|
|
|
|
|
2020-07-14 11:00:49 +02:00
|
|
|
stripped := RelPrefix("/foo/bar.00001.ZIP", "/bar", true)
|
2020-05-31 14:42:41 +02:00
|
|
|
assert.Equal(t, "/foo/bar", stripped)
|
|
|
|
})
|
|
|
|
t.Run("Test copy 3.jpg", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := RelPrefix("/testdata/foo/Test copy 3.jpg", "/testdata", false)
|
2020-05-31 14:42:41 +02:00
|
|
|
assert.Equal(t, "foo/Test copy 3", result)
|
|
|
|
})
|
|
|
|
t.Run("Test (3).jpg", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := RelPrefix("/testdata/foo/Test (3).jpg", "/testdata", false)
|
2020-05-31 14:42:41 +02:00
|
|
|
assert.Equal(t, "foo/Test (3)", result)
|
|
|
|
})
|
2020-07-07 15:13:42 +02:00
|
|
|
t.Run("Test (3).jpg", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := RelPrefix("/testdata/foo/Test (3).jpg", "/testdata/foo/Test (3).jpg", false)
|
2020-07-07 15:13:42 +02:00
|
|
|
assert.Equal(t, "Test (3)", result)
|
|
|
|
})
|
2020-05-31 14:42:41 +02:00
|
|
|
}
|
|
|
|
|
2023-10-20 16:02:52 +02:00
|
|
|
func TestAbsPrefix(t *testing.T) {
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "", AbsPrefix("", true))
|
|
|
|
assert.Equal(t, "", AbsPrefix("", false))
|
|
|
|
})
|
2023-10-21 15:02:16 +02:00
|
|
|
t.Run("IMG_4120", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "/foo/bar/IMG_4120", AbsPrefix("/foo/bar/IMG_4120.JPG", false))
|
|
|
|
assert.Equal(t, "/foo/bar/IMG_E4120", AbsPrefix("/foo/bar/IMG_E4120.JPG", false))
|
|
|
|
})
|
2020-04-14 14:28:47 +02:00
|
|
|
t.Run("Test copy 3.jpg", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := AbsPrefix("/testdata/Test (4).jpg", true)
|
2020-04-14 14:28:47 +02:00
|
|
|
|
|
|
|
assert.Equal(t, "/testdata/Test", result)
|
|
|
|
})
|
|
|
|
t.Run("Test (3).jpg", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
result := AbsPrefix("/testdata/Test (4).jpg", false)
|
2020-04-14 14:28:47 +02:00
|
|
|
|
|
|
|
assert.Equal(t, "/testdata/Test (4)", result)
|
|
|
|
})
|
2023-10-20 16:02:52 +02:00
|
|
|
t.Run("Sequence", func(t *testing.T) {
|
2023-10-21 15:02:16 +02:00
|
|
|
assert.Equal(t, "/foo/bar/Test", AbsPrefix("/foo/bar/Test (4).jpg", true))
|
|
|
|
assert.Equal(t, "/foo/bar/Test (4)", AbsPrefix("/foo/bar/Test (4).jpg", false))
|
2023-10-20 16:02:52 +02:00
|
|
|
})
|
|
|
|
t.Run("LowerCase", func(t *testing.T) {
|
2023-10-21 15:02:16 +02:00
|
|
|
assert.Equal(t, "/foo/bar/IMG_E4120", AbsPrefix("/foo/bar/IMG_E4120.JPG", false))
|
2023-10-20 16:02:52 +02:00
|
|
|
})
|
|
|
|
}
|