Skip to content

Commit

Permalink
Merge pull request #27 from xushiwei/q
Browse files Browse the repository at this point in the history
gopmod.Default
  • Loading branch information
xushiwei committed Oct 19, 2023
2 parents d3593e4 + d82f994 commit da58484
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gopmod/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,8 @@ func (e *MissingError) Error() string {
}

// -----------------------------------------------------------------------------

// Default represents the default gop.mod object.
var Default = New(modload.Default)

// -----------------------------------------------------------------------------
13 changes: 13 additions & 0 deletions modfile/gop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ func TestGoModCompat2(t *testing.T) {
}
}

func TestGoModStd(t *testing.T) {
const (
gopmod = "module std\n"
)
f, err := ParseLax("go.mod", []byte(gopmod), nil)
if err != nil {
t.Fatal("modfile.ParseLax failed:", err)
}
if f.Module.Mod.Path != "" {
t.Fatal("modfile.ParseLax:", f.Module.Mod.Path)
}
}

// -----------------------------------------------------------------------------

func TestParse2(t *testing.T) {
Expand Down
13 changes: 13 additions & 0 deletions modfile/regtest_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package modfile_test

import (
"testing"

"github.com/goplus/mod/gopmod"
)

func TestGopMod(t *testing.T) {
if path := gopmod.Default.Path(); path != "" {
t.Fatal("TestGopMod:", path)
}
}
3 changes: 3 additions & 0 deletions modfile/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ func parseToFile(file string, data []byte, fix VersionFixer, strict bool) (parse
err = errors.NewWith(err, `modfile.ParseLax(file, data, fix)`, -2, "modfile.ParseLax", file, data, fix)
return
}
if mod := f.Module; mod != nil && mod.Mod.Path == "std" {
mod.Mod.Path = "" // the Go std module
}
parsed = &File{File: *f}

var errs ErrorList
Expand Down
18 changes: 18 additions & 0 deletions modload/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,21 @@ func getVerb(e modfile.Expr) string {
}

// -----------------------------------------------------------------------------

const (
defaultGoVer = "1.18"
defaultGopVer = "1.1"
)

// Default represents the default gop.mod object.
var Default = Module{
File: &modfile.File{
File: gomodfile.File{
Module: &gomodfile.Module{},
Go: &gomodfile.Go{Version: defaultGoVer},
},
Gop: &modfile.Gop{Version: defaultGopVer},
},
}

// -----------------------------------------------------------------------------

0 comments on commit da58484

Please sign in to comment.