mirror of
https://github.com/itchyny/mmv.git
synced 2025-12-26 14:14:57 +08:00
return error on empty path
This commit is contained in:
parent
8d8905510f
commit
0e578e6b83
2 changed files with 33 additions and 0 deletions
9
mmv.go
9
mmv.go
|
|
@ -25,6 +25,12 @@ type rename struct {
|
|||
src, dst string
|
||||
}
|
||||
|
||||
type emptyPathError struct{}
|
||||
|
||||
func (err *emptyPathError) Error() string {
|
||||
return "empty path error"
|
||||
}
|
||||
|
||||
type sameDestinationError struct {
|
||||
path string
|
||||
}
|
||||
|
|
@ -38,6 +44,9 @@ func buildRenames(files map[string]string) ([]rename, error) {
|
|||
vs := make(map[string]int, len(files))
|
||||
revs := make(map[string]string, len(files))
|
||||
for src, dst := range files {
|
||||
if src == "" || dst == "" {
|
||||
return nil, &emptyPathError{}
|
||||
}
|
||||
if _, ok := revs[dst]; ok {
|
||||
return nil, &sameDestinationError{dst}
|
||||
}
|
||||
|
|
|
|||
24
mmv_test.go
24
mmv_test.go
|
|
@ -132,6 +132,30 @@ func TestMove(t *testing.T) {
|
|||
"foo": "2",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty source path error",
|
||||
files: map[string]string{
|
||||
"foo": "baz",
|
||||
"": "baz",
|
||||
},
|
||||
contents: map[string]string{
|
||||
"foo": "0",
|
||||
"bar": "1",
|
||||
},
|
||||
err: &emptyPathError{},
|
||||
},
|
||||
{
|
||||
name: "empty destination path error",
|
||||
files: map[string]string{
|
||||
"foo": "baz",
|
||||
"bar": "",
|
||||
},
|
||||
contents: map[string]string{
|
||||
"foo": "0",
|
||||
"bar": "1",
|
||||
},
|
||||
err: &emptyPathError{},
|
||||
},
|
||||
{
|
||||
name: "same destination error",
|
||||
files: map[string]string{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue