mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
237a098526
It's required because: - go.mod file can contain comments - easyjson should respect comments and be able to parse go.mod This commit replaces the logic of parsing go.mod file with the original one from golang.org/x/mod/modfile package. Tests have been introduced to check the behavior of `getModulePath` function. Ref: - https://golang.org/cmd/go/#hdr-The_go_mod_file
40 lines
999 B
Go
40 lines
999 B
Go
package parser
|
|
|
|
import "testing"
|
|
|
|
func Test_getModulePath(t *testing.T) {
|
|
tests := map[string]struct {
|
|
goModPath string
|
|
want string
|
|
}{
|
|
"valid go.mod without comments and deps": {
|
|
goModPath: "./testdata/default.go.mod",
|
|
want: "example.com/user/project",
|
|
},
|
|
"valid go.mod with comments and without deps": {
|
|
goModPath: "./testdata/comments.go.mod",
|
|
want: "example.com/user/project",
|
|
},
|
|
"valid go.mod with comments and deps": {
|
|
goModPath: "./testdata/comments_deps.go.mod",
|
|
want: "example.com/user/project",
|
|
},
|
|
"actual easyjson go.mod": {
|
|
goModPath: "../go.mod",
|
|
want: "github.com/mailru/easyjson",
|
|
},
|
|
"invalid go.mod with missing module": {
|
|
goModPath: "./testdata/missing_module.go",
|
|
want: "",
|
|
},
|
|
}
|
|
for name := range tests {
|
|
tt := tests[name]
|
|
t.Run(name, func(t *testing.T) {
|
|
if got := getModulePath(tt.goModPath); got != tt.want {
|
|
t.Errorf("getModulePath() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|