gen_test.go 1.32 KB
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

Eric Myhre's avatar
Eric Myhre committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
	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)
	}
38

39 40
	f := openOrPanic("_test/minima.go")
	emitMinima(f)
41

Eric Myhre's avatar
Eric Myhre committed
42 43 44 45 46 47 48 49
	tStrang := schema.SpawnString("Strang")
	tStract := schema.SpawnStruct("Stract",
		[]schema.StructField{schema.SpawnStructField(
			"aField", tStrang, false, false,
		)},
		schema.StructRepresentation_Map{},
	)

50 51
	f = openOrPanic("_test/tStrang.go")
	emitFileHeader(f)
52
	emitType(NewGeneratorForKindString(tStrang), f)
Eric Myhre's avatar
Eric Myhre committed
53 54 55 56 57

	_ = generateKindStruct{tStract}
	//f = openOrPanic("_test/tStract.go")
	//emitFileHeader(f)
	//emitType(generateKindStruct{tStract}, f)
Eric Myhre's avatar
Eric Myhre committed
58
}