Skip to content

Commit da58484

Browse files
authored
Merge pull request #27 from xushiwei/q
gopmod.Default
2 parents d3593e4 + d82f994 commit da58484

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

gopmod/module.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,8 @@ func (e *MissingError) Error() string {
222222
}
223223

224224
// -----------------------------------------------------------------------------
225+
226+
// Default represents the default gop.mod object.
227+
var Default = New(modload.Default)
228+
229+
// -----------------------------------------------------------------------------

modfile/gop_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,19 @@ func TestGoModCompat2(t *testing.T) {
169169
}
170170
}
171171

172+
func TestGoModStd(t *testing.T) {
173+
const (
174+
gopmod = "module std\n"
175+
)
176+
f, err := ParseLax("go.mod", []byte(gopmod), nil)
177+
if err != nil {
178+
t.Fatal("modfile.ParseLax failed:", err)
179+
}
180+
if f.Module.Mod.Path != "" {
181+
t.Fatal("modfile.ParseLax:", f.Module.Mod.Path)
182+
}
183+
}
184+
172185
// -----------------------------------------------------------------------------
173186

174187
func TestParse2(t *testing.T) {

modfile/regtest_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package modfile_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/goplus/mod/gopmod"
7+
)
8+
9+
func TestGopMod(t *testing.T) {
10+
if path := gopmod.Default.Path(); path != "" {
11+
t.Fatal("TestGopMod:", path)
12+
}
13+
}

modfile/rule.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ func parseToFile(file string, data []byte, fix VersionFixer, strict bool) (parse
118118
err = errors.NewWith(err, `modfile.ParseLax(file, data, fix)`, -2, "modfile.ParseLax", file, data, fix)
119119
return
120120
}
121+
if mod := f.Module; mod != nil && mod.Mod.Path == "std" {
122+
mod.Mod.Path = "" // the Go std module
123+
}
121124
parsed = &File{File: *f}
122125

123126
var errs ErrorList

modload/module.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,21 @@ func getVerb(e modfile.Expr) string {
266266
}
267267

268268
// -----------------------------------------------------------------------------
269+
270+
const (
271+
defaultGoVer = "1.18"
272+
defaultGopVer = "1.1"
273+
)
274+
275+
// Default represents the default gop.mod object.
276+
var Default = Module{
277+
File: &modfile.File{
278+
File: gomodfile.File{
279+
Module: &gomodfile.Module{},
280+
Go: &gomodfile.Go{Version: defaultGoVer},
281+
},
282+
Gop: &modfile.Gop{Version: defaultGopVer},
283+
},
284+
}
285+
286+
// -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)