Files
dolt/types/assert.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

32 lines
720 B
Go

package types
import "github.com/attic-labs/noms/d"
func assertType(t TypeRef, v ...Value) {
if t.Kind() != ValueKind {
for _, v := range v {
d.Chk.True(t.Equals(v.TypeRef()), "Invalid type. Expected: %s, found: %s", t.Describe(), v.TypeRef().Describe())
}
}
}
func assertSetsSameType(s Set, v ...Set) {
if s.elemType().Kind() != ValueKind {
t := s.TypeRef()
for _, v := range v {
d.Chk.True(t.Equals(v.TypeRef()))
}
}
}
func assertMapElemTypes(m Map, v ...Value) {
elemTypes := m.elemTypes()
keyType := elemTypes[0]
valueType := elemTypes[0]
if keyType.Kind() != ValueKind || valueType.Kind() != ValueKind {
for i, v := range v {
d.Chk.True(elemTypes[i%2].Equals(v.TypeRef()))
}
}
}