Beispiel #1
0
func TestDeepRecursiveStruct(t *testing.T) {
	fixtureSrc := `
	package fixture

	import 	"github.com/tyba/storable"

	type Recur struct {
		storable.Document
		Foo string
		R *Other
	}

	type Other struct {
		R *Recur
	}
	`

	fset := &token.FileSet{}
	astFile, _ := parser.ParseFile(fset, "fixture.go", fixtureSrc, 0)
	cfg := &types.Config{}
	p, _ := cfg.Check("github.com/tcard/navpatch/navpatch", fset, []*ast.File{astFile}, nil)

	prc := generator.NewProcessor("fixture", nil)
	genPkg, err := prc.ProcessTypesPkg(p)

	if err != nil {
		t.Fatal(err)
	}

	if genPkg.Models[0].Fields[2].Fields[0].Fields[2] != genPkg.Models[0].Fields[2] {
		t.Fatalf("indirect type recursivity not handled correctly.")
	}
}
Beispiel #2
0
func (c *CmdGenerate) Execute(args []string) error {
	if !isDirectory(c.Input) {
		return fmt.Errorf("Input path should be a directory %s", c.Input)
	}

	p := generator.NewProcessor(c.Input, []string{c.Output})
	pkg, err := p.Do()
	if err != nil {
		return err
	}

	gen := generator.NewGenerator(filepath.Join(c.Input, c.Output))
	err = gen.Generate(pkg)
	if err != nil {
		return err
	}

	return nil
}