36 lines
569 B
Go
36 lines
569 B
Go
|
package utils
|
||
|
|
||
|
import "testing"
|
||
|
|
||
|
type CleanName struct {
|
||
|
name string
|
||
|
ext string
|
||
|
}
|
||
|
|
||
|
func TestCleanFileName(t *testing.T) {
|
||
|
|
||
|
tests := map[string]CleanName{
|
||
|
"noext": CleanName{"noext", ""},
|
||
|
"with.ext": CleanName{"with", ".ext"},
|
||
|
"path/with.ext": CleanName{"with", ".ext"},
|
||
|
"path/noext": CleanName{"noext", ""},
|
||
|
}
|
||
|
|
||
|
for name, expected := range tests {
|
||
|
|
||
|
t.Run(name, func(t *testing.T) {
|
||
|
|
||
|
resName, resExt := CleanFileName(name)
|
||
|
|
||
|
if resName != expected.name {
|
||
|
t.Fail()
|
||
|
}
|
||
|
|
||
|
if resExt != expected.ext {
|
||
|
t.Fail()
|
||
|
}
|
||
|
|
||
|
})
|
||
|
}
|
||
|
}
|