NomDL: Make NomsValue a Value

This means that when we ReadValue we can now return a NomsValue

Towards #281
This commit is contained in:
Erik Arvidsson
2015-10-06 11:16:33 -07:00
parent 2dec53453e
commit 9cb7596409
31 changed files with 750 additions and 129 deletions
+60 -12
View File
@@ -65,14 +65,21 @@ func (l ListOfMapOfStringToValue) NomsValue() types.Value {
return l.l
}
func (l ListOfMapOfStringToValue) Equals(p ListOfMapOfStringToValue) bool {
return l.l.Equals(p.l)
func (l ListOfMapOfStringToValue) Equals(other types.Value) bool {
if other, ok := other.(ListOfMapOfStringToValue); ok {
return l.l.Equals(other.l)
}
return false
}
func (l ListOfMapOfStringToValue) Ref() ref.Ref {
return l.l.Ref()
}
func (l ListOfMapOfStringToValue) Chunks() []types.Future {
return l.l.Chunks()
}
// A Noms Value that describes ListOfMapOfStringToValue.
var __typeRefForListOfMapOfStringToValue = types.MakeCompoundTypeRef("", types.ListKind, types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakePrimitiveTypeRef(types.ValueKind)))
@@ -196,14 +203,21 @@ func (m MapOfStringToValue) NomsValue() types.Value {
return m.m
}
func (m MapOfStringToValue) Equals(p MapOfStringToValue) bool {
return m.m.Equals(p.m)
func (m MapOfStringToValue) Equals(other types.Value) bool {
if other, ok := other.(MapOfStringToValue); ok {
return m.m.Equals(other.m)
}
return false
}
func (m MapOfStringToValue) Ref() ref.Ref {
return m.m.Ref()
}
func (m MapOfStringToValue) Chunks() []types.Future {
return m.m.Chunks()
}
// A Noms Value that describes MapOfStringToValue.
var __typeRefForMapOfStringToValue = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakePrimitiveTypeRef(types.ValueKind))
@@ -309,14 +323,21 @@ func (m MapOfStringToListOfPitch) NomsValue() types.Value {
return m.m
}
func (m MapOfStringToListOfPitch) Equals(p MapOfStringToListOfPitch) bool {
return m.m.Equals(p.m)
func (m MapOfStringToListOfPitch) Equals(other types.Value) bool {
if other, ok := other.(MapOfStringToListOfPitch); ok {
return m.m.Equals(other.m)
}
return false
}
func (m MapOfStringToListOfPitch) Ref() ref.Ref {
return m.m.Ref()
}
func (m MapOfStringToListOfPitch) Chunks() []types.Future {
return m.m.Chunks()
}
// A Noms Value that describes MapOfStringToListOfPitch.
var __typeRefForMapOfStringToListOfPitch = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Pitch", __mainPackageInFile_types_CachedRef)))
@@ -421,14 +442,21 @@ func (l ListOfPitch) NomsValue() types.Value {
return l.l
}
func (l ListOfPitch) Equals(p ListOfPitch) bool {
return l.l.Equals(p.l)
func (l ListOfPitch) Equals(other types.Value) bool {
if other, ok := other.(ListOfPitch); ok {
return l.l.Equals(other.l)
}
return false
}
func (l ListOfPitch) Ref() ref.Ref {
return l.l.Ref()
}
func (l ListOfPitch) Chunks() []types.Future {
return l.l.Chunks()
}
// A Noms Value that describes ListOfPitch.
var __typeRefForListOfPitch = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Pitch", __mainPackageInFile_types_CachedRef))
@@ -556,6 +584,12 @@ func (m Pitch) TypeRef() types.TypeRef {
return __typeRefForPitch
}
func init() {
types.RegisterFromValFunction(__typeRefForPitch, func(v types.Value) types.NomsValue {
return PitchFromVal(v)
})
}
func PitchFromVal(val types.Value) Pitch {
// TODO: Validate here
return Pitch{val.(types.Map)}
@@ -565,14 +599,21 @@ func (s Pitch) NomsValue() types.Value {
return s.m
}
func (s Pitch) Equals(other Pitch) bool {
return s.m.Equals(other.m)
func (s Pitch) Equals(other types.Value) bool {
if other, ok := other.(Pitch); ok {
return s.m.Equals(other.m)
}
return false
}
func (s Pitch) Ref() ref.Ref {
return s.m.Ref()
}
func (s Pitch) Chunks() []types.Future {
return s.m.Chunks()
}
func (s Pitch) X() float64 {
return float64(s.m.Get(types.NewString("X")).(types.Float64))
}
@@ -627,14 +668,21 @@ func (m MapOfStringToString) NomsValue() types.Value {
return m.m
}
func (m MapOfStringToString) Equals(p MapOfStringToString) bool {
return m.m.Equals(p.m)
func (m MapOfStringToString) Equals(other types.Value) bool {
if other, ok := other.(MapOfStringToString); ok {
return m.m.Equals(other.m)
}
return false
}
func (m MapOfStringToString) Ref() ref.Ref {
return m.m.Ref()
}
func (m MapOfStringToString) Chunks() []types.Future {
return m.m.Chunks()
}
// A Noms Value that describes MapOfStringToString.
var __typeRefForMapOfStringToString = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakePrimitiveTypeRef(types.StringKind))
+129 -22
View File
@@ -107,6 +107,12 @@ func (m Geoposition) TypeRef() types.TypeRef {
return __typeRefForGeoposition
}
func init() {
types.RegisterFromValFunction(__typeRefForGeoposition, func(v types.Value) types.NomsValue {
return GeopositionFromVal(v)
})
}
func GeopositionFromVal(val types.Value) Geoposition {
// TODO: Validate here
return Geoposition{val.(types.Map)}
@@ -116,14 +122,21 @@ func (s Geoposition) NomsValue() types.Value {
return s.m
}
func (s Geoposition) Equals(other Geoposition) bool {
return s.m.Equals(other.m)
func (s Geoposition) Equals(other types.Value) bool {
if other, ok := other.(Geoposition); ok {
return s.m.Equals(other.m)
}
return false
}
func (s Geoposition) Ref() ref.Ref {
return s.m.Ref()
}
func (s Geoposition) Chunks() []types.Future {
return s.m.Chunks()
}
func (s Geoposition) Latitude() float32 {
return float32(s.m.Get(types.NewString("Latitude")).(types.Float32))
}
@@ -182,6 +195,12 @@ func (m Georectangle) TypeRef() types.TypeRef {
return __typeRefForGeorectangle
}
func init() {
types.RegisterFromValFunction(__typeRefForGeorectangle, func(v types.Value) types.NomsValue {
return GeorectangleFromVal(v)
})
}
func GeorectangleFromVal(val types.Value) Georectangle {
// TODO: Validate here
return Georectangle{val.(types.Map)}
@@ -191,14 +210,21 @@ func (s Georectangle) NomsValue() types.Value {
return s.m
}
func (s Georectangle) Equals(other Georectangle) bool {
return s.m.Equals(other.m)
func (s Georectangle) Equals(other types.Value) bool {
if other, ok := other.(Georectangle); ok {
return s.m.Equals(other.m)
}
return false
}
func (s Georectangle) Ref() ref.Ref {
return s.m.Ref()
}
func (s Georectangle) Chunks() []types.Future {
return s.m.Chunks()
}
func (s Georectangle) TopLeft() Geoposition {
return GeopositionFromVal(s.m.Get(types.NewString("TopLeft")))
}
@@ -257,6 +283,12 @@ func (m Node) TypeRef() types.TypeRef {
return __typeRefForNode
}
func init() {
types.RegisterFromValFunction(__typeRefForNode, func(v types.Value) types.NomsValue {
return NodeFromVal(v)
})
}
func NodeFromVal(val types.Value) Node {
// TODO: Validate here
return Node{val.(types.Map)}
@@ -266,14 +298,21 @@ func (s Node) NomsValue() types.Value {
return s.m
}
func (s Node) Equals(other Node) bool {
return s.m.Equals(other.m)
func (s Node) Equals(other types.Value) bool {
if other, ok := other.(Node); ok {
return s.m.Equals(other.m)
}
return false
}
func (s Node) Ref() ref.Ref {
return s.m.Ref()
}
func (s Node) Chunks() []types.Future {
return s.m.Chunks()
}
func (s Node) Geoposition() Geoposition {
return GeopositionFromVal(s.m.Get(types.NewString("Geoposition")))
}
@@ -304,8 +343,15 @@ func (r RefOfValue) Ref() ref.Ref {
return r.r
}
func (r RefOfValue) Equals(other RefOfValue) bool {
return r.Ref() == other.Ref()
func (r RefOfValue) Equals(other types.Value) bool {
if other, ok := other.(RefOfValue); ok {
return r.r == other.r
}
return false
}
func (r RefOfValue) Chunks() []types.Future {
return nil
}
func (r RefOfValue) NomsValue() types.Value {
@@ -396,6 +442,12 @@ func (m QuadTree) TypeRef() types.TypeRef {
return __typeRefForQuadTree
}
func init() {
types.RegisterFromValFunction(__typeRefForQuadTree, func(v types.Value) types.NomsValue {
return QuadTreeFromVal(v)
})
}
func QuadTreeFromVal(val types.Value) QuadTree {
// TODO: Validate here
return QuadTree{val.(types.Map)}
@@ -405,14 +457,21 @@ func (s QuadTree) NomsValue() types.Value {
return s.m
}
func (s QuadTree) Equals(other QuadTree) bool {
return s.m.Equals(other.m)
func (s QuadTree) Equals(other types.Value) bool {
if other, ok := other.(QuadTree); ok {
return s.m.Equals(other.m)
}
return false
}
func (s QuadTree) Ref() ref.Ref {
return s.m.Ref()
}
func (s QuadTree) Chunks() []types.Future {
return s.m.Chunks()
}
func (s QuadTree) Nodes() ListOfNode {
return ListOfNodeFromVal(s.m.Get(types.NewString("Nodes")))
}
@@ -498,14 +557,21 @@ func (l ListOfNode) NomsValue() types.Value {
return l.l
}
func (l ListOfNode) Equals(p ListOfNode) bool {
return l.l.Equals(p.l)
func (l ListOfNode) Equals(other types.Value) bool {
if other, ok := other.(ListOfNode); ok {
return l.l.Equals(other.l)
}
return false
}
func (l ListOfNode) Ref() ref.Ref {
return l.l.Ref()
}
func (l ListOfNode) Chunks() []types.Future {
return l.l.Chunks()
}
// A Noms Value that describes ListOfNode.
var __typeRefForListOfNode = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Node", __mainPackageInFile_types_CachedRef))
@@ -629,14 +695,21 @@ func (m MapOfStringToQuadTree) NomsValue() types.Value {
return m.m
}
func (m MapOfStringToQuadTree) Equals(p MapOfStringToQuadTree) bool {
return m.m.Equals(p.m)
func (m MapOfStringToQuadTree) Equals(other types.Value) bool {
if other, ok := other.(MapOfStringToQuadTree); ok {
return m.m.Equals(other.m)
}
return false
}
func (m MapOfStringToQuadTree) Ref() ref.Ref {
return m.m.Ref()
}
func (m MapOfStringToQuadTree) Chunks() []types.Future {
return m.m.Chunks()
}
// A Noms Value that describes MapOfStringToQuadTree.
var __typeRefForMapOfStringToQuadTree = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef("QuadTree", __mainPackageInFile_types_CachedRef))
@@ -762,6 +835,12 @@ func (m SQuadTree) TypeRef() types.TypeRef {
return __typeRefForSQuadTree
}
func init() {
types.RegisterFromValFunction(__typeRefForSQuadTree, func(v types.Value) types.NomsValue {
return SQuadTreeFromVal(v)
})
}
func SQuadTreeFromVal(val types.Value) SQuadTree {
// TODO: Validate here
return SQuadTree{val.(types.Map)}
@@ -771,14 +850,21 @@ func (s SQuadTree) NomsValue() types.Value {
return s.m
}
func (s SQuadTree) Equals(other SQuadTree) bool {
return s.m.Equals(other.m)
func (s SQuadTree) Equals(other types.Value) bool {
if other, ok := other.(SQuadTree); ok {
return s.m.Equals(other.m)
}
return false
}
func (s SQuadTree) Ref() ref.Ref {
return s.m.Ref()
}
func (s SQuadTree) Chunks() []types.Future {
return s.m.Chunks()
}
func (s SQuadTree) Nodes() ListOfRefOfValue {
return ListOfRefOfValueFromVal(s.m.Get(types.NewString("Nodes")))
}
@@ -864,14 +950,21 @@ func (l ListOfRefOfValue) NomsValue() types.Value {
return l.l
}
func (l ListOfRefOfValue) Equals(p ListOfRefOfValue) bool {
return l.l.Equals(p.l)
func (l ListOfRefOfValue) Equals(other types.Value) bool {
if other, ok := other.(ListOfRefOfValue); ok {
return l.l.Equals(other.l)
}
return false
}
func (l ListOfRefOfValue) Ref() ref.Ref {
return l.l.Ref()
}
func (l ListOfRefOfValue) Chunks() []types.Future {
return l.l.Chunks()
}
// A Noms Value that describes ListOfRefOfValue.
var __typeRefForListOfRefOfValue = types.MakeCompoundTypeRef("", types.ListKind, types.MakeCompoundTypeRef("", types.RefKind, types.MakePrimitiveTypeRef(types.ValueKind)))
@@ -995,14 +1088,21 @@ func (m MapOfStringToRefOfSQuadTree) NomsValue() types.Value {
return m.m
}
func (m MapOfStringToRefOfSQuadTree) Equals(p MapOfStringToRefOfSQuadTree) bool {
return m.m.Equals(p.m)
func (m MapOfStringToRefOfSQuadTree) Equals(other types.Value) bool {
if other, ok := other.(MapOfStringToRefOfSQuadTree); ok {
return m.m.Equals(other.m)
}
return false
}
func (m MapOfStringToRefOfSQuadTree) Ref() ref.Ref {
return m.m.Ref()
}
func (m MapOfStringToRefOfSQuadTree) Chunks() []types.Future {
return m.m.Chunks()
}
// A Noms Value that describes MapOfStringToRefOfSQuadTree.
var __typeRefForMapOfStringToRefOfSQuadTree = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeCompoundTypeRef("", types.RefKind, types.MakeTypeRef("SQuadTree", __mainPackageInFile_types_CachedRef)))
@@ -1084,8 +1184,15 @@ func (r RefOfSQuadTree) Ref() ref.Ref {
return r.r
}
func (r RefOfSQuadTree) Equals(other RefOfSQuadTree) bool {
return r.Ref() == other.Ref()
func (r RefOfSQuadTree) Equals(other types.Value) bool {
if other, ok := other.(RefOfSQuadTree); ok {
return r.r == other.r
}
return false
}
func (r RefOfSQuadTree) Chunks() []types.Future {
return nil
}
func (r RefOfSQuadTree) NomsValue() types.Value {
+39 -6
View File
@@ -81,14 +81,21 @@ func (l ListOfIncident) NomsValue() types.Value {
return l.l
}
func (l ListOfIncident) Equals(p ListOfIncident) bool {
return l.l.Equals(p.l)
func (l ListOfIncident) Equals(other types.Value) bool {
if other, ok := other.(ListOfIncident); ok {
return l.l.Equals(other.l)
}
return false
}
func (l ListOfIncident) Ref() ref.Ref {
return l.l.Ref()
}
func (l ListOfIncident) Chunks() []types.Future {
return l.l.Chunks()
}
// A Noms Value that describes ListOfIncident.
var __typeRefForListOfIncident = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Incident", __mainPackageInFile_types_CachedRef))
@@ -252,6 +259,12 @@ func (m Incident) TypeRef() types.TypeRef {
return __typeRefForIncident
}
func init() {
types.RegisterFromValFunction(__typeRefForIncident, func(v types.Value) types.NomsValue {
return IncidentFromVal(v)
})
}
func IncidentFromVal(val types.Value) Incident {
// TODO: Validate here
return Incident{val.(types.Map)}
@@ -261,14 +274,21 @@ func (s Incident) NomsValue() types.Value {
return s.m
}
func (s Incident) Equals(other Incident) bool {
return s.m.Equals(other.m)
func (s Incident) Equals(other types.Value) bool {
if other, ok := other.(Incident); ok {
return s.m.Equals(other.m)
}
return false
}
func (s Incident) Ref() ref.Ref {
return s.m.Ref()
}
func (s Incident) Chunks() []types.Future {
return s.m.Chunks()
}
func (s Incident) ID() int64 {
return int64(s.m.Get(types.NewString("ID")).(types.Int64))
}
@@ -399,6 +419,12 @@ func (m Geoposition) TypeRef() types.TypeRef {
return __typeRefForGeoposition
}
func init() {
types.RegisterFromValFunction(__typeRefForGeoposition, func(v types.Value) types.NomsValue {
return GeopositionFromVal(v)
})
}
func GeopositionFromVal(val types.Value) Geoposition {
// TODO: Validate here
return Geoposition{val.(types.Map)}
@@ -408,14 +434,21 @@ func (s Geoposition) NomsValue() types.Value {
return s.m
}
func (s Geoposition) Equals(other Geoposition) bool {
return s.m.Equals(other.m)
func (s Geoposition) Equals(other types.Value) bool {
if other, ok := other.(Geoposition); ok {
return s.m.Equals(other.m)
}
return false
}
func (s Geoposition) Ref() ref.Ref {
return s.m.Ref()
}
func (s Geoposition) Chunks() []types.Future {
return s.m.Chunks()
}
func (s Geoposition) Latitude() float32 {
return float32(s.m.Get(types.NewString("Latitude")).(types.Float32))
}
+78 -12
View File
@@ -93,14 +93,21 @@ func (l ListOfIncident) NomsValue() types.Value {
return l.l
}
func (l ListOfIncident) Equals(p ListOfIncident) bool {
return l.l.Equals(p.l)
func (l ListOfIncident) Equals(other types.Value) bool {
if other, ok := other.(ListOfIncident); ok {
return l.l.Equals(other.l)
}
return false
}
func (l ListOfIncident) Ref() ref.Ref {
return l.l.Ref()
}
func (l ListOfIncident) Chunks() []types.Future {
return l.l.Chunks()
}
// A Noms Value that describes ListOfIncident.
var __typeRefForListOfIncident = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Incident", __mainPackageInFile_types_CachedRef))
@@ -240,6 +247,12 @@ func (m Incident) TypeRef() types.TypeRef {
return __typeRefForIncident
}
func init() {
types.RegisterFromValFunction(__typeRefForIncident, func(v types.Value) types.NomsValue {
return IncidentFromVal(v)
})
}
func IncidentFromVal(val types.Value) Incident {
// TODO: Validate here
return Incident{val.(types.Map)}
@@ -249,14 +262,21 @@ func (s Incident) NomsValue() types.Value {
return s.m
}
func (s Incident) Equals(other Incident) bool {
return s.m.Equals(other.m)
func (s Incident) Equals(other types.Value) bool {
if other, ok := other.(Incident); ok {
return s.m.Equals(other.m)
}
return false
}
func (s Incident) Ref() ref.Ref {
return s.m.Ref()
}
func (s Incident) Chunks() []types.Future {
return s.m.Chunks()
}
func (s Incident) Category() string {
return s.m.Get(types.NewString("Category")).(types.String).String()
}
@@ -339,6 +359,12 @@ func (m Geoposition) TypeRef() types.TypeRef {
return __typeRefForGeoposition
}
func init() {
types.RegisterFromValFunction(__typeRefForGeoposition, func(v types.Value) types.NomsValue {
return GeopositionFromVal(v)
})
}
func GeopositionFromVal(val types.Value) Geoposition {
// TODO: Validate here
return Geoposition{val.(types.Map)}
@@ -348,14 +374,21 @@ func (s Geoposition) NomsValue() types.Value {
return s.m
}
func (s Geoposition) Equals(other Geoposition) bool {
return s.m.Equals(other.m)
func (s Geoposition) Equals(other types.Value) bool {
if other, ok := other.(Geoposition); ok {
return s.m.Equals(other.m)
}
return false
}
func (s Geoposition) Ref() ref.Ref {
return s.m.Ref()
}
func (s Geoposition) Chunks() []types.Future {
return s.m.Chunks()
}
func (s Geoposition) Latitude() float32 {
return float32(s.m.Get(types.NewString("Latitude")).(types.Float32))
}
@@ -414,6 +447,12 @@ func (m Georectangle) TypeRef() types.TypeRef {
return __typeRefForGeorectangle
}
func init() {
types.RegisterFromValFunction(__typeRefForGeorectangle, func(v types.Value) types.NomsValue {
return GeorectangleFromVal(v)
})
}
func GeorectangleFromVal(val types.Value) Georectangle {
// TODO: Validate here
return Georectangle{val.(types.Map)}
@@ -423,14 +462,21 @@ func (s Georectangle) NomsValue() types.Value {
return s.m
}
func (s Georectangle) Equals(other Georectangle) bool {
return s.m.Equals(other.m)
func (s Georectangle) Equals(other types.Value) bool {
if other, ok := other.(Georectangle); ok {
return s.m.Equals(other.m)
}
return false
}
func (s Georectangle) Ref() ref.Ref {
return s.m.Ref()
}
func (s Georectangle) Chunks() []types.Future {
return s.m.Chunks()
}
func (s Georectangle) TopLeft() Geoposition {
return GeopositionFromVal(s.m.Get(types.NewString("TopLeft")))
}
@@ -505,6 +551,12 @@ func (m SQuadTree) TypeRef() types.TypeRef {
return __typeRefForSQuadTree
}
func init() {
types.RegisterFromValFunction(__typeRefForSQuadTree, func(v types.Value) types.NomsValue {
return SQuadTreeFromVal(v)
})
}
func SQuadTreeFromVal(val types.Value) SQuadTree {
// TODO: Validate here
return SQuadTree{val.(types.Map)}
@@ -514,14 +566,21 @@ func (s SQuadTree) NomsValue() types.Value {
return s.m
}
func (s SQuadTree) Equals(other SQuadTree) bool {
return s.m.Equals(other.m)
func (s SQuadTree) Equals(other types.Value) bool {
if other, ok := other.(SQuadTree); ok {
return s.m.Equals(other.m)
}
return false
}
func (s SQuadTree) Ref() ref.Ref {
return s.m.Ref()
}
func (s SQuadTree) Chunks() []types.Future {
return s.m.Chunks()
}
func (s SQuadTree) Nodes() ListOfIncident {
return ListOfIncidentFromVal(s.m.Get(types.NewString("Nodes")))
}
@@ -608,14 +667,21 @@ func (m MapOfStringToSQuadTree) NomsValue() types.Value {
return m.m
}
func (m MapOfStringToSQuadTree) Equals(p MapOfStringToSQuadTree) bool {
return m.m.Equals(p.m)
func (m MapOfStringToSQuadTree) Equals(other types.Value) bool {
if other, ok := other.(MapOfStringToSQuadTree); ok {
return m.m.Equals(other.m)
}
return false
}
func (m MapOfStringToSQuadTree) Ref() ref.Ref {
return m.m.Ref()
}
func (m MapOfStringToSQuadTree) Chunks() []types.Future {
return m.m.Chunks()
}
// A Noms Value that describes MapOfStringToSQuadTree.
var __typeRefForMapOfStringToSQuadTree = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef("SQuadTree", __mainPackageInFile_types_CachedRef))
+24 -4
View File
@@ -49,6 +49,12 @@ func (m Commit) TypeRef() types.TypeRef {
return __typeRefForCommit
}
func init() {
types.RegisterFromValFunction(__typeRefForCommit, func(v types.Value) types.NomsValue {
return CommitFromVal(v)
})
}
func CommitFromVal(val types.Value) Commit {
// TODO: Validate here
return Commit{val.(types.Map)}
@@ -58,14 +64,21 @@ func (s Commit) NomsValue() types.Value {
return s.m
}
func (s Commit) Equals(other Commit) bool {
return s.m.Equals(other.m)
func (s Commit) Equals(other types.Value) bool {
if other, ok := other.(Commit); ok {
return s.m.Equals(other.m)
}
return false
}
func (s Commit) Ref() ref.Ref {
return s.m.Ref()
}
func (s Commit) Chunks() []types.Future {
return s.m.Chunks()
}
func (s Commit) Value() types.Value {
return s.m.Get(types.NewString("value"))
}
@@ -100,14 +113,21 @@ func (s SetOfCommit) NomsValue() types.Value {
return s.s
}
func (s SetOfCommit) Equals(p SetOfCommit) bool {
return s.s.Equals(p.s)
func (s SetOfCommit) Equals(other types.Value) bool {
if other, ok := other.(SetOfCommit); ok {
return s.s.Equals(other.s)
}
return false
}
func (s SetOfCommit) Ref() ref.Ref {
return s.s.Ref()
}
func (s SetOfCommit) Chunks() []types.Future {
return s.s.Chunks()
}
// A Noms Value that describes SetOfCommit.
var __typeRefForSetOfCommit = types.MakeCompoundTypeRef("", types.SetKind, types.MakeTypeRef("Commit", __datasPackageInFile_types_CachedRef))
+24 -4
View File
@@ -67,14 +67,21 @@ func (s SetOfDataset) NomsValue() types.Value {
return s.s
}
func (s SetOfDataset) Equals(p SetOfDataset) bool {
return s.s.Equals(p.s)
func (s SetOfDataset) Equals(other types.Value) bool {
if other, ok := other.(SetOfDataset); ok {
return s.s.Equals(other.s)
}
return false
}
func (s SetOfDataset) Ref() ref.Ref {
return s.s.Ref()
}
func (s SetOfDataset) Chunks() []types.Future {
return s.s.Chunks()
}
// A Noms Value that describes SetOfDataset.
var __typeRefForSetOfDataset = types.MakeCompoundTypeRef("", types.SetKind, types.MakeTypeRef("Dataset", __mgmtPackageInFile_types_CachedRef))
@@ -206,6 +213,12 @@ func (m Dataset) TypeRef() types.TypeRef {
return __typeRefForDataset
}
func init() {
types.RegisterFromValFunction(__typeRefForDataset, func(v types.Value) types.NomsValue {
return DatasetFromVal(v)
})
}
func DatasetFromVal(val types.Value) Dataset {
// TODO: Validate here
return Dataset{val.(types.Map)}
@@ -215,14 +228,21 @@ func (s Dataset) NomsValue() types.Value {
return s.m
}
func (s Dataset) Equals(other Dataset) bool {
return s.m.Equals(other.m)
func (s Dataset) Equals(other types.Value) bool {
if other, ok := other.(Dataset); ok {
return s.m.Equals(other.m)
}
return false
}
func (s Dataset) Ref() ref.Ref {
return s.m.Ref()
}
func (s Dataset) Chunks() []types.Future {
return s.m.Chunks()
}
func (s Dataset) Id() string {
return s.m.Get(types.NewString("id")).(types.String).String()
}
+9 -2
View File
@@ -38,14 +38,21 @@ func (l {{.Name}}) NomsValue() types.Value {
return l.l
}
func (l {{.Name}}) Equals(p {{.Name}}) bool {
return l.l.Equals(p.l)
func (l {{.Name}}) Equals(other types.Value) bool {
if other, ok := other.({{.Name}}); ok {
return l.l.Equals(other.l)
}
return false
}
func (l {{.Name}}) Ref() ref.Ref {
return l.l.Ref()
}
func (l {{.Name}}) Chunks() []types.Future {
return l.l.Chunks()
}
{{template "type_ref.tmpl" .}}
func (l {{.Name}}) Len() uint64 {
+9 -2
View File
@@ -39,14 +39,21 @@ func (m {{.Name}}) NomsValue() types.Value {
return m.m
}
func (m {{.Name}}) Equals(p {{.Name}}) bool {
return m.m.Equals(p.m)
func (m {{.Name}}) Equals(other types.Value) bool {
if other, ok := other.({{.Name}}); ok {
return m.m.Equals(other.m)
}
return false
}
func (m {{.Name}}) Ref() ref.Ref {
return m.m.Ref()
}
func (m {{.Name}}) Chunks() []types.Future {
return m.m.Chunks()
}
{{template "type_ref.tmpl" .}}
func (m {{.Name}}) Empty() bool {
+9 -2
View File
@@ -12,8 +12,15 @@ func (r {{.Name}}) Ref() ref.Ref {
return r.r
}
func (r {{.Name}}) Equals(other {{.Name}}) bool {
return r.Ref() == other.Ref()
func (r {{.Name}}) Equals(other types.Value) bool {
if other, ok := other.({{.Name}}); ok {
return r.r == other.r
}
return false
}
func (r {{.Name}}) Chunks() []types.Future {
return nil
}
func (r {{.Name}}) NomsValue() types.Value {
+9 -2
View File
@@ -39,14 +39,21 @@ func (s {{.Name}}) NomsValue() types.Value {
return s.s
}
func (s {{.Name}}) Equals(p {{.Name}}) bool {
return s.s.Equals(p.s)
func (s {{.Name}}) Equals(other types.Value) bool {
if other, ok := other.({{.Name}}); ok {
return s.s.Equals(other.s)
}
return false
}
func (s {{.Name}}) Ref() ref.Ref {
return s.s.Ref()
}
func (s {{.Name}}) Chunks() []types.Future {
return s.s.Chunks()
}
{{template "type_ref.tmpl" .}}
func (s {{.Name}}) Empty() bool {
+15 -2
View File
@@ -67,6 +67,12 @@ func (m {{.Name}}) TypeRef() types.TypeRef {
return __typeRefFor{{.Name}}
}
func init() {
types.RegisterFromValFunction(__typeRefFor{{.Name}}, func(v types.Value) types.NomsValue {
return {{.Name}}FromVal(v)
})
}
func {{.Name}}FromVal(val types.Value) {{.Name}} {
// TODO: Validate here
return {{.Name}}{val.(types.Map)}
@@ -76,14 +82,21 @@ func (s {{.Name}}) NomsValue() types.Value {
return s.m
}
func (s {{.Name}}) Equals(other {{.Name}}) bool {
return s.m.Equals(other.m)
func (s {{.Name}}) Equals(other types.Value) bool {
if other, ok := other.({{.Name}}); ok {
return s.m.Equals(other.m)
}
return false
}
func (s {{.Name}}) Ref() ref.Ref {
return s.m.Ref()
}
func (s {{.Name}}) Chunks() []types.Future {
return s.m.Chunks()
}
{{$name := .Name}}
{{range $index, $field := .Fields}}
{{if .Optional}}
+15 -2
View File
@@ -66,6 +66,12 @@ func (m EnumStruct) TypeRef() types.TypeRef {
return __typeRefForEnumStruct
}
func init() {
types.RegisterFromValFunction(__typeRefForEnumStruct, func(v types.Value) types.NomsValue {
return EnumStructFromVal(v)
})
}
func EnumStructFromVal(val types.Value) EnumStruct {
// TODO: Validate here
return EnumStruct{val.(types.Map)}
@@ -75,14 +81,21 @@ func (s EnumStruct) NomsValue() types.Value {
return s.m
}
func (s EnumStruct) Equals(other EnumStruct) bool {
return s.m.Equals(other.m)
func (s EnumStruct) Equals(other types.Value) bool {
if other, ok := other.(EnumStruct); ok {
return s.m.Equals(other.m)
}
return false
}
func (s EnumStruct) Ref() ref.Ref {
return s.m.Ref()
}
func (s EnumStruct) Chunks() []types.Future {
return s.m.Chunks()
}
func (s EnumStruct) Hand() Handedness {
return Handedness(s.m.Get(types.NewString("hand")).(types.UInt32))
}
+10
View File
@@ -4,6 +4,8 @@ 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/types"
)
func TestEnum(t *testing.T) {
@@ -33,3 +35,11 @@ func TestEnumValue(t *testing.T) {
st2 := EnumStructFromVal(val)
assert.True(st.Equals(st2))
}
func TestEnumIsValue(t *testing.T) {
cs := chunks.NewMemoryStore()
var v types.Value = NewEnumStruct()
ref := types.WriteValue(v, cs)
v2 := types.ReadValue(ref, cs)
assert.True(t, v.Equals(v2))
}
+9 -2
View File
@@ -44,14 +44,21 @@ func (l ListOfInt64) NomsValue() types.Value {
return l.l
}
func (l ListOfInt64) Equals(p ListOfInt64) bool {
return l.l.Equals(p.l)
func (l ListOfInt64) Equals(other types.Value) bool {
if other, ok := other.(ListOfInt64); ok {
return l.l.Equals(other.l)
}
return false
}
func (l ListOfInt64) Ref() ref.Ref {
return l.l.Ref()
}
func (l ListOfInt64) Chunks() []types.Future {
return l.l.Chunks()
}
// A Noms Value that describes ListOfInt64.
var __typeRefForListOfInt64 = types.MakeCompoundTypeRef("", types.ListKind, types.MakePrimitiveTypeRef(types.Int64Kind))
+18 -4
View File
@@ -45,14 +45,21 @@ func (m MapOfBoolToString) NomsValue() types.Value {
return m.m
}
func (m MapOfBoolToString) Equals(p MapOfBoolToString) bool {
return m.m.Equals(p.m)
func (m MapOfBoolToString) Equals(other types.Value) bool {
if other, ok := other.(MapOfBoolToString); ok {
return m.m.Equals(other.m)
}
return false
}
func (m MapOfBoolToString) Ref() ref.Ref {
return m.m.Ref()
}
func (m MapOfBoolToString) Chunks() []types.Future {
return m.m.Chunks()
}
// A Noms Value that describes MapOfBoolToString.
var __typeRefForMapOfBoolToString = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.BoolKind), types.MakePrimitiveTypeRef(types.StringKind))
@@ -158,14 +165,21 @@ func (m MapOfStringToValue) NomsValue() types.Value {
return m.m
}
func (m MapOfStringToValue) Equals(p MapOfStringToValue) bool {
return m.m.Equals(p.m)
func (m MapOfStringToValue) Equals(other types.Value) bool {
if other, ok := other.(MapOfStringToValue); ok {
return m.m.Equals(other.m)
}
return false
}
func (m MapOfStringToValue) Ref() ref.Ref {
return m.m.Ref()
}
func (m MapOfStringToValue) Chunks() []types.Future {
return m.m.Chunks()
}
// A Noms Value that describes MapOfStringToValue.
var __typeRefForMapOfStringToValue = types.MakeCompoundTypeRef("", types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakePrimitiveTypeRef(types.ValueKind))
+69 -14
View File
@@ -42,8 +42,15 @@ func (r RefOfListOfString) Ref() ref.Ref {
return r.r
}
func (r RefOfListOfString) Equals(other RefOfListOfString) bool {
return r.Ref() == other.Ref()
func (r RefOfListOfString) Equals(other types.Value) bool {
if other, ok := other.(RefOfListOfString); ok {
return r.r == other.r
}
return false
}
func (r RefOfListOfString) Chunks() []types.Future {
return nil
}
func (r RefOfListOfString) NomsValue() types.Value {
@@ -113,14 +120,21 @@ func (l ListOfString) NomsValue() types.Value {
return l.l
}
func (l ListOfString) Equals(p ListOfString) bool {
return l.l.Equals(p.l)
func (l ListOfString) Equals(other types.Value) bool {
if other, ok := other.(ListOfString); ok {
return l.l.Equals(other.l)
}
return false
}
func (l ListOfString) Ref() ref.Ref {
return l.l.Ref()
}
func (l ListOfString) Chunks() []types.Future {
return l.l.Chunks()
}
// A Noms Value that describes ListOfString.
var __typeRefForListOfString = types.MakeCompoundTypeRef("", types.ListKind, types.MakePrimitiveTypeRef(types.StringKind))
@@ -243,14 +257,21 @@ func (l ListOfRefOfFloat32) NomsValue() types.Value {
return l.l
}
func (l ListOfRefOfFloat32) Equals(p ListOfRefOfFloat32) bool {
return l.l.Equals(p.l)
func (l ListOfRefOfFloat32) Equals(other types.Value) bool {
if other, ok := other.(ListOfRefOfFloat32); ok {
return l.l.Equals(other.l)
}
return false
}
func (l ListOfRefOfFloat32) Ref() ref.Ref {
return l.l.Ref()
}
func (l ListOfRefOfFloat32) Chunks() []types.Future {
return l.l.Chunks()
}
// A Noms Value that describes ListOfRefOfFloat32.
var __typeRefForListOfRefOfFloat32 = types.MakeCompoundTypeRef("", types.ListKind, types.MakeCompoundTypeRef("", types.RefKind, types.MakePrimitiveTypeRef(types.Float32Kind)))
@@ -350,8 +371,15 @@ func (r RefOfFloat32) Ref() ref.Ref {
return r.r
}
func (r RefOfFloat32) Equals(other RefOfFloat32) bool {
return r.Ref() == other.Ref()
func (r RefOfFloat32) Equals(other types.Value) bool {
if other, ok := other.(RefOfFloat32); ok {
return r.r == other.r
}
return false
}
func (r RefOfFloat32) Chunks() []types.Future {
return nil
}
func (r RefOfFloat32) NomsValue() types.Value {
@@ -422,6 +450,12 @@ func (m StructWithRef) TypeRef() types.TypeRef {
return __typeRefForStructWithRef
}
func init() {
types.RegisterFromValFunction(__typeRefForStructWithRef, func(v types.Value) types.NomsValue {
return StructWithRefFromVal(v)
})
}
func StructWithRefFromVal(val types.Value) StructWithRef {
// TODO: Validate here
return StructWithRef{val.(types.Map)}
@@ -431,14 +465,21 @@ func (s StructWithRef) NomsValue() types.Value {
return s.m
}
func (s StructWithRef) Equals(other StructWithRef) bool {
return s.m.Equals(other.m)
func (s StructWithRef) Equals(other types.Value) bool {
if other, ok := other.(StructWithRef); ok {
return s.m.Equals(other.m)
}
return false
}
func (s StructWithRef) Ref() ref.Ref {
return s.m.Ref()
}
func (s StructWithRef) Chunks() []types.Future {
return s.m.Chunks()
}
func (s StructWithRef) R() RefOfSetOfFloat32 {
return RefOfSetOfFloat32FromVal(s.m.Get(types.NewString("r")))
}
@@ -461,8 +502,15 @@ func (r RefOfSetOfFloat32) Ref() ref.Ref {
return r.r
}
func (r RefOfSetOfFloat32) Equals(other RefOfSetOfFloat32) bool {
return r.Ref() == other.Ref()
func (r RefOfSetOfFloat32) Equals(other types.Value) bool {
if other, ok := other.(RefOfSetOfFloat32); ok {
return r.r == other.r
}
return false
}
func (r RefOfSetOfFloat32) Chunks() []types.Future {
return nil
}
func (r RefOfSetOfFloat32) NomsValue() types.Value {
@@ -534,14 +582,21 @@ func (s SetOfFloat32) NomsValue() types.Value {
return s.s
}
func (s SetOfFloat32) Equals(p SetOfFloat32) bool {
return s.s.Equals(p.s)
func (s SetOfFloat32) Equals(other types.Value) bool {
if other, ok := other.(SetOfFloat32); ok {
return s.s.Equals(other.s)
}
return false
}
func (s SetOfFloat32) Ref() ref.Ref {
return s.s.Ref()
}
func (s SetOfFloat32) Chunks() []types.Future {
return s.s.Chunks()
}
// A Noms Value that describes SetOfFloat32.
var __typeRefForSetOfFloat32 = types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.Float32Kind))
+9 -2
View File
@@ -46,14 +46,21 @@ func (s SetOfBool) NomsValue() types.Value {
return s.s
}
func (s SetOfBool) Equals(p SetOfBool) bool {
return s.s.Equals(p.s)
func (s SetOfBool) Equals(other types.Value) bool {
if other, ok := other.(SetOfBool); ok {
return s.s.Equals(other.s)
}
return false
}
func (s SetOfBool) Ref() ref.Ref {
return s.s.Ref()
}
func (s SetOfBool) Chunks() []types.Future {
return s.s.Chunks()
}
// A Noms Value that describes SetOfBool.
var __typeRefForSetOfBool = types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.BoolKind))
+24 -4
View File
@@ -65,14 +65,21 @@ func (l ListOfStruct) NomsValue() types.Value {
return l.l
}
func (l ListOfStruct) Equals(p ListOfStruct) bool {
return l.l.Equals(p.l)
func (l ListOfStruct) Equals(other types.Value) bool {
if other, ok := other.(ListOfStruct); ok {
return l.l.Equals(other.l)
}
return false
}
func (l ListOfStruct) Ref() ref.Ref {
return l.l.Ref()
}
func (l ListOfStruct) Chunks() []types.Future {
return l.l.Chunks()
}
// A Noms Value that describes ListOfStruct.
var __typeRefForListOfStruct = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Struct", __testPackageInFile_struct_CachedRef))
@@ -200,6 +207,12 @@ func (m Struct) TypeRef() types.TypeRef {
return __typeRefForStruct
}
func init() {
types.RegisterFromValFunction(__typeRefForStruct, func(v types.Value) types.NomsValue {
return StructFromVal(v)
})
}
func StructFromVal(val types.Value) Struct {
// TODO: Validate here
return Struct{val.(types.Map)}
@@ -209,14 +222,21 @@ func (s Struct) NomsValue() types.Value {
return s.m
}
func (s Struct) Equals(other Struct) bool {
return s.m.Equals(other.m)
func (s Struct) Equals(other types.Value) bool {
if other, ok := other.(Struct); ok {
return s.m.Equals(other.m)
}
return false
}
func (s Struct) Ref() ref.Ref {
return s.m.Ref()
}
func (s Struct) Chunks() []types.Future {
return s.m.Chunks()
}
func (s Struct) S() string {
return s.m.Get(types.NewString("s")).(types.String).String()
}
+15 -2
View File
@@ -72,6 +72,12 @@ func (m OptionalStruct) TypeRef() types.TypeRef {
return __typeRefForOptionalStruct
}
func init() {
types.RegisterFromValFunction(__typeRefForOptionalStruct, func(v types.Value) types.NomsValue {
return OptionalStructFromVal(v)
})
}
func OptionalStructFromVal(val types.Value) OptionalStruct {
// TODO: Validate here
return OptionalStruct{val.(types.Map)}
@@ -81,14 +87,21 @@ func (s OptionalStruct) NomsValue() types.Value {
return s.m
}
func (s OptionalStruct) Equals(other OptionalStruct) bool {
return s.m.Equals(other.m)
func (s OptionalStruct) Equals(other types.Value) bool {
if other, ok := other.(OptionalStruct); ok {
return s.m.Equals(other.m)
}
return false
}
func (s OptionalStruct) Ref() ref.Ref {
return s.m.Ref()
}
func (s OptionalStruct) Chunks() []types.Future {
return s.m.Chunks()
}
func (s OptionalStruct) S() (v string, ok bool) {
var vv types.Value
if vv, ok = s.m.MaybeGet(types.NewString("s")); ok {
+15 -2
View File
@@ -130,6 +130,12 @@ func (m StructPrimitives) TypeRef() types.TypeRef {
return __typeRefForStructPrimitives
}
func init() {
types.RegisterFromValFunction(__typeRefForStructPrimitives, func(v types.Value) types.NomsValue {
return StructPrimitivesFromVal(v)
})
}
func StructPrimitivesFromVal(val types.Value) StructPrimitives {
// TODO: Validate here
return StructPrimitives{val.(types.Map)}
@@ -139,14 +145,21 @@ func (s StructPrimitives) NomsValue() types.Value {
return s.m
}
func (s StructPrimitives) Equals(other StructPrimitives) bool {
return s.m.Equals(other.m)
func (s StructPrimitives) Equals(other types.Value) bool {
if other, ok := other.(StructPrimitives); ok {
return s.m.Equals(other.m)
}
return false
}
func (s StructPrimitives) Ref() ref.Ref {
return s.m.Ref()
}
func (s StructPrimitives) Chunks() []types.Future {
return s.m.Chunks()
}
func (s StructPrimitives) Uint64() uint64 {
return uint64(s.m.Get(types.NewString("uint64")).(types.UInt64))
}
+24 -4
View File
@@ -65,6 +65,12 @@ func (m Tree) TypeRef() types.TypeRef {
return __typeRefForTree
}
func init() {
types.RegisterFromValFunction(__typeRefForTree, func(v types.Value) types.NomsValue {
return TreeFromVal(v)
})
}
func TreeFromVal(val types.Value) Tree {
// TODO: Validate here
return Tree{val.(types.Map)}
@@ -74,14 +80,21 @@ func (s Tree) NomsValue() types.Value {
return s.m
}
func (s Tree) Equals(other Tree) bool {
return s.m.Equals(other.m)
func (s Tree) Equals(other types.Value) bool {
if other, ok := other.(Tree); ok {
return s.m.Equals(other.m)
}
return false
}
func (s Tree) Ref() ref.Ref {
return s.m.Ref()
}
func (s Tree) Chunks() []types.Future {
return s.m.Chunks()
}
func (s Tree) Children() ListOfTree {
return ListOfTreeFromVal(s.m.Get(types.NewString("children")))
}
@@ -127,14 +140,21 @@ func (l ListOfTree) NomsValue() types.Value {
return l.l
}
func (l ListOfTree) Equals(p ListOfTree) bool {
return l.l.Equals(p.l)
func (l ListOfTree) Equals(other types.Value) bool {
if other, ok := other.(ListOfTree); ok {
return l.l.Equals(other.l)
}
return false
}
func (l ListOfTree) Ref() ref.Ref {
return l.l.Ref()
}
func (l ListOfTree) Chunks() []types.Future {
return l.l.Chunks()
}
// A Noms Value that describes ListOfTree.
var __typeRefForListOfTree = types.MakeCompoundTypeRef("", types.ListKind, types.MakeTypeRef("Tree", __testPackageInFile_struct_recursive_CachedRef))
+24 -4
View File
@@ -80,6 +80,12 @@ func (m StructWithList) TypeRef() types.TypeRef {
return __typeRefForStructWithList
}
func init() {
types.RegisterFromValFunction(__typeRefForStructWithList, func(v types.Value) types.NomsValue {
return StructWithListFromVal(v)
})
}
func StructWithListFromVal(val types.Value) StructWithList {
// TODO: Validate here
return StructWithList{val.(types.Map)}
@@ -89,14 +95,21 @@ func (s StructWithList) NomsValue() types.Value {
return s.m
}
func (s StructWithList) Equals(other StructWithList) bool {
return s.m.Equals(other.m)
func (s StructWithList) Equals(other types.Value) bool {
if other, ok := other.(StructWithList); ok {
return s.m.Equals(other.m)
}
return false
}
func (s StructWithList) Ref() ref.Ref {
return s.m.Ref()
}
func (s StructWithList) Chunks() []types.Future {
return s.m.Chunks()
}
func (s StructWithList) L() ListOfUInt8 {
return ListOfUInt8FromVal(s.m.Get(types.NewString("l")))
}
@@ -166,14 +179,21 @@ func (l ListOfUInt8) NomsValue() types.Value {
return l.l
}
func (l ListOfUInt8) Equals(p ListOfUInt8) bool {
return l.l.Equals(p.l)
func (l ListOfUInt8) Equals(other types.Value) bool {
if other, ok := other.(ListOfUInt8); ok {
return l.l.Equals(other.l)
}
return false
}
func (l ListOfUInt8) Ref() ref.Ref {
return l.l.Ref()
}
func (l ListOfUInt8) Chunks() []types.Future {
return l.l.Chunks()
}
// A Noms Value that describes ListOfUInt8.
var __typeRefForListOfUInt8 = types.MakeCompoundTypeRef("", types.ListKind, types.MakePrimitiveTypeRef(types.UInt8Kind))
@@ -4,6 +4,8 @@ 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/types"
)
func TestStructWithList(t *testing.T) {
@@ -27,3 +29,24 @@ func TestStructWithList(t *testing.T) {
st2 := def2.New()
assert.Equal(uint8(22), st2.L().Get(2))
}
func TestStructIsValue(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
var v types.Value = StructWithListDef{
L: ListOfUInt8Def{0, 1, 2},
B: true,
S: "world",
I: 42,
}.New()
ref := types.WriteValue(v, cs)
v2 := types.ReadValue(ref, cs)
assert.True(v.Equals(v2))
s2 := v2.(StructWithList)
assert.True(s2.L().Equals(NewListOfUInt8().Append(0, 1, 2)))
assert.True(s2.B())
assert.Equal("world", s2.S())
assert.Equal(int64(42), s2.I())
}
+24 -4
View File
@@ -111,6 +111,12 @@ func (m StructWithUnionField) TypeRef() types.TypeRef {
return __typeRefForStructWithUnionField
}
func init() {
types.RegisterFromValFunction(__typeRefForStructWithUnionField, func(v types.Value) types.NomsValue {
return StructWithUnionFieldFromVal(v)
})
}
func StructWithUnionFieldFromVal(val types.Value) StructWithUnionField {
// TODO: Validate here
return StructWithUnionField{val.(types.Map)}
@@ -120,14 +126,21 @@ func (s StructWithUnionField) NomsValue() types.Value {
return s.m
}
func (s StructWithUnionField) Equals(other StructWithUnionField) bool {
return s.m.Equals(other.m)
func (s StructWithUnionField) Equals(other types.Value) bool {
if other, ok := other.(StructWithUnionField); ok {
return s.m.Equals(other.m)
}
return false
}
func (s StructWithUnionField) Ref() ref.Ref {
return s.m.Ref()
}
func (s StructWithUnionField) Chunks() []types.Future {
return s.m.Chunks()
}
func (s StructWithUnionField) A() float32 {
return float32(s.m.Get(types.NewString("a")).(types.Float32))
}
@@ -295,14 +308,21 @@ func (s SetOfUInt8) NomsValue() types.Value {
return s.s
}
func (s SetOfUInt8) Equals(p SetOfUInt8) bool {
return s.s.Equals(p.s)
func (s SetOfUInt8) Equals(other types.Value) bool {
if other, ok := other.(SetOfUInt8); ok {
return s.s.Equals(other.s)
}
return false
}
func (s SetOfUInt8) Ref() ref.Ref {
return s.s.Ref()
}
func (s SetOfUInt8) Chunks() []types.Future {
return s.s.Chunks()
}
// A Noms Value that describes SetOfUInt8.
var __typeRefForSetOfUInt8 = types.MakeCompoundTypeRef("", types.SetKind, types.MakePrimitiveTypeRef(types.UInt8Kind))
+45 -6
View File
@@ -82,6 +82,12 @@ func (m StructWithUnions) TypeRef() types.TypeRef {
return __typeRefForStructWithUnions
}
func init() {
types.RegisterFromValFunction(__typeRefForStructWithUnions, func(v types.Value) types.NomsValue {
return StructWithUnionsFromVal(v)
})
}
func StructWithUnionsFromVal(val types.Value) StructWithUnions {
// TODO: Validate here
return StructWithUnions{val.(types.Map)}
@@ -91,14 +97,21 @@ func (s StructWithUnions) NomsValue() types.Value {
return s.m
}
func (s StructWithUnions) Equals(other StructWithUnions) bool {
return s.m.Equals(other.m)
func (s StructWithUnions) Equals(other types.Value) bool {
if other, ok := other.(StructWithUnions); ok {
return s.m.Equals(other.m)
}
return false
}
func (s StructWithUnions) Ref() ref.Ref {
return s.m.Ref()
}
func (s StructWithUnions) Chunks() []types.Future {
return s.m.Chunks()
}
func (s StructWithUnions) A() __unionOfBOfFloat64AndCOfString {
return __unionOfBOfFloat64AndCOfStringFromVal(s.m.Get(types.NewString("a")))
}
@@ -177,6 +190,12 @@ func (m __unionOfBOfFloat64AndCOfString) TypeRef() types.TypeRef {
return __typeRefFor__unionOfBOfFloat64AndCOfString
}
func init() {
types.RegisterFromValFunction(__typeRefFor__unionOfBOfFloat64AndCOfString, func(v types.Value) types.NomsValue {
return __unionOfBOfFloat64AndCOfStringFromVal(v)
})
}
func __unionOfBOfFloat64AndCOfStringFromVal(val types.Value) __unionOfBOfFloat64AndCOfString {
// TODO: Validate here
return __unionOfBOfFloat64AndCOfString{val.(types.Map)}
@@ -186,14 +205,21 @@ func (s __unionOfBOfFloat64AndCOfString) NomsValue() types.Value {
return s.m
}
func (s __unionOfBOfFloat64AndCOfString) Equals(other __unionOfBOfFloat64AndCOfString) bool {
return s.m.Equals(other.m)
func (s __unionOfBOfFloat64AndCOfString) Equals(other types.Value) bool {
if other, ok := other.(__unionOfBOfFloat64AndCOfString); ok {
return s.m.Equals(other.m)
}
return false
}
func (s __unionOfBOfFloat64AndCOfString) Ref() ref.Ref {
return s.m.Ref()
}
func (s __unionOfBOfFloat64AndCOfString) Chunks() []types.Future {
return s.m.Chunks()
}
func (s __unionOfBOfFloat64AndCOfString) B() (val float64, ok bool) {
if s.m.Get(types.NewString("$unionIndex")).(types.UInt32) != 0 {
return
@@ -304,6 +330,12 @@ func (m __unionOfEOfFloat64AndFOfString) TypeRef() types.TypeRef {
return __typeRefFor__unionOfEOfFloat64AndFOfString
}
func init() {
types.RegisterFromValFunction(__typeRefFor__unionOfEOfFloat64AndFOfString, func(v types.Value) types.NomsValue {
return __unionOfEOfFloat64AndFOfStringFromVal(v)
})
}
func __unionOfEOfFloat64AndFOfStringFromVal(val types.Value) __unionOfEOfFloat64AndFOfString {
// TODO: Validate here
return __unionOfEOfFloat64AndFOfString{val.(types.Map)}
@@ -313,14 +345,21 @@ func (s __unionOfEOfFloat64AndFOfString) NomsValue() types.Value {
return s.m
}
func (s __unionOfEOfFloat64AndFOfString) Equals(other __unionOfEOfFloat64AndFOfString) bool {
return s.m.Equals(other.m)
func (s __unionOfEOfFloat64AndFOfString) Equals(other types.Value) bool {
if other, ok := other.(__unionOfEOfFloat64AndFOfString); ok {
return s.m.Equals(other.m)
}
return false
}
func (s __unionOfEOfFloat64AndFOfString) Ref() ref.Ref {
return s.m.Ref()
}
func (s __unionOfEOfFloat64AndFOfString) Chunks() []types.Future {
return s.m.Chunks()
}
func (s __unionOfEOfFloat64AndFOfString) E() (val float64, ok bool) {
if s.m.Get(types.NewString("$unionIndex")).(types.UInt32) != 0 {
return
+12
View File
@@ -18,6 +18,18 @@ func (v valueAsNomsValue) TypeRef() TypeRef {
return v.TypeRef()
}
func (v valueAsNomsValue) Ref() ref.Ref {
return v.Ref()
}
func (v valueAsNomsValue) Chunks() []Future {
return v.Chunks()
}
func (v valueAsNomsValue) Equals(other Value) bool {
return v.Equals(other)
}
func fromTypedEncodeable(w typedValueWrapper, cs chunks.ChunkSource) NomsValue {
i := w.TypedValue()
r := newJsonArrayReader(i, cs)
+5 -5
View File
@@ -8,18 +8,18 @@ import (
)
type testNomsValue struct {
Value
t TypeRef
v Value
}
func (nv testNomsValue) NomsValue() Value {
return nv.Value
}
func (nv testNomsValue) TypeRef() TypeRef {
return nv.t
}
func (nv testNomsValue) NomsValue() Value {
return nv.v
}
func TestWrite(t *testing.T) {
assert := assert.New(t)
+1 -1
View File
@@ -31,6 +31,6 @@ func RegisterFromValFunction(t TypeRef, f toNomsValueFunc) {
func ToNomsValueFromTypeRef(t TypeRef, v Value) NomsValue {
f, ok := toNomsValueMap[t.Ref()]
d.Chk.True(ok)
d.Chk.True(ok, "Missing to noms value function for: %s", t.Describe())
return f(v)
}
+1 -1
View File
@@ -22,7 +22,7 @@ func ReadValue(r ref.Ref, cs chunks.ChunkSource) Value {
i := enc.Decode(bytes.NewReader(c.Data()))
if i, ok := i.(typedValueWrapper); ok {
return fromTypedEncodeable(i, cs).NomsValue()
return fromTypedEncodeable(i, cs)
}
return fromEncodeable(i, cs).Deref(cs)
+1 -1
View File
@@ -12,8 +12,8 @@ type primitive interface {
}
type NomsValue interface {
Value
NomsValue() Value
TypeRef() TypeRef
}
func WriteValue(v interface{}, cs chunks.ChunkSink) ref.Ref {
+1 -1
View File
@@ -33,7 +33,7 @@ func TestWriteValue(t *testing.T) {
testEncode("j \"foo\"\n", NewString("foo"))
tref := MakePrimitiveTypeRef(StringKind)
nomsValueString := testNomsValue{tref, NewString("hi")}
nomsValueString := testNomsValue{Value: NewString("hi"), t: tref}
testEncode(fmt.Sprintf("t [%d,\"hi\"]\n", StringKind), nomsValueString)
}