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