2022-11-05 06:52:08 +03:00
|
|
|
package utils
|
|
|
|
|
2022-11-21 05:48:13 +03:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
2022-11-05 06:52:08 +03:00
|
|
|
|
|
|
|
func TestSourceDir(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
file string
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{
|
2022-11-21 05:48:13 +03:00
|
|
|
file: `C:/Users/name/go/pkg/mod/gorm.io/gorm@v1.2.3/utils/utils.go`,
|
|
|
|
want: `C:/Users/name/go/pkg/mod/gorm.io/`,
|
2022-11-05 06:52:08 +03:00
|
|
|
},
|
|
|
|
{
|
2022-11-21 05:48:13 +03:00
|
|
|
file: `C:/go/work/proj/gorm/utils/utils.go`,
|
|
|
|
want: `C:/go/work/proj/gorm/`,
|
2022-11-05 06:52:08 +03:00
|
|
|
},
|
|
|
|
{
|
2022-11-21 05:48:13 +03:00
|
|
|
file: `C:/go/work/proj/gorm_alias/utils/utils.go`,
|
|
|
|
want: `C:/go/work/proj/gorm_alias/`,
|
2022-11-05 06:52:08 +03:00
|
|
|
},
|
|
|
|
{
|
2022-11-21 05:48:13 +03:00
|
|
|
file: `C:/go/work/proj/my.gorm.io/gorm@v1.2.3/utils/utils.go`,
|
|
|
|
want: `C:/go/work/proj/my.gorm.io/gorm@v1.2.3/`,
|
2022-11-05 06:52:08 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, c := range cases {
|
|
|
|
s := sourceDir(c.file)
|
|
|
|
if s != c.want {
|
|
|
|
t.Fatalf("%s: expected %s, got %s", c.file, c.want, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|