Ignore whitespace when stripping sequence from filename #335

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-06-01 01:35:07 +02:00
parent 344c88b84c
commit a6e06844f3
2 changed files with 23 additions and 1 deletions

View file

@ -37,6 +37,8 @@ func Base(fileName string, stripSequence bool) string {
basename = basename[:end]
}
basename = strings.TrimSpace(basename)
return basename
}

View file

@ -67,6 +67,26 @@ func TestBase(t *testing.T) {
result := Base("/testdata/Test (3).jpg", false)
assert.Equal(t, "Test (3)", result)
})
t.Run("20180506_091537_DSC02122.JPG", func(t *testing.T) {
result := Base("20180506_091537_DSC02122.JPG", true)
assert.Equal(t, "20180506_091537_DSC02122", result)
})
t.Run("20180506_091537_DSC02122 (+3.3).JPG", func(t *testing.T) {
result := Base("20180506_091537_DSC02122 (+3.3).JPG", true)
assert.Equal(t, "20180506_091537_DSC02122", result)
})
t.Run("20180506_091537_DSC02122 (-2.7).JPG", func(t *testing.T) {
result := Base("20180506_091537_DSC02122 (-2.7).JPG", true)
assert.Equal(t, "20180506_091537_DSC02122", result)
})
t.Run("20180506_091537_DSC02122(+3.3).JPG", func(t *testing.T) {
result := Base("20180506_091537_DSC02122(+3.3).JPG", true)
assert.Equal(t, "20180506_091537_DSC02122", result)
})
t.Run("20180506_091537_DSC02122(-2.7).JPG", func(t *testing.T) {
result := Base("20180506_091537_DSC02122(-2.7).JPG", true)
assert.Equal(t, "20180506_091537_DSC02122", result)
})
}
func TestRelativeBase(t *testing.T) {