Files
dolt/nomdl/codegen/test/enum_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

47 lines
987 B
Go

package test
import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/nomdl/codegen/test/gen"
"github.com/attic-labs/noms/types"
)
func TestEnum(t *testing.T) {
assert := assert.New(t)
def := gen.EnumStructDef{gen.Right}
st := def.New()
def2 := st.Def()
st2 := def.New()
assert.Equal(def, def2)
assert.True(st.Equals(st2))
st3 := gen.NewEnumStruct()
assert.Equal(gen.Right, st3.Hand())
st3 = st3.SetHand(gen.Left)
assert.Equal(gen.Left, st3.Hand())
}
func TestEnumValue(t *testing.T) {
assert := assert.New(t)
def := gen.EnumStructDef{gen.Switch}
var st types.Value
st = def.New()
st2 := st.(gen.EnumStruct)
assert.True(st.Equals(st2))
}
func TestEnumIsValue(t *testing.T) {
cs := chunks.NewMemoryStore()
var v types.Value = gen.NewEnumStruct()
ref := types.WriteValue(v, cs)
v2 := types.ReadValue(ref, cs)
assert.True(t, v.Equals(v2))
}