gen_test.go 957 Bytes
Newer Older
Eric Myhre's avatar
Eric Myhre committed
1
package gengo
Eric Myhre's avatar
Eric Myhre committed
2 3 4 5 6 7

import (
	"io"
	"os"
	"testing"

8
	"github.com/ipld/go-ipld-prime/schema"
Eric Myhre's avatar
Eric Myhre committed
9 10 11
)

func TestNuevo(t *testing.T) {
12
	os.Mkdir("_test", 0755)
Eric Myhre's avatar
Eric Myhre committed
13 14 15 16 17 18 19
	openOrPanic := func(filename string) *os.File {
		y, err := os.OpenFile(filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
		if err != nil {
			panic(err)
		}
		return y
	}
20
	f := openOrPanic("_test/neu.go")
Eric Myhre's avatar
Eric Myhre committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
	emitFileHeader(f)
	emitType := func(tg typeGenerator, w io.Writer) {
		tg.EmitNodeType(w)
		tg.EmitNodeMethodReprKind(w)
		tg.EmitNodeMethodTraverseField(w)
		tg.EmitNodeMethodTraverseIndex(w)
		tg.EmitNodeMethodMapIterator(w)
		tg.EmitNodeMethodListIterator(w)
		tg.EmitNodeMethodLength(w)
		tg.EmitNodeMethodIsNull(w)
		tg.EmitNodeMethodAsBool(w)
		tg.EmitNodeMethodAsInt(w)
		tg.EmitNodeMethodAsFloat(w)
		tg.EmitNodeMethodAsString(w)
		tg.EmitNodeMethodAsBytes(w)
		tg.EmitNodeMethodAsLink(w)
		tg.EmitNodeMethodNodeBuilder(w)
	}
39
	emitType(generateKindString{"Strang", schema.TypeString{}}, f)
Eric Myhre's avatar
Eric Myhre committed
40
}