作者 yangfu

fix: file name error

package domain
import (
"path"
"path/filepath"
"strings"
"time"
)
... ... @@ -58,8 +58,13 @@ func (file *File) Update(data map[string]interface{}) error {
}
func FileName(fileName string) string {
if len(fileName) == 0 {
return ""
}
base := filepath.Base(fileName)
return strings.Split(base, ".")[0]
suffix := path.Ext(fileName)
prefix := base[0 : len(base)-len(suffix)]
return prefix
}
func (file *File) CopyTo(fileType FileType, ctx *Context) *File {
... ...
package domain
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestFileName(t *testing.T) {
inputs := []struct {
input string
want string
}{
{
input: "device/sdk/CMakeLists.txt",
want: "CMakeLists",
},
{
input: "",
want: "",
},
{
input: "CMakeLists.txt",
want: "CMakeLists",
},
{
input: "d:\\CMakeLists.txt",
want: "CMakeLists",
},
}
for _, input := range inputs {
got := FileName(input.input)
assert.Equal(t, input.want, got)
}
}
... ...