| 1 |
//go:build unix |
| 2 |
// +build unix |
| 3 |
|
| 4 |
package utils |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
) |
| 9 |
|
| 10 |
func TestSourceDir(t *testing.T) { |
| 11 |
cases := []struct { |
| 12 |
file string |
| 13 |
want string |
| 14 |
}{ |
| 15 |
{ |
| 16 |
file: "/Users/name/go/pkg/mod/gorm.io/[email protected]/utils/utils.go", |
| 17 |
want: "/Users/name/go/pkg/mod/gorm.io/", |
| 18 |
}, |
| 19 |
{ |
| 20 |
file: "/go/work/proj/gorm/utils/utils.go", |
| 21 |
want: "/go/work/proj/gorm/", |
| 22 |
}, |
| 23 |
{ |
| 24 |
file: "/go/work/proj/gorm_alias/utils/utils.go", |
| 25 |
want: "/go/work/proj/gorm_alias/", |
| 26 |
}, |
| 27 |
{ |
| 28 |
file: "/go/work/proj/my.gorm.io/[email protected]/utils/utils.go", |
| 29 |
want: "/go/work/proj/my.gorm.io/[email protected]/", |
| 30 |
}, |
| 31 |
} |
| 32 |
for _, c := range cases { |
| 33 |
s := sourceDir(c.file) |
| 34 |
if s != c.want { |
| 35 |
t.Fatalf("%s: expected %s, got %s", c.file, c.want, s) |
| 36 |
} |
| 37 |
} |
| 38 |
} |