Skip to content

Commit

Permalink
Merge pull request #13 from visualfc/works
Browse files Browse the repository at this point in the history
modfile: new Project.Works
  • Loading branch information
xushiwei authored Jul 3, 2023
2 parents d8560af + 6e1e4ba commit 7d8ec33
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
11 changes: 3 additions & 8 deletions gopmod/classfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ import (
)

type Class = modfile.Class

type Project struct {
Ext, Class string // NOTE: allow Ext/Class empty if there is no ProjectClass.
Works []*Class
PkgPaths []string
}
type Project = modfile.Project

var (
SpxProject = &Project{
Expand Down Expand Up @@ -70,7 +65,7 @@ func (p *Module) RegisterClasses(registerClass ...func(c *Project)) (err error)
}
p.registerClass(SpxProject, regcls)
if c := p.Project; c != nil {
p.registerClass(&Project{Ext: c.Ext, Class: c.Class, Works: p.Classes, PkgPaths: c.PkgPaths}, regcls)
p.registerClass(c, regcls)
}
for _, r := range p.Register {
if err = p.registerMod(r.ClassfileMod, regcls); err != nil {
Expand Down Expand Up @@ -109,7 +104,7 @@ func (p *Module) registerClassFrom(modVer module.Version, regcls func(c *Project
if c == nil {
return ErrNotClassFileMod
}
p.registerClass(&Project{Ext: c.Ext, Class: c.Class, Works: mod.Classes, PkgPaths: c.PkgPaths}, regcls)
p.registerClass(c, regcls)
return
}

Expand Down
32 changes: 16 additions & 16 deletions modfile/gop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,20 @@ func TestParse1(t *testing.T) {
t.Errorf("project path expected be math, but %s got", f.Project.PkgPaths[1])
}

if len(f.Classes) != 2 {
t.Errorf("project workclass length expected be 2, but %d got", len(f.Classes))
if len(f.Project.Works) != 2 {
t.Errorf("project workclass length expected be 2, but %d got", len(f.Project.Works))
}
if f.Classes[0].Ext != ".spx" {
t.Errorf("project class[0] exts expected be .spx, but %s got", f.Classes[0].Ext)
if f.Project.Works[0].Ext != ".spx" {
t.Errorf("project class[0] exts expected be .spx, but %s got", f.Project.Works[0].Ext)
}
if f.Classes[0].Class != "Sprite" {
t.Errorf("project class[0] class expected be Sprite, but %s got", f.Classes[0].Class)
if f.Project.Works[0].Class != "Sprite" {
t.Errorf("project class[0] class expected be Sprite, but %s got", f.Project.Works[0].Class)
}
if f.Classes[1].Ext != ".spx2" {
t.Errorf("project class[1] exts expected be .spx2, but %s got", f.Classes[1].Ext)
if f.Project.Works[1].Ext != ".spx2" {
t.Errorf("project class[1] exts expected be .spx2, but %s got", f.Project.Works[1].Ext)
}
if f.Classes[1].Class != "*Sprite2" {
t.Errorf("project class[1] class expected be Sprite, but %s got", f.Classes[1].Class)
if f.Project.Works[1].Class != "*Sprite2" {
t.Errorf("project class[1] class expected be Sprite, but %s got", f.Project.Works[1].Class)
}
}

Expand Down Expand Up @@ -201,14 +201,14 @@ func TestParse2(t *testing.T) {
t.Errorf("project path expected be math, but %s got", f.Project.PkgPaths[1])
}

if len(f.Classes) != 1 {
t.Errorf("project workclass length expected be 2, but %d got", len(f.Classes))
if len(f.Project.Works) != 1 {
t.Errorf("project workclass length expected be 2, but %d got", len(f.Project.Works))
}
if f.Classes[0].Ext != ".spx" {
t.Errorf("project class[0] exts expected be .spx, but %s got", f.Classes[0].Ext)
if f.Project.Works[0].Ext != ".spx" {
t.Errorf("project class[0] exts expected be .spx, but %s got", f.Project.Works[0].Ext)
}
if f.Classes[0].Class != "Sprite" {
t.Errorf("project class[0] class expected be Sprite, but %s got", f.Classes[0].Class)
if f.Project.Works[0].Class != "Sprite" {
t.Errorf("project class[0] class expected be Sprite, but %s got", f.Project.Works[0].Class)
}
}

Expand Down
4 changes: 2 additions & 2 deletions modfile/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type File struct {
modfile.File
Gop *Gop
Project *Project
Classes []*Class
Register []*Register
}

Expand Down Expand Up @@ -69,6 +68,7 @@ type Register struct {
type Project struct {
Ext string // ".gmx"
Class string // "Game"
Works []*Class // work class of classfile
PkgPaths []string // package paths of classfile
Syntax *Line
}
Expand Down Expand Up @@ -325,7 +325,7 @@ func (f *File) parseVerb(errs *ErrorList, verb string, line *Line, args []string
wrapError(err)
return
}
f.Classes = append(f.Classes, &Class{
f.Project.Works = append(f.Project.Works, &Class{
Ext: workExt,
Class: class,
Syntax: line,
Expand Down

0 comments on commit 7d8ec33

Please sign in to comment.