Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update gox and add test #1468

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions cl/compile_spx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
7 changes: 7 additions & 0 deletions cl/internal/spx/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
23 changes: 23 additions & 0 deletions cl/internal/spx/pkg/pkg.go
Original file line number Diff line number Diff line change
@@ -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)
}
9 changes: 9 additions & 0 deletions cl/internal/spx/sprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}) {
Expand All @@ -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{}) {
}

Expand Down
71 changes: 71 additions & 0 deletions cl/outline/cl/compile_spx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down