Repository: goplus/gop
Pull request #1468 (2023-10-12 07:25:12)

update gox and add test


Patch:
diff --git a/cl/internal/spx/game.go b/cl/internal/spx/game.go
index a201d089..9367eae7 100644
--- a/cl/internal/spx/game.go
+++ b/cl/internal/spx/game.go
@@ -41,6 +41,13 @@ func (p *MyGame) Broadcast__2(msg string, data interface{}, wait bool) {
 func (p *MyGame) Play(media string, wait ...bool) {
 }
 
+func (p *MyGame) sendMessage(data interface{}) {
+}
+
+func (p *MyGame) SendMessage(data interface{}) {
+	p.sendMessage(data)
+}
+
 func Gopt_MyGame_Run(game interface{}, resource string) error {
 	return nil
 }
diff --git a/cl/internal/spx/pkg/pkg.go b/cl/internal/spx/pkg/pkg.go
new file mode 100644
index 00000000..649406b5
--- /dev/null
+++ b/cl/internal/spx/pkg/pkg.go
@@ -0,0 +1,23 @@
+package pkg
+
+var (
+	GopPackage = true
+)
+
+type Vector struct {
+	x int
+	y int
+}
+
+func NewVector(x, y int) *Vector {
+	return &Vector{x, y}
+}
+
+func (v *Vector) Add__0(x int, y int) {
+	v.x += x
+	v.y += y
+}
+
+func (v *Vector) Add__1(o *Vector) {
+	v.Add__0(o.x, o.y)
+}
diff --git a/cl/internal/spx/sprite.go b/cl/internal/spx/sprite.go
index 9bbd27fd..00963bb8 100644
--- a/cl/internal/spx/sprite.go
+++ b/cl/internal/spx/sprite.go
@@ -16,7 +16,12 @@
 
 package spx
 
+import (
+	"github.com/goplus/gop/cl/internal/spx/pkg"
+)
+
 type Sprite struct {
+	pos pkg.Vector
 }
 
 func (p *Sprite) SetCostume(costume interface{}) {
@@ -25,6 +30,10 @@ func (p *Sprite) SetCostume(costume interface{}) {
 func (p *Sprite) Say(msg string, secs ...float64) {
 }
 
+func (p *Sprite) Position() *pkg.Vector {
+	return &p.pos
+}
+
 func Gopt_Sprite_Clone__0(sprite interface{}) {
 }
 
diff --git a/go.mod b/go.mod
index 95c7ec3f..9ae30e0d 100644
--- a/go.mod
+++ b/go.mod
@@ -5,7 +5,7 @@ go 1.17
 require (
 	github.com/fsnotify/fsnotify v1.6.0
 	github.com/goplus/c2go v0.7.16
-	github.com/goplus/gox v1.12.5
+	github.com/goplus/gox v1.12.2-0.20231012035644-c3bf89ec9e2b
 	github.com/goplus/mod v0.11.7
 	github.com/qiniu/x v1.13.1
 	golang.org/x/tools v0.14.0
diff --git a/go.sum b/go.sum
index 50d77c9b..80ab5bf2 100644
--- a/go.sum
+++ b/go.sum
@@ -7,8 +7,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
 github.com/goplus/c2go v0.7.16 h1:B9jRNNytoq7yDBQOZSm2qENQhRQMfNhgOea5XHWNUnI=
 github.com/goplus/c2go v0.7.16/go.mod h1:XODEFX2PeEEJXNLLdykWeZgMSaKJ51fVm+C9IM3FxNQ=
 github.com/goplus/gox v1.12.1/go.mod h1:wymoQJ7ydd42cTlaXb4wNbvn4LlKjR+j8PZehI7v1zQ=
-github.com/goplus/gox v1.12.5 h1:YkdsZDIOW3DZLJctWYKVzdsqMeuCYNn7J4BsFi6B058=
-github.com/goplus/gox v1.12.5/go.mod h1:ferIrvJSoXae8gABk5Z4olEzfAxZpUy4hD91Vm5E/qs=
+github.com/goplus/gox v1.12.2-0.20231012035644-c3bf89ec9e2b h1:5jCLZcnLj2jOTOw5j979XMoqeWI1ghZVnfuwmKbe5Eo=
+github.com/goplus/gox v1.12.2-0.20231012035644-c3bf89ec9e2b/go.mod h1:ferIrvJSoXae8gABk5Z4olEzfAxZpUy4hD91Vm5E/qs=
 github.com/goplus/mod v0.11.5/go.mod h1:NDC5E+XOT8vcJCMjqKhLDJHTHX7lyVN4Vbfi2U7dBhs=
 github.com/goplus/mod v0.11.7 h1:OTGFi/Jk0qmTy3ih8u3BQ6CbtcaPlTrJBlTacnge0jE=
 github.com/goplus/mod v0.11.7/go.mod h1:yl2QncBKTdXk+8UaNsdo4u2zSpGEJYA5JKjgD3K2h00=


Test patch:
diff --git a/cl/compile_spx_test.go b/cl/compile_spx_test.go
index 0451c301..9786376e 100644
--- a/cl/compile_spx_test.go
+++ b/cl/compile_spx_test.go
@@ -654,3 +654,78 @@ func (this *Kai) onCloned() {
 }
 `, "Game.tgmx", "Kai.tspx")
 }
+
+func TestSpxErrorSel(t *testing.T) {
+	gopSpxErrorTestEx(t, `./Kai.tspx:2:9: this.pos undefined (type *Kai has no field or method pos)`, `
+println "hi"
+`, `
+println this.pos
+`, "Game.tgmx", "Kai.tspx")
+}
+
+func TestSpxMethodSel(t *testing.T) {
+	gopSpxTestEx(t, `
+sendMessage "Hi"
+`, `
+func onMsg(msg string) {
+}
+`, `package main
+
+import spx "github.com/goplus/gop/cl/internal/spx"
+
+type Game struct {
+	*spx.MyGame
+}
+
+func (this *Game) MainEntry() {
+	this.SendMessage("Hi")
+}
+func main() {
+	spx.Gopt_MyGame_Main(new(Game))
+}
+
+type Kai struct {
+	spx.Sprite
+	*Game
+}
+
+func (this *Kai) onMsg(msg string) {
+}
+`, "Game.tgmx", "Kai.tspx")
+}
+
+func TestSpxPkgOverload(t *testing.T) {
+	gopSpxTestEx(t, `
+println "Hi"
+`, `
+func onMsg(msg string) {
+	this.position.add 100,200
+}
+`, `package main
+
+import (
+	fmt "fmt"
+	spx "github.com/goplus/gop/cl/internal/spx"
+)
+
+type Game struct {
+	*spx.MyGame
+}
+
+func (this *Game) MainEntry() {
+	fmt.Println("Hi")
+}
+func main() {
+	spx.Gopt_MyGame_Main(new(Game))
+}
+
+type Kai struct {
+	spx.Sprite
+	*Game
+}
+
+func (this *Kai) onMsg(msg string) {
+	this.Position().Add__0(100, 200)
+}
+`, "Game.tgmx", "Kai.tspx")
+}
diff --git a/cl/outline/cl/compile_spx_test.go b/cl/outline/cl/compile_spx_test.go
index e730234f..583afaf9 100644
--- a/cl/outline/cl/compile_spx_test.go
+++ b/cl/outline/cl/compile_spx_test.go
@@ -650,3 +650,74 @@ func (this *Kai) onCloned() {
 }
 `, "Game.tgmx", "Kai.tspx")
 }
+
+func TestSpxErrorSel(t *testing.T) {
+	gopSpxErrorTestEx(t, `./Kai.tspx:2:9: this.pos undefined (type *Kai has no field or method pos)`, `
+println "hi"
+`, `
+println this.pos
+`, "Game.tgmx", "Kai.tspx")
+}
+
+func TestSpxMethodSel(t *testing.T) {
+	gopSpxTestEx(t, `
+sendMessage "Hi"
+`, `
+func onMsg(msg string) {
+}
+`, `package main
+
+import spx "github.com/goplus/gop/cl/internal/spx"
+
+type Game struct {
+	*spx.MyGame
+}
+type Kai struct {
+	spx.Sprite
+	*Game
+}
+
+func (this *Game) MainEntry() {
+	this.SendMessage("Hi")
+}
+func (this *Kai) onMsg(msg string) {
+}
+func main() {
+	spx.Gopt_MyGame_Main(new(Game))
+}
+`, "Game.tgmx", "Kai.tspx")
+}
+
+func TestSpxPkgOverload(t *testing.T) {
+	gopSpxTestEx(t, `
+println "Hi"
+`, `
+func onMsg(msg string) {
+	this.position.add 100,200
+}
+`, `package main
+
+import (
+	fmt "fmt"
+	spx "github.com/goplus/gop/cl/internal/spx"
+)
+
+type Game struct {
+	*spx.MyGame
+}
+type Kai struct {
+	spx.Sprite
+	*Game
+}
+
+func (this *Game) MainEntry() {
+	fmt.Println("Hi")
+}
+func (this *Kai) onMsg(msg string) {
+	this.Position().Add__0(100, 200)
+}
+func main() {
+	spx.Gopt_MyGame_Main(new(Game))
+}
+`, "Game.tgmx", "Kai.tspx")
+}