Repository: goplus/gop
Pull request #1128 (2022-04-10 00:02:11)

gox v1.9.15


Patch:
diff --git a/.gitignore b/.gitignore
index 227a0dec..9aa396cf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,6 +33,8 @@ coverage.txt
 .gop/
 gop_autogen*.go
 go.json
+go.work
+go.work.sum
 format.result
 *.cache
 
diff --git a/go.mod b/go.mod
index 0254b986..77275ff6 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module github.com/goplus/gop
 go 1.16
 
 require (
-	github.com/goplus/gox v1.9.13
+	github.com/goplus/gox v1.9.15
 	github.com/qiniu/x v1.11.5
 	golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3
 )
diff --git a/go.sum b/go.sum
index 135b9393..62476315 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,5 @@
-github.com/goplus/gox v1.9.13 h1:oK5HwkqBmFDCeKfSnjph6+USSp5D/37A3coKMtx1lk4=
-github.com/goplus/gox v1.9.13/go.mod h1:gu7fuQF8RmWPZUjd+tEJGuV3m/vOEv0bHrct0x/KatM=
+github.com/goplus/gox v1.9.15 h1:a9X8sJtq9BDiH24FxRuoW7nePohz9OPApQGlkg4QRrY=
+github.com/goplus/gox v1.9.15/go.mod h1:gu7fuQF8RmWPZUjd+tEJGuV3m/vOEv0bHrct0x/KatM=
 github.com/qiniu/x v1.11.5 h1:TYr5cl4g2yoHAZeDK4MTjKF6CMoG+IHlCDvvM5qym6U=
 github.com/qiniu/x v1.11.5/go.mod h1:03Ni9tj+N2h2aKnAz+6N0Xfl8FwMEDRC2PAlxekASDs=
 github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=


Test patch:
diff --git a/cl/compile_spx_test.go b/cl/compile_spx_test.go
index 9bf77e2c..001682d9 100644
--- a/cl/compile_spx_test.go
+++ b/cl/compile_spx_test.go
@@ -70,33 +70,35 @@ func gopSpxTest(t *testing.T, gmx, spxcode, expected string) {
 }
 
 func gopSpxTestEx(t *testing.T, gmx, spxcode, expected, gmxfile, spxfile string) {
-	gopSpxTestExConf(t, gblConf, gmx, spxcode, expected, gmxfile, spxfile)
-}
-
-func gopSpxTestExConf(t *testing.T, conf *cl.Config, gmx, spxcode, expected, gmxfile, spxfile string) {
-	cl.SetDisableRecover(true)
-	defer cl.SetDisableRecover(false)
-
-	fs := newTwoFileFS("/foo", spxfile, spxcode, gmxfile, gmx)
-	pkgs, err := parser.ParseFSDir(gblFset, fs, "/foo", spxParserConf())
-	if err != nil {
-		scanner.PrintError(os.Stderr, err)
-		t.Fatal("ParseFSDir:", err)
-	}
-	bar := pkgs["main"]
-	pkg, err := cl.NewPackage("", bar, conf)
-	if err != nil {
-		t.Fatal("NewPackage:", err)
-	}
-	var b bytes.Buffer
-	err = gox.WriteTo(&b, pkg, false)
-	if err != nil {
-		t.Fatal("gox.WriteTo failed:", err)
-	}
-	result := b.String()
-	if result != expected {
-		t.Fatalf("\nResult:\n%s\nExpected:\n%s\n", result, expected)
-	}
+	gopSpxTestExConf(t, "gopSpxTest", gblConf, gmx, spxcode, expected, gmxfile, spxfile)
+}
+
+func gopSpxTestExConf(t *testing.T, name string, conf *cl.Config, gmx, spxcode, expected, gmxfile, spxfile string) {
+	t.Run(name, func(t *testing.T) {
+		cl.SetDisableRecover(true)
+		defer cl.SetDisableRecover(false)
+
+		fs := newTwoFileFS("/foo", spxfile, spxcode, gmxfile, gmx)
+		pkgs, err := parser.ParseFSDir(gblFset, fs, "/foo", spxParserConf())
+		if err != nil {
+			scanner.PrintError(os.Stderr, err)
+			t.Fatal("ParseFSDir:", err)
+		}
+		bar := pkgs["main"]
+		pkg, err := cl.NewPackage("", bar, conf)
+		if err != nil {
+			t.Fatal("NewPackage:", err)
+		}
+		var b bytes.Buffer
+		err = gox.WriteTo(&b, pkg, false)
+		if err != nil {
+			t.Fatal("gox.WriteTo failed:", err)
+		}
+		result := b.String()
+		if result != expected {
+			t.Fatalf("\nResult:\n%s\nExpected:\n%s\n", result, expected)
+		}
+	})
 }
 
 func gopSpxErrorTestEx(t *testing.T, msg, gmx, spxcode, gmxfile, spxfile string) {
@@ -301,16 +303,18 @@ type Game struct {
 	*spx.MyGame
 	Kai Kai
 }
+
+func (this *Game) onInit() {
+	this.Kai.Clone()
+	this.Broadcast__0("msg1")
+}
+
 type Kai struct {
 	spx.Sprite
 	*Game
 	a int
 }
 
-func (this *Game) onInit() {
-	this.Kai.Clone()
-	this.Broadcast__0("msg1")
-}
 func (this *Kai) onInit() {
 	this.a = 1
 }
@@ -346,10 +350,6 @@ type index struct {
 	Kai Kai
 	t   spx.Sound
 }
-type Kai struct {
-	spx.Sprite
-	*index
-}
 
 func (this *index) MainEntry() {
 	spx.Gopt_MyGame_Run(this, "hzip://open.qiniu.us/weather/res.zip")
@@ -357,6 +357,12 @@ func (this *index) MainEntry() {
 func main() {
 	spx.Gopt_MyGame_Main(new(index))
 }
+
+type Kai struct {
+	spx.Sprite
+	*index
+}
+
 func (this *Kai) Main() {
 	fmt.Println("Hi")
 }
@@ -401,7 +407,7 @@ func TestSpxMainEntry(t *testing.T) {
 	conf := *gblConf
 	conf.NoAutoGenMain = false
 
-	gopSpxTestExConf(t, &conf, `
+	gopSpxTestExConf(t, "Nocode", &conf, `
 `, `
 `, `package main
 
@@ -417,7 +423,7 @@ func main() {
 	new(Game).Main()
 }
 `, "Game.t2gmx", "Kai.t2spx")
-	gopSpxTestExConf(t, &conf, `
+	gopSpxTestExConf(t, "OnlyGmx", &conf, `
 var (
 	Kai Kai
 )
@@ -430,19 +436,20 @@ type Game struct {
 	spx2.Game
 	Kai Kai
 }
-type Kai struct {
-	spx2.Sprite
-	*Game
-}
 
 func (this *Game) MainEntry() {
 }
 func main() {
 	new(Game).Main()
 }
+
+type Kai struct {
+	spx2.Sprite
+	*Game
+}
 `, "Game.t2gmx", "Kai.t2spx")
 
-	gopSpxTestExConf(t, &conf, `
+	gopSpxTestExConf(t, "KaiAndGmx", &conf, `
 var (
 	Kai Kai
 )
@@ -466,10 +473,6 @@ type Game struct {
 	spx2.Game
 	Kai Kai
 }
-type Kai struct {
-	spx2.Sprite
-	*Game
-}
 
 func (this *Game) MainEntry() {
 	fmt.Println("Hi")
@@ -477,6 +480,12 @@ func (this *Game) MainEntry() {
 func main() {
 	new(Game).Main()
 }
+
+type Kai struct {
+	spx2.Sprite
+	*Game
+}
+
 func (this *Kai) Main() {
 	fmt.Println("Hello")
 }
diff --git a/cl/compile_test.go b/cl/compile_test.go
index 8f2fcc91..007b701f 100644
--- a/cl/compile_test.go
+++ b/cl/compile_test.go
@@ -68,6 +68,12 @@ func init() {
 	}
 }
 
+func gopClNamedTest(t *testing.T, name string, gopcode, expected string) {
+	t.Run(name, func(t *testing.T) {
+		gopClTest(t, gopcode, expected)
+	})
+}
+
 func gopClTest(t *testing.T, gopcode, expected string) {
 	gopClTestEx(t, gblConf, "main", gopcode, expected)
 }
@@ -549,7 +555,7 @@ func main() {
 }
 
 func TestIssue774(t *testing.T) {
-	gopClTest(t, `
+	gopClNamedTest(t, "InterfaceTypeAssert", `
 package main
 
 import "fmt"
@@ -579,9 +585,6 @@ func main() {
 	fmt.Println(a.(*A))
 }
 
-type AA interface {
-	String() string
-}
 type A struct {
 	str string
 }
@@ -589,8 +592,12 @@ type A struct {
 func (a *A) String() string {
 	return a.str
 }
+
+type AA interface {
+	String() string
+}
 `)
-	gopClTest(t, `
+	gopClNamedTest(t, "getInterface", `
 package main
 
 import "fmt"
@@ -624,16 +631,14 @@ func main() {
 	a := get()
 	fmt.Println(a.(*A))
 }
-
-type AA interface {
-	String() string
-}
-
 func get() AA {
 	var a AA
 	return a
 }
 
+type AA interface {
+	String() string
+}
 type A struct {
 	str string
 }
@@ -1610,12 +1615,12 @@ func main() {
 }
 `, `package main
 
+type bar = foo
 type foo struct {
 	p *foo
 	A int
 	B string "tag1:123"
 }
-type bar = foo
 
 func main() {
 	type a struct {
@@ -1885,10 +1890,6 @@ type fooIter struct {
 	data *foo
 	idx  int
 }
-type foo struct {
-	key []int
-	val []string
-}
 
 func (p *fooIter) Next() (key int, val string, ok bool) {
 	if p.idx < len(p.data.key) {
@@ -1897,6 +1898,12 @@ func (p *fooIter) Next() (key int, val string, ok bool) {
 	}
 	return
 }
+
+type foo struct {
+	key []int
+	val []string
+}
+
 func (p *foo) Gop_Enum() *fooIter {
 	return &fooIter{data: p}
 }
@@ -3230,22 +3237,19 @@ func TestNew(t *testing.T) {
 		t.Fatal("Test failed:", ret, expected)
 	}
 }
-
-type Result struct {
-	Repo Repo
-}
-
 func New() Result {
 	repo := newRepo()
 	return Result{Repo: repo}
 }
+func newRepo() Repo {
+	return Repo{Title: "Hi"}
+}
 
 type Repo struct {
 	Title string
 }
-
-func newRepo() Repo {
-	return Repo{Title: "Hi"}
+type Result struct {
+	Repo Repo
 }
 `)
 	}