Files
dolt/nomdl/codegen/test/struct_test.go
Erik Arvidsson 9aadd85004 Add types.Struct and improve typed structs
The generated code for typed structs now uses a Go struct which
implements Value directly. The fields in this struct uses the "user"
type. (The union value still uses types.Value though.)

When a typed struct is created by the decoder, it asks for a struct
builder which returns a channel that the values of the fields of the
struct are sent to.
2015-11-04 11:55:07 -05:00

58 lines
1.1 KiB
Go

package test
import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/nomdl/codegen/test/gen"
"github.com/attic-labs/noms/types"
)
func TestDef(t *testing.T) {
assert := assert.New(t)
def := gen.StructDef{"hi", true}
st := def.New()
def2 := st.Def()
st2 := def.New()
assert.Equal(def, def2)
assert.True(st.Equals(st2))
st3 := gen.NewStruct()
st3 = st3.SetS("hi").SetB(true)
assert.Equal("hi", st3.S())
assert.Equal(true, st3.B())
}
func TestValue(t *testing.T) {
assert := assert.New(t)
def := gen.StructDef{"hi", true}
var st types.Value
st = def.New()
st2 := st.(gen.Struct)
assert.True(st.Equals(st2))
}
func TestTypeRef(t *testing.T) {
assert := assert.New(t)
def := gen.StructDef{"hi", true}
st := def.New()
typ := st.TypeRef()
assert.EqualValues(0, typ.Ordinal())
assert.Equal(types.UnresolvedKind, typ.Kind())
}
func TestStructChunks(t *testing.T) {
assert := assert.New(t)
st := gen.StructDef{"hi", true}.New()
cs := st.Chunks()
// One chunk for the TypeRef
assert.Len(cs, 1)
}