Rename types.TypeRef to types.Type

There are probably still a lot of variable names and comments to fix,
but this updates all the Go code.

Towards #441
This commit is contained in:
Chris Masone
2015-11-09 08:26:32 -08:00
parent 8938c1e065
commit eda9b92870
57 changed files with 664 additions and 668 deletions
+3 -3
View File
@@ -48,11 +48,11 @@ Here is the diff:
--- a/nomdl/pkg/grammar.peg
+++ b/nomdl/pkg/grammar.peg
@@ -159,7 +159,7 @@ CompoundType <- `List` _ `(` _ t:Type _ `)` _ {
return types.MakeCompoundTypeRef(types.RefKind, t.(types.TypeRef)), nil
return types.MakeCompoundTypeRef(types.RefKind, t.(types.Type)), nil
}
-PrimitiveType <- p:(`UInt64` / `UInt32` / `UInt16` / `UInt8` / `Int64` / `Int32` / `Int16` / `Int8` / `Float64` / `Float32` / `Bool` / `String` / `Blob` / `Value` / `TypeRef`) {
+PrimitiveType <- p:(`UInt64` / `UInt32` / `UInt16` / `UInt8` / `Int64` / `Int32` / `Int16` / `Int8` / `Float64` / `Float32` / `Bool` / `String` / `Blob` / `Value` / `TypeRef` / `Package`) {
-PrimitiveType <- p:(`UInt64` / `UInt32` / `UInt16` / `UInt8` / `Int64` / `Int32` / `Int16` / `Int8` / `Float64` / `Float32` / `Bool` / `String` / `Blob` / `Value` / `Type`) {
+PrimitiveType <- p:(`UInt64` / `UInt32` / `UInt16` / `UInt8` / `Int64` / `Int32` / `Int16` / `Int8` / `Float64` / `Float32` / `Bool` / `String` / `Blob` / `Value` / `Type` / `Package`) {
return types.MakePrimitiveTypeRefByString(string(p.([]uint8))), nil
}
```
+26 -26
View File
@@ -1,4 +1,4 @@
// Package code provides Generator, which has methods for generating code snippets from a types.TypeRef.
// Package code provides Generator, which has methods for generating code snippets from a types.Type.
// Conceptually there are few type spaces here:
//
// - Def - MyStructDef, ListOfBoolDef; convenient Go types for working with data from a given Noms Value.
@@ -17,19 +17,19 @@ import (
"github.com/attic-labs/noms/types"
)
// Resolver provides a single method for resolving an unresolved types.TypeRef.
// Resolver provides a single method for resolving an unresolved types.Type.
type Resolver interface {
Resolve(t types.TypeRef) types.TypeRef
Resolve(t types.Type) types.Type
}
// Generator provides methods for generating code snippets from both resolved and unresolved types.TypeRefs. In the latter case, it uses R to resolve the types.TypeRef before generating code.
// Generator provides methods for generating code snippets from both resolved and unresolved types.TypeRefs. In the latter case, it uses R to resolve the types.Type before generating code.
type Generator struct {
R Resolver
TypesPackage string
}
// DefType returns a string containing the Go type that should be used as the 'Def' for the Noms type described by t.
func (gen Generator) DefType(t types.TypeRef) string {
func (gen Generator) DefType(t types.Type) string {
rt := gen.R.Resolve(t)
k := rt.Kind()
switch k {
@@ -48,13 +48,13 @@ func (gen Generator) DefType(t types.TypeRef) string {
case types.ValueKind:
return fmt.Sprintf("%sValue", gen.TypesPackage)
case types.TypeRefKind:
return fmt.Sprintf("%sTypeRef", gen.TypesPackage)
return fmt.Sprintf("%sType", gen.TypesPackage)
}
panic("unreachable")
}
// UserType returns a string containing the Go type that should be used when the Noms type described by t needs to be returned by a generated getter or taken as a parameter to a generated setter.
func (gen Generator) UserType(t types.TypeRef) string {
func (gen Generator) UserType(t types.Type) string {
rt := gen.R.Resolve(t)
k := rt.Kind()
switch k {
@@ -69,13 +69,13 @@ func (gen Generator) UserType(t types.TypeRef) string {
case types.ValueKind:
return fmt.Sprintf("%sValue", gen.TypesPackage)
case types.TypeRefKind:
return fmt.Sprintf("%sTypeRef", gen.TypesPackage)
return fmt.Sprintf("%sType", gen.TypesPackage)
}
panic("unreachable")
}
// DefToValue returns a string containing Go code to convert an instance of a Def type (named val) to a Noms types.Value of the type described by t.
func (gen Generator) DefToValue(val string, t types.TypeRef) string {
func (gen Generator) DefToValue(val string, t types.Type) string {
rt := gen.R.Resolve(t)
switch rt.Kind() {
case types.BlobKind, types.EnumKind, types.PackageKind, types.ValueKind, types.TypeRefKind:
@@ -91,7 +91,7 @@ func (gen Generator) DefToValue(val string, t types.TypeRef) string {
}
// DefToUser returns a string containing Go code to convert an instance of a Def type (named val) to a User type described by t.
func (gen Generator) DefToUser(val string, t types.TypeRef) string {
func (gen Generator) DefToUser(val string, t types.Type) string {
rt := gen.R.Resolve(t)
switch rt.Kind() {
case types.BlobKind, types.BoolKind, types.EnumKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.PackageKind, types.StringKind, types.TypeRefKind, types.UInt16Kind, types.UInt32Kind, types.UInt64Kind, types.UInt8Kind, types.ValueKind:
@@ -103,7 +103,7 @@ func (gen Generator) DefToUser(val string, t types.TypeRef) string {
}
// MayHaveChunks returns whether the type (t) may contain more chunks.
func (gen Generator) MayHaveChunks(t types.TypeRef) bool {
func (gen Generator) MayHaveChunks(t types.Type) bool {
rt := gen.R.Resolve(t)
switch rt.Kind() {
case types.BlobKind, types.ListKind, types.MapKind, types.PackageKind, types.RefKind, types.SetKind, types.StructKind, types.TypeRefKind, types.ValueKind:
@@ -115,7 +115,7 @@ func (gen Generator) MayHaveChunks(t types.TypeRef) bool {
}
// ValueToDef returns a string containing Go code to convert an instance of a types.Value (val) into the Def type appropriate for t.
func (gen Generator) ValueToDef(val string, t types.TypeRef) string {
func (gen Generator) ValueToDef(val string, t types.Type) string {
rt := gen.R.Resolve(t)
switch rt.Kind() {
case types.BlobKind, types.PackageKind, types.TypeRefKind:
@@ -135,7 +135,7 @@ func (gen Generator) ValueToDef(val string, t types.TypeRef) string {
}
// UserToDef returns a string containing Go code to convert an User value (val) into the Def type appropriate for t.
func (gen Generator) UserToDef(val string, t types.TypeRef) string {
func (gen Generator) UserToDef(val string, t types.Type) string {
rt := gen.R.Resolve(t)
switch rt.Kind() {
case types.BlobKind, types.EnumKind, types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.PackageKind, types.StringKind, types.TypeRefKind, types.UInt16Kind, types.UInt32Kind, types.UInt64Kind, types.UInt8Kind, types.ValueKind:
@@ -149,7 +149,7 @@ func (gen Generator) UserToDef(val string, t types.TypeRef) string {
}
// NativeToValue returns a string containing Go code to convert an instance of a native type (named val) to a Noms types.Value of the type described by t.
func (gen Generator) NativeToValue(val string, t types.TypeRef) string {
func (gen Generator) NativeToValue(val string, t types.Type) string {
t = gen.R.Resolve(t)
k := t.Kind()
switch k {
@@ -162,7 +162,7 @@ func (gen Generator) NativeToValue(val string, t types.TypeRef) string {
}
// ValueToNative returns a string containing Go code to convert an instance of a types.Value (val) into the native type appropriate for t.
func (gen Generator) ValueToNative(val string, t types.TypeRef) string {
func (gen Generator) ValueToNative(val string, t types.Type) string {
k := t.Kind()
switch k {
case types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.UInt16Kind, types.UInt32Kind, types.UInt64Kind, types.UInt8Kind:
@@ -175,7 +175,7 @@ func (gen Generator) ValueToNative(val string, t types.TypeRef) string {
}
// UserToValue returns a string containing Go code to convert an instance of a User type (named val) to a Noms types.Value of the type described by t. For Go primitive types, this will use NativeToValue(). For other types, their UserType is a Noms types.Value (or a wrapper around one), so this is more-or-less a pass-through.
func (gen Generator) UserToValue(val string, t types.TypeRef) string {
func (gen Generator) UserToValue(val string, t types.Type) string {
t = gen.R.Resolve(t)
k := t.Kind()
switch k {
@@ -188,7 +188,7 @@ func (gen Generator) UserToValue(val string, t types.TypeRef) string {
}
// ValueToUser returns a string containing Go code to convert an instance of a types.Value (val) into the User type appropriate for t. For Go primitives, this will use ValueToNative().
func (gen Generator) ValueToUser(val string, t types.TypeRef) string {
func (gen Generator) ValueToUser(val string, t types.Type) string {
rt := gen.R.Resolve(t)
k := rt.Kind()
switch k {
@@ -203,13 +203,13 @@ func (gen Generator) ValueToUser(val string, t types.TypeRef) string {
case types.ValueKind:
return val
case types.TypeRefKind:
return fmt.Sprintf("%s.(%sTypeRef)", val, gen.TypesPackage)
return fmt.Sprintf("%s.(%sType)", val, gen.TypesPackage)
}
panic("unreachable")
}
// UserZero returns a string containing Go code to create an uninitialized instance of the User type appropriate for t.
func (gen Generator) UserZero(t types.TypeRef) string {
func (gen Generator) UserZero(t types.Type) string {
rt := gen.R.Resolve(t)
k := rt.Kind()
switch k {
@@ -231,13 +231,13 @@ func (gen Generator) UserZero(t types.TypeRef) string {
// TODO: This is where a null Value would have been useful.
return fmt.Sprintf("%sBool(false)", gen.TypesPackage)
case types.TypeRefKind:
return fmt.Sprintf("%sTypeRef{R: ref.Ref{}}", gen.TypesPackage)
return fmt.Sprintf("%sType{R: ref.Ref{}}", gen.TypesPackage)
}
panic("unreachable")
}
// ValueZero returns a string containing Go code to create an uninitialized instance of the Noms types.Value appropriate for t.
func (gen Generator) ValueZero(t types.TypeRef) string {
func (gen Generator) ValueZero(t types.Type) string {
rt := gen.R.Resolve(t)
k := rt.Kind()
switch k {
@@ -261,13 +261,13 @@ func (gen Generator) ValueZero(t types.TypeRef) string {
// TODO: Use nil here
return fmt.Sprintf("%sBool(false)", gen.TypesPackage)
case types.TypeRefKind:
return fmt.Sprintf("%sTypeRef{R: ref.Ref{}}", gen.TypesPackage)
return fmt.Sprintf("%sType{R: ref.Ref{}}", gen.TypesPackage)
}
panic("unreachable")
}
// UserName returns the name of the User type appropriate for t, taking into account Noms types imported from other packages.
func (gen Generator) UserName(t types.TypeRef) string {
func (gen Generator) UserName(t types.Type) string {
rt := gen.R.Resolve(t)
k := rt.Kind()
switch k {
@@ -302,15 +302,15 @@ func (gen Generator) UserName(t types.TypeRef) string {
panic("unreachable")
}
func (gen Generator) refToId(t types.TypeRef) string {
func (gen Generator) refToId(t types.Type) string {
if !t.IsUnresolved() || !t.HasPackageRef() {
return gen.UserName(t)
}
return gen.UserName(gen.R.Resolve(t))
}
// ToTypeRef returns a string containing Go code that instantiates a types.TypeRef instance equivalent to t.
func (gen Generator) ToTypeRef(t types.TypeRef, fileID, packageName string) string {
// ToTypeRef returns a string containing Go code that instantiates a types.Type instance equivalent to t.
func (gen Generator) ToTypeRef(t types.Type, fileID, packageName string) string {
if t.HasPackageRef() {
return fmt.Sprintf(`%sMakeTypeRef(ref.Parse("%s"), %d)`, gen.TypesPackage, t.PackageRef().String(), t.Ordinal())
}
+2 -2
View File
@@ -14,7 +14,7 @@ type testResolver struct {
deps map[ref.Ref]types.Package
}
func (res *testResolver) Resolve(t types.TypeRef) types.TypeRef {
func (res *testResolver) Resolve(t types.Type) types.Type {
if !t.IsUnresolved() {
return t
}
@@ -31,7 +31,7 @@ func (res *testResolver) Resolve(t types.TypeRef) types.TypeRef {
func TestUserName(t *testing.T) {
assert := assert.New(t)
imported := types.NewPackage([]types.TypeRef{
imported := types.NewPackage([]types.Type{
types.MakeEnumTypeRef("E1", "a", "b"),
types.MakeStructTypeRef("S1", []types.Field{
types.Field{"f", types.MakePrimitiveTypeRef(types.BoolKind), false},
+34 -34
View File
@@ -216,7 +216,7 @@ type codeGen struct {
pkg pkg.Parsed
deps depsMap
written map[string]bool
toWrite []types.TypeRef
toWrite []types.Type
generator *code.Generator
templates *template.Template
sharedData sharedData
@@ -227,7 +227,7 @@ func newCodeGen(w io.Writer, fileID string, written map[string]bool, deps depsMa
if pkg.Name == "types" {
typesPackage = ""
}
gen := &codeGen{w, pkg, deps, written, []types.TypeRef{}, nil, nil, sharedData{
gen := &codeGen{w, pkg, deps, written, []types.Type{}, nil, nil, sharedData{
fileID,
pkg.Name,
typesPackage,
@@ -258,7 +258,7 @@ func (gen *codeGen) readTemplates() *template.Template {
}).ParseGlob(glob))
}
func (gen *codeGen) Resolve(t types.TypeRef) types.TypeRef {
func (gen *codeGen) Resolve(t types.Type) types.Type {
if !t.IsUnresolved() {
return t
}
@@ -284,7 +284,7 @@ func (gen *codeGen) WritePackage() {
HasTypes bool
Dependencies []ref.Ref
Name string
Types []types.TypeRef
Types []types.Type
}{
gen.sharedData,
len(pkgTypes) > 0,
@@ -310,7 +310,7 @@ func (gen *codeGen) WritePackage() {
}
}
func (gen *codeGen) shouldBeWritten(t types.TypeRef) bool {
func (gen *codeGen) shouldBeWritten(t types.Type) bool {
if t.IsUnresolved() {
return false
}
@@ -322,7 +322,7 @@ func (gen *codeGen) shouldBeWritten(t types.TypeRef) bool {
return !gen.written[gen.generator.UserName(t)]
}
func (gen *codeGen) writeTopLevel(t types.TypeRef, ordinal int) {
func (gen *codeGen) writeTopLevel(t types.Type, ordinal int) {
switch t.Kind() {
case types.EnumKind:
gen.writeEnum(t, ordinal)
@@ -334,7 +334,7 @@ func (gen *codeGen) writeTopLevel(t types.TypeRef, ordinal int) {
}
// write generates the code for the given type.
func (gen *codeGen) write(t types.TypeRef) {
func (gen *codeGen) write(t types.Type) {
if !gen.shouldBeWritten(t) {
return
}
@@ -355,31 +355,31 @@ func (gen *codeGen) write(t types.TypeRef) {
}
}
func (gen *codeGen) writeLater(t types.TypeRef) {
func (gen *codeGen) writeLater(t types.Type) {
if !gen.shouldBeWritten(t) {
return
}
gen.toWrite = append(gen.toWrite, t)
}
func (gen *codeGen) writeTemplate(tmpl string, t types.TypeRef, data interface{}) {
func (gen *codeGen) writeTemplate(tmpl string, t types.Type, data interface{}) {
err := gen.templates.ExecuteTemplate(gen.w, tmpl, data)
d.Exp.NoError(err)
gen.written[gen.generator.UserName(t)] = true
}
func (gen *codeGen) writeStruct(t types.TypeRef, ordinal int) {
func (gen *codeGen) writeStruct(t types.Type, ordinal int) {
d.Chk.True(ordinal >= 0)
desc := t.Desc.(types.StructDesc)
data := struct {
sharedData
Name string
Type types.TypeRef
Type types.Type
Ordinal int
Fields []types.Field
Choices types.Choices
HasUnion bool
UnionZeroType types.TypeRef
UnionZeroType types.Type
CanUseDef bool
}{
gen.sharedData,
@@ -408,13 +408,13 @@ func (gen *codeGen) writeStruct(t types.TypeRef, ordinal int) {
}
}
func (gen *codeGen) writeList(t types.TypeRef) {
func (gen *codeGen) writeList(t types.Type) {
elemTypes := t.Desc.(types.CompoundDesc).ElemTypes
data := struct {
sharedData
Name string
Type types.TypeRef
ElemType types.TypeRef
Type types.Type
ElemType types.Type
CanUseDef bool
}{
gen.sharedData,
@@ -427,14 +427,14 @@ func (gen *codeGen) writeList(t types.TypeRef) {
gen.writeLater(elemTypes[0])
}
func (gen *codeGen) writeMap(t types.TypeRef) {
func (gen *codeGen) writeMap(t types.Type) {
elemTypes := t.Desc.(types.CompoundDesc).ElemTypes
data := struct {
sharedData
Name string
Type types.TypeRef
KeyType types.TypeRef
ValueType types.TypeRef
Type types.Type
KeyType types.Type
ValueType types.Type
CanUseDef bool
}{
gen.sharedData,
@@ -449,13 +449,13 @@ func (gen *codeGen) writeMap(t types.TypeRef) {
gen.writeLater(elemTypes[1])
}
func (gen *codeGen) writeRef(t types.TypeRef) {
func (gen *codeGen) writeRef(t types.Type) {
elemTypes := t.Desc.(types.CompoundDesc).ElemTypes
data := struct {
sharedData
Name string
Type types.TypeRef
ElemType types.TypeRef
Type types.Type
ElemType types.Type
}{
gen.sharedData,
gen.generator.UserName(t),
@@ -466,13 +466,13 @@ func (gen *codeGen) writeRef(t types.TypeRef) {
gen.writeLater(elemTypes[0])
}
func (gen *codeGen) writeSet(t types.TypeRef) {
func (gen *codeGen) writeSet(t types.Type) {
elemTypes := t.Desc.(types.CompoundDesc).ElemTypes
data := struct {
sharedData
Name string
Type types.TypeRef
ElemType types.TypeRef
Type types.Type
ElemType types.Type
CanUseDef bool
}{
gen.sharedData,
@@ -485,12 +485,12 @@ func (gen *codeGen) writeSet(t types.TypeRef) {
gen.writeLater(elemTypes[0])
}
func (gen *codeGen) writeEnum(t types.TypeRef, ordinal int) {
func (gen *codeGen) writeEnum(t types.Type, ordinal int) {
d.Chk.True(ordinal >= 0)
data := struct {
sharedData
Name string
Type types.TypeRef
Type types.Type
Ordinal int
Ids []string
}{
@@ -504,11 +504,11 @@ func (gen *codeGen) writeEnum(t types.TypeRef, ordinal int) {
gen.writeTemplate("enum.tmpl", t, data)
}
func (gen *codeGen) canUseDef(t types.TypeRef) bool {
func (gen *codeGen) canUseDef(t types.Type) bool {
cache := map[string]bool{}
var rec func(t types.TypeRef, p types.Package) bool
rec = func(t types.TypeRef, p types.Package) bool {
var rec func(t types.Type, p types.Package) bool
rec = func(t types.Type, p types.Package) bool {
if t.HasPackageRef() {
p = gen.deps[t.PackageRef()]
d.Chk.NotNil(p)
@@ -546,11 +546,11 @@ func (gen *codeGen) canUseDef(t types.TypeRef) bool {
// We use a go map as the def for Set and Map. These cannot have a key that is a
// Set, Map or a List because slices and maps are not comparable in go.
func (gen *codeGen) containsNonComparable(t types.TypeRef) bool {
func (gen *codeGen) containsNonComparable(t types.Type) bool {
cache := map[string]bool{}
var rec func(t types.TypeRef, p types.Package) bool
rec = func(t types.TypeRef, p types.Package) bool {
var rec func(t types.Type, p types.Package) bool
rec = func(t types.Type, p types.Package) bool {
if t.HasPackageRef() {
p = gen.deps[t.PackageRef()]
d.Chk.NotNil(p)
@@ -583,7 +583,7 @@ func (gen *codeGen) containsNonComparable(t types.TypeRef) bool {
return rec(t, gen.pkg.Package)
}
func resolveInPackage(t types.TypeRef, p *types.Package) types.TypeRef {
func resolveInPackage(t types.Type, p *types.Package) types.Type {
if !t.IsUnresolved() {
return t
}
+6 -6
View File
@@ -154,14 +154,14 @@ func TestSkipDuplicateTypes(t *testing.T) {
assert.NoError(err)
defer os.RemoveAll(dir)
leaf1 := types.NewPackage([]types.TypeRef{
leaf1 := types.NewPackage([]types.Type{
types.MakeEnumTypeRef("E1", "a", "b"),
types.MakeStructTypeRef("S1", []types.Field{
types.Field{"f", types.MakeCompoundTypeRef(types.ListKind, types.MakePrimitiveTypeRef(types.UInt16Kind)), false},
types.Field{"e", types.MakeTypeRef(ref.Ref{}, 0), false},
}, types.Choices{}),
}, []ref.Ref{})
leaf2 := types.NewPackage([]types.TypeRef{
leaf2 := types.NewPackage([]types.Type{
types.MakeStructTypeRef("S2", []types.Field{
types.Field{"f", types.MakeCompoundTypeRef(types.ListKind, types.MakePrimitiveTypeRef(types.UInt16Kind)), false},
}, types.Choices{}),
@@ -188,15 +188,15 @@ func TestGenerateDeps(t *testing.T) {
assert.NoError(err)
defer os.RemoveAll(dir)
leaf1 := types.NewPackage([]types.TypeRef{types.MakeEnumTypeRef("e1", "a", "b")}, []ref.Ref{})
leaf1 := types.NewPackage([]types.Type{types.MakeEnumTypeRef("e1", "a", "b")}, []ref.Ref{})
leaf1Ref := types.WriteValue(leaf1, cs)
leaf2 := types.NewPackage([]types.TypeRef{types.MakePrimitiveTypeRef(types.BoolKind)}, []ref.Ref{})
leaf2 := types.NewPackage([]types.Type{types.MakePrimitiveTypeRef(types.BoolKind)}, []ref.Ref{})
leaf2Ref := types.WriteValue(leaf2, cs)
depender := types.NewPackage([]types.TypeRef{}, []ref.Ref{leaf1Ref})
depender := types.NewPackage([]types.Type{}, []ref.Ref{leaf1Ref})
dependerRef := types.WriteValue(depender, cs)
top := types.NewPackage([]types.TypeRef{}, []ref.Ref{leaf2Ref, dependerRef})
top := types.NewPackage([]types.Type{}, []ref.Ref{leaf2Ref, dependerRef})
types.RegisterPackage(&top)
localPkgs := refSet{top.Ref(): true}
+2 -2
View File
@@ -13,9 +13,9 @@ func New{{.Name}}() {{.Name}} {
return {{.Name}}(0)
}
var __typeRefFor{{.Name}} {{$typesPackage}}TypeRef
var __typeRefFor{{.Name}} {{$typesPackage}}Type
func (e {{.Name}}) TypeRef() {{$typesPackage}}TypeRef {
func (e {{.Name}}) Type() {{$typesPackage}}Type {
return __typeRefFor{{.Name}}
}
+1 -1
View File
@@ -16,7 +16,7 @@ var __{{.Name}}PackageInFile_{{.FileID}}_CachedRef ref.Ref
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
p := {{$typesPackage}}NewPackage([]{{$typesPackage}}TypeRef{ {{range $t := .Types}}
p := {{$typesPackage}}NewPackage([]{{$typesPackage}}Type{ {{range $t := .Types}}
{{toTypesTypeRef $t "" ""}},{{end}}
}, []ref.Ref{ {{range $deps := .Dependencies}}
ref.Parse("{{$deps}}"),{{end}}
+4 -4
View File
@@ -32,7 +32,7 @@ func New{{.Name}}() {{.Name}} {
{{end}}
func (l {{.Name}}) Equals(other {{$typesPackage}}Value) bool {
return other != nil && __typeRefFor{{.Name}}.Equals(other.TypeRef()) && l.Ref() == other.Ref()
return other != nil && __typeRefFor{{.Name}}.Equals(other.Type()) && l.Ref() == other.Ref()
}
func (l {{.Name}}) Ref() ref.Ref {
@@ -40,7 +40,7 @@ func (l {{.Name}}) Ref() ref.Ref {
}
func (l {{.Name}}) Chunks() (chunks []ref.Ref) {
chunks = append(chunks, l.TypeRef().Chunks()...)
chunks = append(chunks, l.Type().Chunks()...)
chunks = append(chunks, l.l.Chunks()...)
return
}
@@ -50,9 +50,9 @@ func (l {{.Name}}) ChildValues() []{{$typesPackage}}Value {
}
// A Noms Value that describes {{.Name}}.
var __typeRefFor{{.Name}} {{$typesPackage}}TypeRef
var __typeRefFor{{.Name}} {{$typesPackage}}Type
func (m {{.Name}}) TypeRef() {{$typesPackage}}TypeRef {
func (m {{.Name}}) Type() {{$typesPackage}}Type {
return __typeRefFor{{.Name}}
}
+4 -4
View File
@@ -33,7 +33,7 @@ func New{{.Name}}() {{.Name}} {
{{end}}
func (m {{.Name}}) Equals(other {{$typesPackage}}Value) bool {
return other != nil && __typeRefFor{{.Name}}.Equals(other.TypeRef()) && m.Ref() == other.Ref()
return other != nil && __typeRefFor{{.Name}}.Equals(other.Type()) && m.Ref() == other.Ref()
}
func (m {{.Name}}) Ref() ref.Ref {
@@ -41,7 +41,7 @@ func (m {{.Name}}) Ref() ref.Ref {
}
func (m {{.Name}}) Chunks() (chunks []ref.Ref) {
chunks = append(chunks, m.TypeRef().Chunks()...)
chunks = append(chunks, m.Type().Chunks()...)
chunks = append(chunks, m.m.Chunks()...)
return
}
@@ -51,9 +51,9 @@ func (m {{.Name}}) ChildValues() []{{$typesPackage}}Value {
}
// A Noms Value that describes {{.Name}}.
var __typeRefFor{{.Name}} {{$typesPackage}}TypeRef
var __typeRefFor{{.Name}} {{$typesPackage}}Type
func (m {{.Name}}) TypeRef() {{$typesPackage}}TypeRef {
func (m {{.Name}}) Type() {{$typesPackage}}Type {
return __typeRefFor{{.Name}}
}
+4 -4
View File
@@ -20,11 +20,11 @@ func (r {{.Name}}) Ref() ref.Ref {
}
func (r {{.Name}}) Equals(other {{$typesPackage}}Value) bool {
return other != nil && __typeRefFor{{.Name}}.Equals(other.TypeRef()) && r.Ref() == other.Ref()
return other != nil && __typeRefFor{{.Name}}.Equals(other.Type()) && r.Ref() == other.Ref()
}
func (r {{.Name}}) Chunks() (chunks []ref.Ref) {
chunks = append(chunks, r.TypeRef().Chunks()...)
chunks = append(chunks, r.Type().Chunks()...)
chunks = append(chunks, r.target)
return
}
@@ -34,9 +34,9 @@ func (r {{.Name}}) ChildValues() []{{$typesPackage}}Value {
}
// A Noms Value that describes {{.Name}}.
var __typeRefFor{{.Name}} {{$typesPackage}}TypeRef
var __typeRefFor{{.Name}} {{$typesPackage}}Type
func (m {{.Name}}) TypeRef() {{$typesPackage}}TypeRef {
func (m {{.Name}}) Type() {{$typesPackage}}Type {
return __typeRefFor{{.Name}}
}
+4 -4
View File
@@ -35,7 +35,7 @@ func New{{.Name}}() {{.Name}} {
{{end}}
func (s {{.Name}}) Equals(other {{$typesPackage}}Value) bool {
return other != nil && __typeRefFor{{.Name}}.Equals(other.TypeRef()) && s.Ref() == other.Ref()
return other != nil && __typeRefFor{{.Name}}.Equals(other.Type()) && s.Ref() == other.Ref()
}
func (s {{.Name}}) Ref() ref.Ref {
@@ -43,7 +43,7 @@ func (s {{.Name}}) Ref() ref.Ref {
}
func (s {{.Name}}) Chunks() (chunks []ref.Ref) {
chunks = append(chunks, s.TypeRef().Chunks()...)
chunks = append(chunks, s.Type().Chunks()...)
chunks = append(chunks, s.s.Chunks()...)
return
}
@@ -53,9 +53,9 @@ func (s {{.Name}}) ChildValues() []{{$typesPackage}}Value {
}
// A Noms Value that describes {{.Name}}.
var __typeRefFor{{.Name}} {{$typesPackage}}TypeRef
var __typeRefFor{{.Name}} {{$typesPackage}}Type
func (m {{.Name}}) TypeRef() {{$typesPackage}}TypeRef {
func (m {{.Name}}) Type() {{$typesPackage}}Type {
return __typeRefFor{{.Name}}
}
+3 -3
View File
@@ -45,9 +45,9 @@ func New{{.Name}}() {{.Name}} {
}
{{end}}
var __typeRefFor{{.Name}} {{$typesPackage}}TypeRef
var __typeRefFor{{.Name}} {{$typesPackage}}Type
func (m {{.Name}}) TypeRef() {{$typesPackage}}TypeRef {
func (m {{.Name}}) Type() {{$typesPackage}}Type {
return __typeRefFor{{.Name}}
}
@@ -88,7 +88,7 @@ func readerFor{{.Name}}(v {{$typesPackage}}Value) []{{$typesPackage}}Value {
}
func (s {{.Name}}) Equals(other {{$typesPackage}}Value) bool {
return other != nil && __typeRefFor{{.Name}}.Equals(other.TypeRef()) && s.Ref() == other.Ref()
return other != nil && __typeRefFor{{.Name}}.Equals(other.Type()) && s.Ref() == other.Ref()
}
func (s {{.Name}}) Ref() ref.Ref {
+1 -1
View File
@@ -104,6 +104,6 @@ func TestStructWithRefChunks(t *testing.T) {
R: set.Ref(),
}.New()
// 1 for the TypeRef and 1 for the ref in the R field.
// 1 for the Type and 1 for the ref in the R field.
assert.Len(str.Chunks(), 2)
}
+2 -2
View File
@@ -41,7 +41,7 @@ func TestTypeRef(t *testing.T) {
def := gen.StructDef{"hi", true}
st := def.New()
typ := st.TypeRef()
typ := st.Type()
assert.EqualValues(0, typ.Ordinal())
assert.Equal(types.UnresolvedKind, typ.Kind())
}
@@ -52,6 +52,6 @@ func TestStructChunks(t *testing.T) {
st := gen.StructDef{"hi", true}.New()
cs := st.Chunks()
// One chunk for the TypeRef
// One chunk for the Type
assert.Len(cs, 1)
}
@@ -53,7 +53,7 @@ func TestListOfImportsDef(t *testing.T) {
func TestDepsAndPackageRefs(t *testing.T) {
assert := assert.New(t)
tr := gen.NewImportUser().ImportedStruct().TypeRef()
tr := gen.NewImportUser().ImportedStruct().Type()
assert.Equal(types.UnresolvedKind, tr.Kind())
assert.True(tr.HasPackageRef())
p := types.LookupPackage(tr.PackageRef())
+11 -11
View File
@@ -14,9 +14,9 @@ type namespaceIdent struct {
Package <- _ dd:Definition+ _ EOF {
aliases := map[string]string{}
usings := []types.TypeRef{}
usings := []types.Type{}
seenTypes := map[string]bool{}
orderedTypes := []types.TypeRef{}
orderedTypes := []types.Type{}
for _, d := range dd.([]interface{}) {
switch d := d.(type) {
default:
@@ -26,8 +26,8 @@ Package <- _ dd:Definition+ _ EOF {
return nil, fmt.Errorf("Redefinition of " + d.Name)
}
aliases[d.Name] = d.Target
case types.TypeRef:
switch d.Desc.Kind() {
case types.Type:
switch d.Kind() {
default:
return nil, fmt.Errorf("%v can't be defined at the top-level", d)
case types.ListKind, types.MapKind, types.RefKind, types.SetKind:
@@ -129,16 +129,16 @@ Union <- `union` _ `{` _ u:UnionField+ _ `}` _ {
}
Field <- i:Ident _ `:` _ o:(`optional` _)? t:Type _ {
return types.Field{i.(string), t.(types.TypeRef), o != nil}, nil
return types.Field{i.(string), t.(types.Type), o != nil}, nil
}
UnionField <- i:Ident _ `:` _ t:Type _ {
return types.Field{i.(string), t.(types.TypeRef), false}, nil
return types.Field{i.(string), t.(types.Type), false}, nil
}
Type <- t:(PrimitiveType / CompoundType / Union / NamespaceIdent) {
switch t := t.(type) {
case types.TypeRef:
case types.Type:
return t, nil
case types.Choices:
return types.MakeStructTypeRef("", nil, t), nil
@@ -150,13 +150,13 @@ Type <- t:(PrimitiveType / CompoundType / Union / NamespaceIdent) {
}
CompoundType <- `List` _ `(` _ t:Type _ `)` _ {
return types.MakeCompoundTypeRef(types.ListKind, t.(types.TypeRef)), nil
return types.MakeCompoundTypeRef(types.ListKind, t.(types.Type)), nil
} / `Map` _ `(` _ k:Type _ `,` _ v:Type _ `)` _ {
return types.MakeCompoundTypeRef(types.MapKind, k.(types.TypeRef), v.(types.TypeRef)), nil
return types.MakeCompoundTypeRef(types.MapKind, k.(types.Type), v.(types.Type)), nil
} / `Set` _ `(` _ t:Type _ `)` _ {
return types.MakeCompoundTypeRef(types.SetKind, t.(types.TypeRef)), nil
return types.MakeCompoundTypeRef(types.SetKind, t.(types.Type)), nil
} / `Ref` _ `(` _ t:Type _ `)` _ {
return types.MakeCompoundTypeRef(types.RefKind, t.(types.TypeRef)), nil
return types.MakeCompoundTypeRef(types.RefKind, t.(types.Type)), nil
}
PrimitiveType <- p:(`UInt64` / `UInt32` / `UInt16` / `UInt8` / `Int64` / `Int32` / `Int16` / `Int8` / `Float64` / `Float32` / `Bool` / `String` / `Blob` / `Value` / `TypeRef`) {
+275 -275
View File
File diff suppressed because it is too large Load Diff
@@ -34,7 +34,7 @@ func (suite *ImportTestSuite) SetupTest() {
types.Field{"b", types.MakePrimitiveTypeRef(types.BoolKind), false},
types.Field{"i", types.MakePrimitiveTypeRef(types.Int8Kind), false},
})
suite.nested = types.NewPackage([]types.TypeRef{ns}, []ref.Ref{})
suite.nested = types.NewPackage([]types.Type{ns}, []ref.Ref{})
suite.nestedRef = types.WriteValue(suite.nested, suite.cs)
fs := types.MakeStructTypeRef("ForeignStruct", []types.Field{
@@ -43,37 +43,37 @@ func (suite *ImportTestSuite) SetupTest() {
},
types.Choices{})
fe := types.MakeEnumTypeRef("ForeignEnum", "uno", "dos")
suite.imported = types.NewPackage([]types.TypeRef{fs, fe}, []ref.Ref{suite.nestedRef})
suite.imported = types.NewPackage([]types.Type{fs, fe}, []ref.Ref{suite.nestedRef})
suite.importRef = types.WriteValue(suite.imported, suite.cs)
}
func (suite *ImportTestSuite) TestGetDeps() {
deps := GetDeps([]ref.Ref{suite.importRef}, suite.cs)
deps := getDeps([]ref.Ref{suite.importRef}, suite.cs)
suite.Len(deps, 1)
imported, ok := deps[suite.importRef]
suite.True(ok, "%s is a dep; should have been found.", suite.importRef.String())
deps = GetDeps(imported.Dependencies(), suite.cs)
deps = getDeps(imported.Dependencies(), suite.cs)
suite.Len(deps, 1)
imported, ok = deps[suite.nestedRef]
suite.True(ok, "%s is a dep; should have been found.", suite.nestedRef.String())
}
func (suite *ImportTestSuite) TestResolveNamespace() {
deps := GetDeps([]ref.Ref{suite.importRef}, suite.cs)
deps := getDeps([]ref.Ref{suite.importRef}, suite.cs)
t := resolveNamespace(types.MakeUnresolvedTypeRef("Other", "ForeignEnum"), map[string]ref.Ref{"Other": suite.importRef}, deps)
suite.EqualValues(types.MakeTypeRef(suite.importRef, 1), t)
}
func (suite *ImportTestSuite) TestUnknownAlias() {
deps := GetDeps([]ref.Ref{suite.importRef}, suite.cs)
deps := getDeps([]ref.Ref{suite.importRef}, suite.cs)
suite.Panics(func() {
resolveNamespace(types.MakeUnresolvedTypeRef("Bother", "ForeignEnum"), map[string]ref.Ref{"Other": suite.importRef}, deps)
})
}
func (suite *ImportTestSuite) TestUnknownImportedType() {
deps := GetDeps([]ref.Ref{suite.importRef}, suite.cs)
deps := getDeps([]ref.Ref{suite.importRef}, suite.cs)
suite.Panics(func() {
resolveNamespace(types.MakeUnresolvedTypeRef("Other", "NotThere"), map[string]ref.Ref{"Other": suite.importRef}, deps)
})
@@ -86,13 +86,13 @@ func (suite *ImportTestSuite) TestDetectFreeVariable() {
},
types.Choices{})
suite.Panics(func() {
inter := intermediate{Types: []types.TypeRef{ls}}
inter := intermediate{Types: []types.Type{ls}}
resolveLocalOrdinals(&inter)
})
}
func (suite *ImportTestSuite) TestImports() {
find := func(n string, tref types.TypeRef) types.Field {
find := func(n string, tref types.Type) types.Field {
suite.Equal(types.StructKind, tref.Kind())
for _, f := range tref.Desc.(types.StructDesc).Fields {
if f.Name == n {
@@ -102,7 +102,7 @@ func (suite *ImportTestSuite) TestImports() {
suite.Fail("Could not find field", "%s not present", n)
return types.Field{}
}
findChoice := func(n string, tref types.TypeRef) types.Field {
findChoice := func(n string, tref types.Type) types.Field {
suite.Equal(types.StructKind, tref.Kind())
for _, f := range tref.Desc.(types.StructDesc).Union {
if f.Name == n {
+15 -15
View File
@@ -27,7 +27,7 @@ func ParseNomDL(packageName string, r io.Reader, includePath string, cs chunks.C
}
resolveLocalOrdinals(&i)
resolveNamespaces(&i, imports, GetDeps(deps, cs))
resolveNamespaces(&i, imports, getDeps(deps, cs))
return Parsed{
types.NewPackage(i.Types, deps),
i.Name,
@@ -35,8 +35,8 @@ func ParseNomDL(packageName string, r io.Reader, includePath string, cs chunks.C
}
}
// GetDeps reads the types.Package objects referred to by depRefs out of cs and returns a map of ref: PackageDef.
func GetDeps(deps []ref.Ref, cs chunks.ChunkStore) map[ref.Ref]types.Package {
// getDeps reads the types.Package objects referred to by depRefs out of cs and returns a map of ref: PackageDef.
func getDeps(deps []ref.Ref, cs chunks.ChunkStore) map[ref.Ref]types.Package {
depsMap := map[ref.Ref]types.Package{}
for _, depRef := range deps {
v := types.ReadValue(depRef, cs)
@@ -51,17 +51,17 @@ func GetDeps(deps []ref.Ref, cs chunks.ChunkStore) map[ref.Ref]types.Package {
type Parsed struct {
types.Package
Name string
UsingDeclarations []types.TypeRef
UsingDeclarations []types.Type
}
type intermediate struct {
Name string
Aliases map[string]string
UsingDeclarations []types.TypeRef
Types []types.TypeRef
UsingDeclarations []types.Type
Types []types.Type
}
func indexOf(t types.TypeRef, ts []types.TypeRef) int16 {
func indexOf(t types.Type, ts []types.Type) int16 {
for i, tt := range ts {
if tt.Name() == t.Name() && tt.Namespace() == "" {
return int16(i)
@@ -70,7 +70,7 @@ func indexOf(t types.TypeRef, ts []types.TypeRef) int16 {
return -1
}
func (i *intermediate) checkLocal(t types.TypeRef) bool {
func (i *intermediate) checkLocal(t types.Type) bool {
if t.Namespace() == "" {
d.Chk.True(t.HasOrdinal(), "Invalid local reference")
return true
@@ -110,14 +110,14 @@ func resolveImports(aliases map[string]string, includePath string, cs chunks.Chu
}
func resolveLocalOrdinals(p *intermediate) {
var rec func(t types.TypeRef) types.TypeRef
var rec func(t types.Type) types.Type
resolveFields := func(fields []types.Field) {
for idx, f := range fields {
f.T = rec(f.T)
fields[idx] = f
}
}
rec = func(t types.TypeRef) types.TypeRef {
rec = func(t types.Type) types.Type {
if t.IsUnresolved() {
if t.Namespace() == "" && !t.HasOrdinal() {
ordinal := indexOf(t, p.Types)
@@ -149,7 +149,7 @@ func resolveLocalOrdinals(p *intermediate) {
}
func resolveNamespaces(p *intermediate, aliases map[string]ref.Ref, deps map[ref.Ref]types.Package) {
var rec func(t types.TypeRef) types.TypeRef
var rec func(t types.Type) types.Type
resolveFields := func(fields []types.Field) {
for idx, f := range fields {
if f.T.IsUnresolved() {
@@ -165,7 +165,7 @@ func resolveNamespaces(p *intermediate, aliases map[string]ref.Ref, deps map[ref
fields[idx] = f
}
}
rec = func(t types.TypeRef) types.TypeRef {
rec = func(t types.Type) types.Type {
if t.IsUnresolved() {
if p.checkLocal(t) {
return t
@@ -195,7 +195,7 @@ func resolveNamespaces(p *intermediate, aliases map[string]ref.Ref, deps map[ref
}
}
func resolveNamespace(t types.TypeRef, aliases map[string]ref.Ref, deps map[ref.Ref]types.Package) types.TypeRef {
func resolveNamespace(t types.Type, aliases map[string]ref.Ref, deps map[ref.Ref]types.Package) types.Type {
pkgRef, ok := aliases[t.Namespace()]
d.Exp.True(ok, "Could not find import aliased to %s", t.Namespace())
d.Chk.NotEqual("", t.Name())
@@ -205,9 +205,9 @@ func resolveNamespace(t types.TypeRef, aliases map[string]ref.Ref, deps map[ref.
}
// expandStruct takes a struct definition and expands the internal structs created for unions.
func expandStruct(t types.TypeRef, ordinal int) []types.TypeRef {
func expandStruct(t types.Type, ordinal int) []types.Type {
d.Chk.Equal(types.StructKind, t.Kind())
ts := []types.TypeRef{t}
ts := []types.Type{t}
ordinal++
doFields := func(fields []types.Field) []types.Field {
+4 -4
View File
@@ -264,21 +264,21 @@ type testField struct {
}
func (t testField) toField() types.Field {
return types.Field{t.Name, t.D.(types.TypeRef), t.Optional}
return types.Field{t.Name, t.D.(types.Type), t.Optional}
}
type describable interface {
Describe() string
}
func (suite *ParsedResultTestSuite) findTypeByName(n string, ts []types.TypeRef) types.TypeRef {
func (suite *ParsedResultTestSuite) findTypeByName(n string, ts []types.Type) types.Type {
for _, t := range ts {
if n == t.Name() {
return t
}
}
suite.Fail("Failed to find type by name")
return types.TypeRef{}
panic("Unreachable")
}
func (suite *ParsedResultTestSuite) checkStruct(pkg intermediate, s structTestCase) {
@@ -295,7 +295,7 @@ func (suite *ParsedResultTestSuite) checkStruct(pkg intermediate, s structTestCa
// ...make sure the names are the same...
suite.Equal(f.Name, typFields[i].Name)
suite.Equal(f.Optional, typFields[i].Optional)
// and the TypeRef points to somewhere else.
// and the Type points to somewhere else.
suite.True(typFields[i].T.IsUnresolved())
suite.True(typFields[i].T.Ordinal() > 0)
suite.Equal(ref.Ref{}, typFields[i].T.PackageRef())
+5 -5
View File
@@ -2,19 +2,19 @@ package types
import "github.com/attic-labs/noms/d"
func assertType(t TypeRef, v ...Value) {
func assertType(t Type, 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())
d.Chk.True(t.Equals(v.Type()), "Invalid type. Expected: %s, found: %s", t.Describe(), v.Type().Describe())
}
}
}
func assertSetsSameType(s Set, v ...Set) {
if s.elemType().Kind() != ValueKind {
t := s.TypeRef()
t := s.Type()
for _, v := range v {
d.Chk.True(t.Equals(v.TypeRef()))
d.Chk.True(t.Equals(v.Type()))
}
}
}
@@ -25,7 +25,7 @@ func assertMapElemTypes(m Map, v ...Value) {
valueType := elemTypes[0]
if keyType.Kind() != ValueKind || valueType.Kind() != ValueKind {
for i, v := range v {
d.Chk.True(elemTypes[i%2].Equals(v.TypeRef()))
d.Chk.True(elemTypes[i%2].Equals(v.Type()))
}
}
}
+2 -2
View File
@@ -40,10 +40,10 @@ func (bl blobLeaf) ChildValues() []Value {
return nil
}
func (bl blobLeaf) TypeRef() TypeRef {
func (bl blobLeaf) Type() Type {
return typeRefForBlob
}
func (bl blobLeaf) Equals(other Value) bool {
return other != nil && typeRefForBlob.Equals(other.TypeRef()) && bl.Ref() == other.Ref()
return other != nil && typeRefForBlob.Equals(other.Type()) && bl.Ref() == other.Ref()
}
+1 -1
View File
@@ -39,5 +39,5 @@ func TestBlobLeafChunks(t *testing.T) {
func TestBlobLeafTypeRef(t *testing.T) {
assert := assert.New(t)
b := newBlobLeaf([]byte{})
assert.True(b.TypeRef().Equals(MakePrimitiveTypeRef(BlobKind)))
assert.True(b.Type().Equals(MakePrimitiveTypeRef(BlobKind)))
}
+2 -2
View File
@@ -112,9 +112,9 @@ func (cb compoundBlob) Ref() ref.Ref {
}
func (cb compoundBlob) Equals(other Value) bool {
return other != nil && typeRefForBlob.Equals(other.TypeRef()) && cb.Ref() == other.Ref()
return other != nil && typeRefForBlob.Equals(other.Type()) && cb.Ref() == other.Ref()
}
func (cb compoundBlob) TypeRef() TypeRef {
func (cb compoundBlob) Type() Type {
return typeRefForBlob
}
+16 -16
View File
@@ -13,7 +13,7 @@ var __typesPackageInFile_compound_blob_struct_CachedRef ref.Ref
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
p := NewPackage([]TypeRef{
p := NewPackage([]Type{
MakeStructTypeRef("compoundBlobStruct",
[]Field{
Field{"Offsets", MakeCompoundTypeRef(ListKind, MakePrimitiveTypeRef(UInt64Kind)), false},
@@ -62,9 +62,9 @@ func (s compoundBlobStruct) Def() (d compoundBlobStructDef) {
return
}
var __typeRefForcompoundBlobStruct TypeRef
var __typeRefForcompoundBlobStruct Type
func (m compoundBlobStruct) TypeRef() TypeRef {
func (m compoundBlobStruct) Type() Type {
return __typeRefForcompoundBlobStruct
}
@@ -92,7 +92,7 @@ func readerForcompoundBlobStruct(v Value) []Value {
}
func (s compoundBlobStruct) Equals(other Value) bool {
return other != nil && __typeRefForcompoundBlobStruct.Equals(other.TypeRef()) && s.Ref() == other.Ref()
return other != nil && __typeRefForcompoundBlobStruct.Equals(other.Type()) && s.Ref() == other.Ref()
}
func (s compoundBlobStruct) Ref() ref.Ref {
@@ -162,7 +162,7 @@ func (l ListOfUInt64) Def() ListOfUInt64Def {
}
func (l ListOfUInt64) Equals(other Value) bool {
return other != nil && __typeRefForListOfUInt64.Equals(other.TypeRef()) && l.Ref() == other.Ref()
return other != nil && __typeRefForListOfUInt64.Equals(other.Type()) && l.Ref() == other.Ref()
}
func (l ListOfUInt64) Ref() ref.Ref {
@@ -170,7 +170,7 @@ func (l ListOfUInt64) Ref() ref.Ref {
}
func (l ListOfUInt64) Chunks() (chunks []ref.Ref) {
chunks = append(chunks, l.TypeRef().Chunks()...)
chunks = append(chunks, l.Type().Chunks()...)
chunks = append(chunks, l.l.Chunks()...)
return
}
@@ -180,9 +180,9 @@ func (l ListOfUInt64) ChildValues() []Value {
}
// A Noms Value that describes ListOfUInt64.
var __typeRefForListOfUInt64 TypeRef
var __typeRefForListOfUInt64 Type
func (m ListOfUInt64) TypeRef() TypeRef {
func (m ListOfUInt64) Type() Type {
return __typeRefForListOfUInt64
}
@@ -304,7 +304,7 @@ func (l ListOfRefOfBlob) Def() ListOfRefOfBlobDef {
}
func (l ListOfRefOfBlob) Equals(other Value) bool {
return other != nil && __typeRefForListOfRefOfBlob.Equals(other.TypeRef()) && l.Ref() == other.Ref()
return other != nil && __typeRefForListOfRefOfBlob.Equals(other.Type()) && l.Ref() == other.Ref()
}
func (l ListOfRefOfBlob) Ref() ref.Ref {
@@ -312,7 +312,7 @@ func (l ListOfRefOfBlob) Ref() ref.Ref {
}
func (l ListOfRefOfBlob) Chunks() (chunks []ref.Ref) {
chunks = append(chunks, l.TypeRef().Chunks()...)
chunks = append(chunks, l.Type().Chunks()...)
chunks = append(chunks, l.l.Chunks()...)
return
}
@@ -322,9 +322,9 @@ func (l ListOfRefOfBlob) ChildValues() []Value {
}
// A Noms Value that describes ListOfRefOfBlob.
var __typeRefForListOfRefOfBlob TypeRef
var __typeRefForListOfRefOfBlob Type
func (m ListOfRefOfBlob) TypeRef() TypeRef {
func (m ListOfRefOfBlob) Type() Type {
return __typeRefForListOfRefOfBlob
}
@@ -436,11 +436,11 @@ func (r RefOfBlob) Ref() ref.Ref {
}
func (r RefOfBlob) Equals(other Value) bool {
return other != nil && __typeRefForRefOfBlob.Equals(other.TypeRef()) && r.Ref() == other.Ref()
return other != nil && __typeRefForRefOfBlob.Equals(other.Type()) && r.Ref() == other.Ref()
}
func (r RefOfBlob) Chunks() (chunks []ref.Ref) {
chunks = append(chunks, r.TypeRef().Chunks()...)
chunks = append(chunks, r.Type().Chunks()...)
chunks = append(chunks, r.target)
return
}
@@ -450,9 +450,9 @@ func (r RefOfBlob) ChildValues() []Value {
}
// A Noms Value that describes RefOfBlob.
var __typeRefForRefOfBlob TypeRef
var __typeRefForRefOfBlob Type
func (m RefOfBlob) TypeRef() TypeRef {
func (m RefOfBlob) Type() Type {
return __typeRefForRefOfBlob
}
+1 -1
View File
@@ -202,5 +202,5 @@ func TestCompoundBlobTypeRef(t *testing.T) {
assert := assert.New(t)
cb := getTestCompoundBlob("hello", "world")
assert.True(cb.TypeRef().Equals(MakePrimitiveTypeRef(BlobKind)))
assert.True(cb.Type().Equals(MakePrimitiveTypeRef(BlobKind)))
}
+17 -17
View File
@@ -56,7 +56,7 @@ func (r *jsonArrayReader) readRef() ref.Ref {
return ref.Parse(s)
}
func (r *jsonArrayReader) readTypeRefAsTag() TypeRef {
func (r *jsonArrayReader) readTypeRefAsTag() Type {
kind := r.readKind()
switch kind {
case ListKind, SetKind, RefKind:
@@ -82,7 +82,7 @@ func (r *jsonArrayReader) readTypeRefAsTag() TypeRef {
panic("unreachable")
}
func (r *jsonArrayReader) readBlob(t TypeRef) Value {
func (r *jsonArrayReader) readBlob(t Type) Value {
s := r.readString()
decoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(s))
b, err := ioutil.ReadAll(decoder)
@@ -90,7 +90,7 @@ func (r *jsonArrayReader) readBlob(t TypeRef) Value {
return newBlobLeaf(b)
}
func (r *jsonArrayReader) readList(t TypeRef, pkg *Package) Value {
func (r *jsonArrayReader) readList(t Type, pkg *Package) Value {
desc := t.Desc.(CompoundDesc)
data := []Value{}
elemType := desc.ElemTypes[0]
@@ -104,7 +104,7 @@ func (r *jsonArrayReader) readList(t TypeRef, pkg *Package) Value {
return valueFromTypeRef(newListNoCopy(data, t), t)
}
func (r *jsonArrayReader) readSet(t TypeRef, pkg *Package) Value {
func (r *jsonArrayReader) readSet(t Type, pkg *Package) Value {
desc := t.Desc.(CompoundDesc)
data := setData{}
elemType := desc.ElemTypes[0]
@@ -118,7 +118,7 @@ func (r *jsonArrayReader) readSet(t TypeRef, pkg *Package) Value {
return valueFromTypeRef(newSetFromData(data, t), t)
}
func (r *jsonArrayReader) readMap(t TypeRef, pkg *Package) Value {
func (r *jsonArrayReader) readMap(t Type, pkg *Package) Value {
desc := t.Desc.(CompoundDesc)
data := mapData{}
keyType := desc.ElemTypes[0]
@@ -135,14 +135,14 @@ func (r *jsonArrayReader) readMap(t TypeRef, pkg *Package) Value {
return valueFromTypeRef(newMapFromData(data, t), t)
}
func (r *jsonArrayReader) readEnum(t TypeRef, pkg *Package) Value {
func (r *jsonArrayReader) readEnum(t Type, pkg *Package) Value {
t = fixupTypeRef(t, pkg)
return enumFromTypeRef(uint32(r.read().(float64)), t)
}
func (r *jsonArrayReader) readPackage(t TypeRef, pkg *Package) Value {
func (r *jsonArrayReader) readPackage(t Type, pkg *Package) Value {
r2 := newJsonArrayReader(r.readArray(), r.cs)
types := []TypeRef{}
types := []Type{}
for !r2.atEnd() {
types = append(types, r2.readTypeRefAsValue(pkg))
}
@@ -156,7 +156,7 @@ func (r *jsonArrayReader) readPackage(t TypeRef, pkg *Package) Value {
return NewPackage(types, deps)
}
func (r *jsonArrayReader) readRefValue(t TypeRef, pkg *Package) Value {
func (r *jsonArrayReader) readRefValue(t Type, pkg *Package) Value {
ref := r.readRef()
t = fixupTypeRef(t, pkg)
return refFromTypeRef(ref, t)
@@ -167,7 +167,7 @@ func (r *jsonArrayReader) readTopLevelValue() Value {
return r.readValueWithoutTag(t, nil)
}
func (r *jsonArrayReader) readValueWithoutTag(t TypeRef, pkg *Package) Value {
func (r *jsonArrayReader) readValueWithoutTag(t Type, pkg *Package) Value {
switch t.Kind() {
case BlobKind:
return r.readBlob(t)
@@ -222,12 +222,12 @@ func (r *jsonArrayReader) readValueWithoutTag(t TypeRef, pkg *Package) Value {
panic("not reachable")
}
func (r *jsonArrayReader) readTypeRefKindToValue(t TypeRef, pkg *Package) Value {
func (r *jsonArrayReader) readTypeRefKindToValue(t Type, pkg *Package) Value {
d.Chk.IsType(PrimitiveDesc(0), t.Desc)
return r.readTypeRefAsValue(pkg)
}
func (r *jsonArrayReader) readUnresolvedKindToValue(t TypeRef, pkg *Package) Value {
func (r *jsonArrayReader) readUnresolvedKindToValue(t Type, pkg *Package) Value {
// When we have a struct referencing another struct/enum in the same package the package ref is empty. In that case we use the package that is passed into this function.
d.Chk.True(t.IsUnresolved())
pkgRef := t.PackageRef()
@@ -253,7 +253,7 @@ func (r *jsonArrayReader) readUnresolvedKindToValue(t TypeRef, pkg *Package) Val
return r.readStruct(typeDef, t, pkg)
}
func (r *jsonArrayReader) readTypeRefAsValue(pkg *Package) TypeRef {
func (r *jsonArrayReader) readTypeRefAsValue(pkg *Package) Type {
k := r.readKind()
switch k {
case EnumKind:
@@ -266,7 +266,7 @@ func (r *jsonArrayReader) readTypeRefAsValue(pkg *Package) TypeRef {
return MakeEnumTypeRef(name, ids...)
case ListKind, MapKind, RefKind, SetKind:
r2 := newJsonArrayReader(r.readArray(), r.cs)
elemTypes := []TypeRef{}
elemTypes := []Type{}
for !r2.atEnd() {
t := r2.readTypeRefAsValue(pkg)
elemTypes = append(elemTypes, t)
@@ -310,14 +310,14 @@ func (r *jsonArrayReader) readTypeRefAsValue(pkg *Package) TypeRef {
}
// fixupTypeRef goes trough the object graph of tr and updates the PackageRef to pkg if the the old PackageRef was an empty ref.
func fixupTypeRef(tr TypeRef, pkg *Package) TypeRef {
func fixupTypeRef(tr Type, pkg *Package) Type {
switch desc := tr.Desc.(type) {
case EnumDesc, StructDesc:
panic("unreachable")
case PrimitiveDesc:
return tr
case CompoundDesc:
elemTypes := make([]TypeRef, len(desc.ElemTypes))
elemTypes := make([]Type, len(desc.ElemTypes))
for i, elemType := range desc.ElemTypes {
elemTypes[i] = fixupTypeRef(elemType, pkg)
}
@@ -331,7 +331,7 @@ func fixupTypeRef(tr TypeRef, pkg *Package) TypeRef {
panic("unreachable")
}
func (r *jsonArrayReader) readStruct(typeDef, typeRef TypeRef, pkg *Package) Value {
func (r *jsonArrayReader) readStruct(typeDef, typeRef Type, pkg *Package) Value {
// We've read `[StructKind, sha1, name` at this point
values := []Value{}
desc := typeDef.Desc.(StructDesc)
+16 -16
View File
@@ -38,7 +38,7 @@ func parseJson(s string, vs ...interface{}) (v []interface{}) {
func TestReadTypeRefAsTag(t *testing.T) {
cs := chunks.NewMemoryStore()
test := func(expected TypeRef, s string, vs ...interface{}) {
test := func(expected Type, s string, vs ...interface{}) {
a := parseJson(s, vs...)
r := newJsonArrayReader(a, cs)
tr := r.readTypeRefAsTag()
@@ -197,7 +197,7 @@ func TestReadStruct(t *testing.T) {
Field{"s", MakePrimitiveTypeRef(StringKind), false},
Field{"b", MakePrimitiveTypeRef(BoolKind), false},
}, Choices{})
pkg := NewPackage([]TypeRef{tref}, []ref.Ref{})
pkg := NewPackage([]Type{tref}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
a := parseJson(`[%d, "%s", 0, 42, "hi", true]`, UnresolvedKind, pkgRef.String())
@@ -219,7 +219,7 @@ func TestReadStructUnion(t *testing.T) {
Field{"b", MakePrimitiveTypeRef(BoolKind), false},
Field{"s", MakePrimitiveTypeRef(StringKind), false},
})
pkg := NewPackage([]TypeRef{tref}, []ref.Ref{})
pkg := NewPackage([]Type{tref}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
a := parseJson(`[%d, "%s", 0, 42, 1, "hi"]`, UnresolvedKind, pkgRef.String())
@@ -249,7 +249,7 @@ func TestReadStructOptional(t *testing.T) {
Field{"s", MakePrimitiveTypeRef(StringKind), true},
Field{"b", MakePrimitiveTypeRef(BoolKind), true},
}, Choices{})
pkg := NewPackage([]TypeRef{tref}, []ref.Ref{})
pkg := NewPackage([]Type{tref}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
a := parseJson(`[%d, "%s", 0, 42, false, true, false]`, UnresolvedKind, pkgRef.String())
@@ -280,7 +280,7 @@ func TestReadStructWithList(t *testing.T) {
Field{"l", MakeCompoundTypeRef(ListKind, MakePrimitiveTypeRef(Int32Kind)), false},
Field{"s", MakePrimitiveTypeRef(StringKind), false},
}, Choices{})
pkg := NewPackage([]TypeRef{tref}, []ref.Ref{})
pkg := NewPackage([]Type{tref}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
a := parseJson(`[%d, "%s", 0, true, [0, 1, 2], "hi"]`, UnresolvedKind, pkgRef.String())
@@ -310,7 +310,7 @@ func TestReadStructWithValue(t *testing.T) {
Field{"v", MakePrimitiveTypeRef(ValueKind), false},
Field{"s", MakePrimitiveTypeRef(StringKind), false},
}, Choices{})
pkg := NewPackage([]TypeRef{tref}, []ref.Ref{})
pkg := NewPackage([]Type{tref}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
a := parseJson(`[%d, "%s", 0, true, %d, 42, "hi"]`, UnresolvedKind, pkgRef.String(), UInt8Kind)
@@ -337,7 +337,7 @@ func TestReadValueStruct(t *testing.T) {
Field{"s", MakePrimitiveTypeRef(StringKind), false},
Field{"b", MakePrimitiveTypeRef(BoolKind), false},
}, Choices{})
pkg := NewPackage([]TypeRef{tref}, []ref.Ref{})
pkg := NewPackage([]Type{tref}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
a := parseJson(`[%d, %d, "%s", 0, 42, "hi", true]`, ValueKind, UnresolvedKind, pkgRef.String())
@@ -354,7 +354,7 @@ func TestReadEnum(t *testing.T) {
cs := chunks.NewMemoryStore()
typeDef := MakeEnumTypeRef("E", "a", "b", "c")
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
a := parseJson(`[%d, "%s", 0, 1]`, UnresolvedKind, pkgRef.String())
@@ -369,7 +369,7 @@ func TestReadValueEnum(t *testing.T) {
cs := chunks.NewMemoryStore()
typeDef := MakeEnumTypeRef("E", "a", "b", "c")
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
a := parseJson(`[%d, %d, "%s", 0, 1]`, ValueKind, UnresolvedKind, pkgRef.String())
@@ -421,7 +421,7 @@ func TestReadStructWithEnum(t *testing.T) {
Field{"b", MakePrimitiveTypeRef(BoolKind), false},
}, Choices{})
enumTref := MakeEnumTypeRef("E", "a", "b", "c")
pkg := NewPackage([]TypeRef{structTref, enumTref}, []ref.Ref{})
pkg := NewPackage([]Type{structTref, enumTref}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
a := parseJson(`[%d, "%s", 0, 42, 1, true]`, UnresolvedKind, pkgRef.String())
@@ -445,7 +445,7 @@ func TestReadStructWithBlob(t *testing.T) {
tref := MakeStructTypeRef("A5", []Field{
Field{"b", MakePrimitiveTypeRef(BlobKind), false},
}, Choices{})
pkg := NewPackage([]TypeRef{tref}, []ref.Ref{})
pkg := NewPackage([]Type{tref}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
a := parseJson(`[%d, "%s", 0, "AAE="]`, UnresolvedKind, pkgRef.String())
@@ -461,7 +461,7 @@ func TestReadTypeRefValue(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
test := func(expected TypeRef, json string, vs ...interface{}) {
test := func(expected Type, json string, vs ...interface{}) {
a := parseJson(json, vs...)
r := newJsonArrayReader(a, cs)
tr := r.readTopLevelValue()
@@ -503,7 +503,7 @@ func TestReadTypeRefValue(t *testing.T) {
func TestReadPackage(t *testing.T) {
cs := chunks.NewMemoryStore()
pkg := NewPackage([]TypeRef{
pkg := NewPackage([]Type{
MakeStructTypeRef("EnumStruct",
[]Field{
Field{"hand", MakeTypeRef(ref.Ref{}, 1), false},
@@ -515,7 +515,7 @@ func TestReadPackage(t *testing.T) {
// struct Package {
// Dependencies: Set(Ref(Package))
// Types: List(TypeRef)
// Types: List(Type)
// }
a := []interface{}{
@@ -538,7 +538,7 @@ func TestReadPackage2(t *testing.T) {
rr := ref.Parse("sha1-a9993e364706816aba3e25717850c26c9cd0d89d")
setTref := MakeCompoundTypeRef(SetKind, MakePrimitiveTypeRef(UInt32Kind))
pkg := NewPackage([]TypeRef{setTref}, []ref.Ref{rr})
pkg := NewPackage([]Type{setTref}, []ref.Ref{rr})
a := []interface{}{float64(PackageKind), []interface{}{float64(SetKind), []interface{}{float64(UInt32Kind)}}, []interface{}{rr.String()}}
r := newJsonArrayReader(a, cs)
@@ -550,7 +550,7 @@ func TestReadPackageThroughChunkSource(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
pkg := NewPackage([]TypeRef{
pkg := NewPackage([]Type{
MakeStructTypeRef("S", []Field{
Field{"X", MakePrimitiveTypeRef(Int32Kind), false},
}, Choices{}),
+16 -16
View File
@@ -37,7 +37,7 @@ func (w *jsonArrayWriter) writeRef(r ref.Ref) {
w.write(r.String())
}
func (w *jsonArrayWriter) writeTypeRefAsTag(t TypeRef) {
func (w *jsonArrayWriter) writeTypeRefAsTag(t Type) {
k := t.Kind()
w.write(k)
switch k {
@@ -61,12 +61,12 @@ func (w *jsonArrayWriter) writeTypeRefAsTag(t TypeRef) {
}
func (w *jsonArrayWriter) writeTopLevelValue(v Value) {
tr := v.TypeRef()
tr := v.Type()
w.writeTypeRefAsTag(tr)
w.writeValue(v, tr, nil)
}
func (w *jsonArrayWriter) writeValue(v Value, tr TypeRef, pkg *Package) {
func (w *jsonArrayWriter) writeValue(v Value, tr Type, pkg *Package) {
switch tr.Kind() {
case BlobKind:
w.writeBlob(v.(Blob))
@@ -124,14 +124,14 @@ func (w *jsonArrayWriter) writeValue(v Value, tr TypeRef, pkg *Package) {
}
w.writeUnresolvedKindValue(v, tr, pkg)
case ValueKind:
w.writeTypeRefAsTag(v.TypeRef())
w.writeValue(v, v.TypeRef(), pkg)
w.writeTypeRefAsTag(v.Type())
w.writeValue(v, v.Type(), pkg)
default:
d.Chk.Fail("Unknown NomsKind")
}
}
func (w *jsonArrayWriter) writeTypeRefAsValue(v TypeRef) {
func (w *jsonArrayWriter) writeTypeRefAsValue(v Type) {
k := v.Kind()
w.write(k)
switch k {
@@ -167,7 +167,7 @@ func (w *jsonArrayWriter) writeTypeRefAsValue(v TypeRef) {
case UnresolvedKind:
pkgRef := v.PackageRef()
w.writeRef(pkgRef)
// Don't use Ordinal() here since we might need to serialize a TypeRef that hasn't gotten a valid ordinal yet.
// Don't use Ordinal() here since we might need to serialize a Type that hasn't gotten a valid ordinal yet.
ordinal := v.Desc.(UnresolvedDesc).ordinal
w.write(ordinal)
if ordinal == -1 {
@@ -181,23 +181,23 @@ func (w *jsonArrayWriter) writeTypeRefAsValue(v TypeRef) {
}
default:
d.Chk.True(IsPrimitiveKind(k), v.Describe())
d.Chk.True(IsPrimitiveKind(k), "Kind: %v Desc: %s\n", v.Kind(), v.Describe())
}
}
// writeTypeRefKindValue writes either a struct, enum or a TypeRef value
func (w *jsonArrayWriter) writeTypeRefKindValue(v Value, tr TypeRef, pkg *Package) {
d.Chk.IsType(TypeRef{}, v)
w.writeTypeRefAsValue(v.(TypeRef))
// writeTypeRefKindValue writes either a struct, enum or a Type value
func (w *jsonArrayWriter) writeTypeRefKindValue(v Value, tr Type, pkg *Package) {
d.Chk.IsType(Type{}, v)
w.writeTypeRefAsValue(v.(Type))
}
// writeUnresolvedKindValue writes either a struct or an enum
func (w *jsonArrayWriter) writeUnresolvedKindValue(v Value, tr TypeRef, pkg *Package) {
func (w *jsonArrayWriter) writeUnresolvedKindValue(v Value, tr Type, pkg *Package) {
d.Chk.NotNil(pkg)
typeDef := pkg.types[tr.Ordinal()]
switch typeDef.Kind() {
default:
d.Chk.Fail("An Unresolved TypeRef can only reference a StructKind or Enum Kind.", "Actually referenced: %+v", typeDef)
d.Chk.Fail("An Unresolved Type can only reference a StructKind or Enum Kind.", "Actually referenced: %+v", typeDef)
case EnumKind:
w.writeEnum(v, tr, pkg)
case StructKind:
@@ -215,7 +215,7 @@ func (w *jsonArrayWriter) writeBlob(b Blob) {
w.write(buf.String())
}
func (w *jsonArrayWriter) writeStruct(v Value, typeRef, typeDef TypeRef, pkg *Package) {
func (w *jsonArrayWriter) writeStruct(v Value, typeRef, typeDef Type, pkg *Package) {
typeRef = fixupTypeRef(typeRef, pkg)
i := 0
@@ -245,7 +245,7 @@ func (w *jsonArrayWriter) writeStruct(v Value, typeRef, typeDef TypeRef, pkg *Pa
}
}
func (w *jsonArrayWriter) writeEnum(v Value, t TypeRef, pkg *Package) {
func (w *jsonArrayWriter) writeEnum(v Value, t Type, pkg *Package) {
t = fixupTypeRef(t, pkg)
i := enumPrimitiveValueFromTypeRef(v, t)
w.write(i)
+17 -17
View File
@@ -136,7 +136,7 @@ func TestWriteEmptyStruct(t *testing.T) {
cs := chunks.NewMemoryStore()
typeDef := MakeStructTypeRef("S", []Field{}, Choices{})
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
typeRef := MakeTypeRef(pkgRef, 0)
v := NewStruct(typeRef, typeDef, nil)
@@ -154,7 +154,7 @@ func TestWriteStruct(t *testing.T) {
Field{"x", MakePrimitiveTypeRef(Int8Kind), false},
Field{"b", MakePrimitiveTypeRef(BoolKind), false},
}, Choices{})
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
typeRef := MakeTypeRef(pkgRef, 0)
v := NewStruct(typeRef, typeDef, structData{"x": Int8(42), "b": Bool(true)})
@@ -172,7 +172,7 @@ func TestWriteStructOptionalField(t *testing.T) {
Field{"x", MakePrimitiveTypeRef(Int8Kind), true},
Field{"b", MakePrimitiveTypeRef(BoolKind), false},
}, Choices{})
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
typeRef := MakeTypeRef(pkgRef, 0)
v := NewStruct(typeRef, typeDef, structData{"x": Int8(42), "b": Bool(true)})
@@ -198,7 +198,7 @@ func TestWriteStructWithUnion(t *testing.T) {
Field{"b", MakePrimitiveTypeRef(BoolKind), false},
Field{"s", MakePrimitiveTypeRef(StringKind), false},
})
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
typeRef := MakeTypeRef(pkgRef, 0)
v := NewStruct(typeRef, typeDef, structData{"x": Int8(42), "s": NewString("hi")})
@@ -221,7 +221,7 @@ func TestWriteStructWithList(t *testing.T) {
typeDef := MakeStructTypeRef("S", []Field{
Field{"l", MakeCompoundTypeRef(ListKind, MakePrimitiveTypeRef(StringKind)), false},
}, Choices{})
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
typeRef := MakeTypeRef(pkgRef, 0)
@@ -246,7 +246,7 @@ func TestWriteStructWithStruct(t *testing.T) {
sTypeDef := MakeStructTypeRef("S", []Field{
Field{"s", MakeTypeRef(ref.Ref{}, 0), false},
}, Choices{})
pkg := NewPackage([]TypeRef{s2TypeDef, sTypeDef}, []ref.Ref{})
pkg := NewPackage([]Type{s2TypeDef, sTypeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
s2TypeRef := MakeTypeRef(pkgRef, 0)
sTypeRef := MakeTypeRef(pkgRef, 1)
@@ -264,7 +264,7 @@ func TestWriteStructWithBlob(t *testing.T) {
typeDef := MakeStructTypeRef("S", []Field{
Field{"b", MakePrimitiveTypeRef(BlobKind), false},
}, Choices{})
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
typeRef := MakeTypeRef(pkgRef, 0)
b, _ := NewMemoryBlob(bytes.NewBuffer([]byte{0x00, 0x01}))
@@ -279,7 +279,7 @@ func TestWriteEnum(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
pkg := NewPackage([]TypeRef{
pkg := NewPackage([]Type{
MakeEnumTypeRef("E", "a", "b", "c")}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
tref := MakeTypeRef(pkgRef, 0)
@@ -293,7 +293,7 @@ func TestWriteListOfEnum(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
pkg := NewPackage([]TypeRef{
pkg := NewPackage([]Type{
MakeEnumTypeRef("E", "a", "b", "c")}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
et := MakeTypeRef(pkgRef, 0)
@@ -356,7 +356,7 @@ func TestWriteListOfValueWithStruct(t *testing.T) {
typeDef := MakeStructTypeRef("S", []Field{
Field{"x", MakePrimitiveTypeRef(Int32Kind), false},
}, Choices{})
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
listTypeRef := MakeCompoundTypeRef(ListKind, MakePrimitiveTypeRef(ValueKind))
structTypeRef := MakeTypeRef(pkgRef, 0)
@@ -372,7 +372,7 @@ func TestWriteListOfValueWithTypeRefs(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
pkg := NewPackage([]TypeRef{
pkg := NewPackage([]Type{
MakeStructTypeRef("S", []Field{
Field{"x", MakePrimitiveTypeRef(Int32Kind), false},
}, Choices{})}, []ref.Ref{})
@@ -399,10 +399,10 @@ func TestWriteListOfValueWithTypeRefs(t *testing.T) {
type testRef struct {
Value
t TypeRef
t Type
}
func (r testRef) TypeRef() TypeRef {
func (r testRef) Type() Type {
return r.t
}
@@ -427,7 +427,7 @@ func TestWriteTypeRefValue(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
test := func(expected []interface{}, v TypeRef) {
test := func(expected []interface{}, v Type) {
w := newJsonArrayWriter(cs)
w.writeTopLevelValue(v)
assert.EqualValues(expected, w.toArray())
@@ -482,7 +482,7 @@ func TestWriteListOfTypeRefs(t *testing.T) {
func TestWritePackage(t *testing.T) {
cs := chunks.NewMemoryStore()
pkg := NewPackage([]TypeRef{
pkg := NewPackage([]Type{
MakeStructTypeRef("EnumStruct",
[]Field{
Field{"hand", MakeTypeRef(ref.Ref{}, 1), false},
@@ -497,7 +497,7 @@ func TestWritePackage(t *testing.T) {
// struct Package {
// Dependencies: Set(Ref(Package))
// Types: List(TypeRef)
// Types: List(Type)
// }
exp := []interface{}{
@@ -520,7 +520,7 @@ func TestWritePackage2(t *testing.T) {
setTref := MakeCompoundTypeRef(SetKind, MakePrimitiveTypeRef(UInt32Kind))
r := ref.Parse("sha1-0123456789abcdef0123456789abcdef01234567")
v := Package{[]TypeRef{setTref}, []ref.Ref{r}, &ref.Ref{}}
v := Package{[]Type{setTref}, []ref.Ref{r}, &ref.Ref{}}
w := newJsonArrayWriter(cs)
w.writeTopLevelValue(v)
+4 -4
View File
@@ -4,15 +4,15 @@ import "github.com/attic-labs/noms/ref"
type Enum struct {
v uint32
t TypeRef
t Type
}
func newEnum(v uint32, t TypeRef) Enum {
func newEnum(v uint32, t Type) Enum {
return Enum{v, t}
}
func (e Enum) Equals(other Value) bool {
return other != nil && e.t.Equals(other.TypeRef()) && e.Ref() == other.Ref()
return other != nil && e.t.Equals(other.Type()) && e.Ref() == other.Ref()
}
func (e Enum) Ref() ref.Ref {
@@ -28,6 +28,6 @@ func (e Enum) ChildValues() []Value {
return nil
}
func (e Enum) TypeRef() TypeRef {
func (e Enum) Type() Type {
return e.t
}
+1 -1
View File
@@ -14,7 +14,7 @@ func TestGenericEnumWriteRead(t *testing.T) {
typeDefA := MakeEnumTypeRef("EA", "aA", "bA")
typeDefB := MakeEnumTypeRef("EB", "aB", "bB")
pkg := NewPackage([]TypeRef{typeDefA, typeDefB}, []ref.Ref{})
pkg := NewPackage([]Type{typeDefA, typeDefB}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
typeRefA := MakeTypeRef(pkgRef, 0)
typeRefB := MakeTypeRef(pkgRef, 1)
+1 -1
View File
@@ -22,7 +22,7 @@ func (v {{.NomsType}}) ToPrimitive() interface{} {
var typeRefFor{{.NomsType}} = MakePrimitiveTypeRef({{.NomsType}}Kind)
func (v {{.NomsType}}) TypeRef() TypeRef {
func (v {{.NomsType}}) Type() Type {
return typeRefFor{{.NomsType}}
}
+4 -4
View File
@@ -10,7 +10,7 @@ import (
type List struct {
values []Value
t TypeRef
t Type
ref *ref.Ref
}
@@ -23,7 +23,7 @@ func NewList(v ...Value) List {
return newListNoCopy(values, listTypeRef)
}
func newListNoCopy(values []Value, t TypeRef) List {
func newListNoCopy(values []Value, t Type) List {
d.Chk.Equal(ListKind, t.Kind())
return List{values, t, &ref.Ref{}}
}
@@ -199,10 +199,10 @@ func (l List) ChildValues() []Value {
return append([]Value{}, l.values...)
}
func (l List) TypeRef() TypeRef {
func (l List) Type() Type {
return l.t
}
func (l List) elemType() TypeRef {
func (l List) elemType() Type {
return l.t.Desc.(CompoundDesc).ElemTypes[0]
}
+8 -8
View File
@@ -336,25 +336,25 @@ func TestListIterAllP(t *testing.T) {
func TestListTypeRef(t *testing.T) {
assert := assert.New(t)
l := NewList(Int32(0))
assert.True(l.TypeRef().Equals(MakeCompoundTypeRef(ListKind, MakePrimitiveTypeRef(ValueKind))))
assert.True(l.Type().Equals(MakeCompoundTypeRef(ListKind, MakePrimitiveTypeRef(ValueKind))))
tr := MakeCompoundTypeRef(ListKind, MakePrimitiveTypeRef(UInt8Kind))
l2 := newListNoCopy([]Value{UInt8(0), UInt8(1)}, tr)
assert.Equal(tr, l2.TypeRef())
assert.Equal(tr, l2.Type())
l3 := l2.Slice(0, 1)
assert.True(tr.Equals(l3.TypeRef()))
assert.True(tr.Equals(l3.Type()))
l3 = l2.Remove(0, 1)
assert.True(tr.Equals(l3.TypeRef()))
assert.True(tr.Equals(l3.Type()))
l3 = l2.RemoveAt(0)
assert.True(tr.Equals(l3.TypeRef()))
assert.True(tr.Equals(l3.Type()))
l3 = l2.Set(0, UInt8(11))
assert.True(tr.Equals(l3.TypeRef()))
assert.True(tr.Equals(l3.Type()))
l3 = l2.Append(UInt8(2))
assert.True(tr.Equals(l3.TypeRef()))
assert.True(tr.Equals(l3.Type()))
l3 = l2.Insert(0, UInt8(3))
assert.True(tr.Equals(l3.TypeRef()))
assert.True(tr.Equals(l3.Type()))
assert.Panics(func() { l2.Set(0, NewString("")) })
assert.Panics(func() { l2.Append(NewString("")) })
+5 -5
View File
@@ -11,7 +11,7 @@ import (
type Map struct {
data mapData // sorted by entry.key.Ref()
t TypeRef
t Type
ref *ref.Ref
}
@@ -144,7 +144,7 @@ func (m Map) Ref() ref.Ref {
}
func (m Map) Equals(other Value) bool {
return other != nil && m.t.Equals(other.TypeRef()) && m.Ref() == other.Ref()
return other != nil && m.t.Equals(other.Type()) && m.Ref() == other.Ref()
}
func (m Map) Chunks() (chunks []ref.Ref) {
@@ -166,11 +166,11 @@ func (m Map) ChildValues() []Value {
var mapTypeRef = MakeCompoundTypeRef(MapKind, MakePrimitiveTypeRef(ValueKind), MakePrimitiveTypeRef(ValueKind))
func (m Map) TypeRef() TypeRef {
func (m Map) Type() Type {
return m.t
}
func (m Map) elemTypes() []TypeRef {
func (m Map) elemTypes() []Type {
return m.t.Desc.(CompoundDesc).ElemTypes
}
@@ -179,7 +179,7 @@ type mapEntry struct {
value Value
}
func newMapFromData(data mapData, t TypeRef) Map {
func newMapFromData(data mapData, t Type) Map {
return Map{data, t, &ref.Ref{}}
}
+6 -6
View File
@@ -261,25 +261,25 @@ func TestMapEmpty(t *testing.T) {
func TestMapTypeRef(t *testing.T) {
assert := assert.New(t)
m := NewMap()
assert.True(m.TypeRef().Equals(MakeCompoundTypeRef(MapKind, MakePrimitiveTypeRef(ValueKind), MakePrimitiveTypeRef(ValueKind))))
assert.True(m.Type().Equals(MakeCompoundTypeRef(MapKind, MakePrimitiveTypeRef(ValueKind), MakePrimitiveTypeRef(ValueKind))))
tr := MakeCompoundTypeRef(MapKind, MakePrimitiveTypeRef(StringKind), MakePrimitiveTypeRef(UInt64Kind))
m = newMapFromData(mapData{}, tr)
assert.Equal(tr, m.TypeRef())
assert.Equal(tr, m.Type())
m2 := m.Remove(NewString("B"))
assert.True(tr.Equals(m2.TypeRef()))
assert.True(tr.Equals(m2.Type()))
m = m.Filter(func(k, v Value) bool {
return true
})
assert.True(tr.Equals(m2.TypeRef()))
assert.True(tr.Equals(m2.Type()))
m2 = m.Set(NewString("A"), UInt64(1))
assert.True(tr.Equals(m2.TypeRef()))
assert.True(tr.Equals(m2.Type()))
m2 = m.SetM(NewString("B"), UInt64(2), NewString("C"), UInt64(2))
assert.True(tr.Equals(m2.TypeRef()))
assert.True(tr.Equals(m2.Type()))
assert.Panics(func() { m.Set(NewString("A"), UInt8(1)) })
assert.Panics(func() { m.Set(Bool(true), UInt64(1)) })
+1 -1
View File
@@ -30,7 +30,7 @@ const (
PackageKind
)
// IsPrimitiveKind returns true if k represents a Noms primitive type, which excludes collections (List, Map, Set), Refs, Enums, Structs and Unresolved type references.
// IsPrimitiveKind returns true if k represents a Noms primitive type, which excludes collections (List, Map, Set), Refs, Enums, Structs, Symbolic and Unresolved type references.
func IsPrimitiveKind(k NomsKind) bool {
switch k {
case BoolKind, Int8Kind, Int16Kind, Int32Kind, Int64Kind, Float32Kind, Float64Kind, UInt8Kind, UInt16Kind, UInt32Kind, UInt64Kind, StringKind, BlobKind, ValueKind, TypeRefKind, PackageKind:
+5 -5
View File
@@ -3,17 +3,17 @@ package types
import "github.com/attic-labs/noms/ref"
type Package struct {
types []TypeRef
types []Type
dependencies []ref.Ref
ref *ref.Ref
}
func NewPackage(types []TypeRef, deps []ref.Ref) Package {
func NewPackage(types []Type, deps []ref.Ref) Package {
return Package{types, deps, &ref.Ref{}}
}
func (p Package) Equals(other Value) bool {
return other != nil && typeRefForPackage.Equals(other.TypeRef()) && p.Ref() == other.Ref()
return other != nil && typeRefForPackage.Equals(other.Type()) && p.Ref() == other.Ref()
}
func (p Package) Ref() ref.Ref {
@@ -42,7 +42,7 @@ func (p Package) ChildValues() (res []Value) {
var typeRefForPackage = MakePrimitiveTypeRef(PackageKind)
func (p Package) TypeRef() TypeRef {
func (p Package) Type() Type {
return typeRefForPackage
}
@@ -60,7 +60,7 @@ func (p Package) Dependencies() []ref.Ref {
return p.dependencies
}
func (p Package) Types() []TypeRef {
func (p Package) Types() []Type {
// TODO: Change API to prevent mutations.
return p.types
}
+11 -11
View File
@@ -57,65 +57,65 @@ func readPackage(r ref.Ref, cs chunks.ChunkSource) *Package {
return &p
}
func RegisterStruct(t TypeRef, bf structBuilderFunc, rf structReaderFunc) {
func RegisterStruct(t Type, bf structBuilderFunc, rf structReaderFunc) {
structFuncMap[t.Ref()] = structFuncs{bf, rf}
}
func structBuilderForTypeRef(values []Value, typeRef, typeDef TypeRef) Value {
func structBuilderForTypeRef(values []Value, typeRef, typeDef Type) Value {
if s, ok := structFuncMap[typeRef.Ref()]; ok {
return s.builder(values)
}
return structBuilder(values, typeRef, typeDef)
}
func structReaderForTypeRef(v Value, typeRef, typeDef TypeRef) []Value {
func structReaderForTypeRef(v Value, typeRef, typeDef Type) []Value {
if s, ok := structFuncMap[typeRef.Ref()]; ok {
return s.reader(v)
}
return structReader(v.(Struct), typeRef, typeDef)
}
func RegisterEnum(t TypeRef, bf enumBuilderFunc, rf enumReaderFunc) {
func RegisterEnum(t Type, bf enumBuilderFunc, rf enumReaderFunc) {
enumFuncMap[t.Ref()] = enumFuncs{bf, rf}
}
func enumFromTypeRef(v uint32, t TypeRef) Value {
func enumFromTypeRef(v uint32, t Type) Value {
if s, ok := enumFuncMap[t.Ref()]; ok {
return s.builder(v)
}
return newEnum(v, t)
}
func enumPrimitiveValueFromTypeRef(v Value, t TypeRef) uint32 {
func enumPrimitiveValueFromTypeRef(v Value, t Type) uint32 {
if s, ok := enumFuncMap[t.Ref()]; ok {
return s.reader(v)
}
return v.(Enum).v
}
func RegisterValue(t TypeRef, bf valueBuilderFunc, rf valueReaderFunc) {
func RegisterValue(t Type, bf valueBuilderFunc, rf valueReaderFunc) {
valueFuncMap[t.Ref()] = valueFuncs{bf, rf}
}
func valueFromTypeRef(v Value, t TypeRef) Value {
func valueFromTypeRef(v Value, t Type) Value {
if s, ok := valueFuncMap[t.Ref()]; ok {
return s.builder(v)
}
return v
}
func internalValueFromTypeRef(v Value, t TypeRef) Value {
func internalValueFromTypeRef(v Value, t Type) Value {
if s, ok := valueFuncMap[t.Ref()]; ok {
return s.reader(v)
}
return v
}
func RegisterRef(t TypeRef, bf refBuilderFunc) {
func RegisterRef(t Type, bf refBuilderFunc) {
refFuncMap[t.Ref()] = bf
}
func refFromTypeRef(target ref.Ref, t TypeRef) Value {
func refFromTypeRef(target ref.Ref, t Type) Value {
if f, ok := refFuncMap[t.Ref()]; ok {
return f(target)
}
+9 -9
View File
@@ -41,7 +41,7 @@ func (s SetOfRefOfPackage) Def() SetOfRefOfPackageDef {
}
func (s SetOfRefOfPackage) Equals(other Value) bool {
return other != nil && __typeRefForSetOfRefOfPackage.Equals(other.TypeRef()) && s.Ref() == other.Ref()
return other != nil && __typeRefForSetOfRefOfPackage.Equals(other.Type()) && s.Ref() == other.Ref()
}
func (s SetOfRefOfPackage) Ref() ref.Ref {
@@ -49,21 +49,21 @@ func (s SetOfRefOfPackage) Ref() ref.Ref {
}
func (s SetOfRefOfPackage) Chunks() (chunks []ref.Ref) {
chunks = append(chunks, s.TypeRef().Chunks()...)
chunks = append(chunks, s.Type().Chunks()...)
chunks = append(chunks, s.s.Chunks()...)
return
}
func (s SetOfRefOfPackage) ChildValues() (ret []Value) {
ret = append(ret, s.TypeRef())
ret = append(ret, s.Type())
ret = append(ret, s.s.ChildValues()...)
return
}
// A Noms Value that describes SetOfRefOfPackage.
var __typeRefForSetOfRefOfPackage TypeRef
var __typeRefForSetOfRefOfPackage Type
func (m SetOfRefOfPackage) TypeRef() TypeRef {
func (m SetOfRefOfPackage) Type() Type {
return __typeRefForSetOfRefOfPackage
}
@@ -176,11 +176,11 @@ func (r RefOfPackage) Ref() ref.Ref {
}
func (r RefOfPackage) Equals(other Value) bool {
return other != nil && __typeRefForRefOfPackage.Equals(other.TypeRef()) && r.Ref() == other.Ref()
return other != nil && __typeRefForRefOfPackage.Equals(other.Type()) && r.Ref() == other.Ref()
}
func (r RefOfPackage) Chunks() (chunks []ref.Ref) {
chunks = append(chunks, r.TypeRef().Chunks()...)
chunks = append(chunks, r.Type().Chunks()...)
chunks = append(chunks, r.target)
return
}
@@ -190,9 +190,9 @@ func (r RefOfPackage) ChildValues() []Value {
}
// A Noms Value that describes RefOfPackage.
var __typeRefForRefOfPackage TypeRef
var __typeRefForRefOfPackage Type
func (m RefOfPackage) TypeRef() TypeRef {
func (m RefOfPackage) Type() Type {
return __typeRefForRefOfPackage
}
+2 -2
View File
@@ -10,7 +10,7 @@ import (
func TestType(t *testing.T) {
assert := assert.New(t)
st := NewPackage([]TypeRef{}, []ref.Ref{})
typ := st.TypeRef()
st := NewPackage([]Type{}, []ref.Ref{})
typ := st.Type()
assert.Equal(PackageKind, typ.Kind())
}
+11 -11
View File
@@ -31,7 +31,7 @@ func (v Bool) ToPrimitive() interface{} {
var typeRefForBool = MakePrimitiveTypeRef(BoolKind)
func (v Bool) TypeRef() TypeRef {
func (v Bool) Type() Type {
return typeRefForBool
}
@@ -59,7 +59,7 @@ func (v Int8) ToPrimitive() interface{} {
var typeRefForInt8 = MakePrimitiveTypeRef(Int8Kind)
func (v Int8) TypeRef() TypeRef {
func (v Int8) Type() Type {
return typeRefForInt8
}
@@ -87,7 +87,7 @@ func (v Int16) ToPrimitive() interface{} {
var typeRefForInt16 = MakePrimitiveTypeRef(Int16Kind)
func (v Int16) TypeRef() TypeRef {
func (v Int16) Type() Type {
return typeRefForInt16
}
@@ -115,7 +115,7 @@ func (v Int32) ToPrimitive() interface{} {
var typeRefForInt32 = MakePrimitiveTypeRef(Int32Kind)
func (v Int32) TypeRef() TypeRef {
func (v Int32) Type() Type {
return typeRefForInt32
}
@@ -143,7 +143,7 @@ func (v Int64) ToPrimitive() interface{} {
var typeRefForInt64 = MakePrimitiveTypeRef(Int64Kind)
func (v Int64) TypeRef() TypeRef {
func (v Int64) Type() Type {
return typeRefForInt64
}
@@ -171,7 +171,7 @@ func (v UInt8) ToPrimitive() interface{} {
var typeRefForUInt8 = MakePrimitiveTypeRef(UInt8Kind)
func (v UInt8) TypeRef() TypeRef {
func (v UInt8) Type() Type {
return typeRefForUInt8
}
@@ -199,7 +199,7 @@ func (v UInt16) ToPrimitive() interface{} {
var typeRefForUInt16 = MakePrimitiveTypeRef(UInt16Kind)
func (v UInt16) TypeRef() TypeRef {
func (v UInt16) Type() Type {
return typeRefForUInt16
}
@@ -227,7 +227,7 @@ func (v UInt32) ToPrimitive() interface{} {
var typeRefForUInt32 = MakePrimitiveTypeRef(UInt32Kind)
func (v UInt32) TypeRef() TypeRef {
func (v UInt32) Type() Type {
return typeRefForUInt32
}
@@ -255,7 +255,7 @@ func (v UInt64) ToPrimitive() interface{} {
var typeRefForUInt64 = MakePrimitiveTypeRef(UInt64Kind)
func (v UInt64) TypeRef() TypeRef {
func (v UInt64) Type() Type {
return typeRefForUInt64
}
@@ -283,7 +283,7 @@ func (v Float32) ToPrimitive() interface{} {
var typeRefForFloat32 = MakePrimitiveTypeRef(Float32Kind)
func (v Float32) TypeRef() TypeRef {
func (v Float32) Type() Type {
return typeRefForFloat32
}
@@ -311,7 +311,7 @@ func (v Float64) ToPrimitive() interface{} {
var typeRefForFloat64 = MakePrimitiveTypeRef(Float64Kind)
func (v Float64) TypeRef() TypeRef {
func (v Float64) Type() Type {
return typeRefForFloat64
}
+1 -1
View File
@@ -49,6 +49,6 @@ func TestPrimitivesTypeRef(t *testing.T) {
}
for _, d := range data {
assert.True(t, d.v.TypeRef().Equals(MakePrimitiveTypeRef(d.k)))
assert.True(t, d.v.Type().Equals(MakePrimitiveTypeRef(d.k)))
}
}
+4 -4
View File
@@ -7,7 +7,7 @@ import (
type Ref struct {
target ref.Ref
t TypeRef
t Type
ref *ref.Ref
}
@@ -19,12 +19,12 @@ func NewRef(target ref.Ref) Ref {
return newRef(target, refTypeRef)
}
func newRef(target ref.Ref, t TypeRef) Ref {
func newRef(target ref.Ref, t Type) Ref {
return Ref{target, t, &ref.Ref{}}
}
func (r Ref) Equals(other Value) bool {
return other != nil && r.t.Equals(other.TypeRef()) && r.Ref() == other.Ref()
return other != nil && r.t.Equals(other.Type()) && r.Ref() == other.Ref()
}
func (r Ref) Ref() ref.Ref {
@@ -45,7 +45,7 @@ func (r Ref) TargetRef() ref.Ref {
var refTypeRef = MakeCompoundTypeRef(RefKind, MakePrimitiveTypeRef(ValueKind))
func (r Ref) TypeRef() TypeRef {
func (r Ref) Type() Type {
return r.t
}
+4 -4
View File
@@ -45,19 +45,19 @@ func TestRefTypeRef(t *testing.T) {
l := NewList()
r := NewRef(l.Ref())
assert.True(r.TypeRef().Equals(tr))
assert.True(r.Type().Equals(tr))
cs := chunks.NewMemoryStore()
m := NewMap()
r2 := r.SetTargetValue(m, cs)
assert.True(r2.TypeRef().Equals(tr))
assert.True(r2.Type().Equals(tr))
b := Bool(true)
r2 = r.SetTargetValue(b, cs)
r2.t = MakeCompoundTypeRef(RefKind, b.TypeRef())
r2.t = MakeCompoundTypeRef(RefKind, b.Type())
r3 := r2.SetTargetValue(Bool(false), cs)
assert.True(r2.TypeRef().Equals(r3.TypeRef()))
assert.True(r2.Type().Equals(r3.Type()))
assert.Panics(func() { r2.SetTargetValue(Int16(1), cs) })
}
+5 -5
View File
@@ -12,7 +12,7 @@ type setData []Value
type Set struct {
data setData // sorted by Ref()
t TypeRef
t Type
ref *ref.Ref
}
@@ -141,7 +141,7 @@ func (s Set) Ref() ref.Ref {
}
func (s Set) Equals(other Value) bool {
return other != nil && s.t.Equals(other.TypeRef()) && s.Ref() == other.Ref()
return other != nil && s.t.Equals(other.Type()) && s.Ref() == other.Ref()
}
func (s Set) Chunks() (chunks []ref.Ref) {
@@ -155,15 +155,15 @@ func (s Set) ChildValues() []Value {
return append([]Value{}, s.data...)
}
func (s Set) TypeRef() TypeRef {
func (s Set) Type() Type {
return s.t
}
func (s Set) elemType() TypeRef {
func (s Set) elemType() Type {
return s.t.Desc.(CompoundDesc).ElemTypes[0]
}
func newSetFromData(m setData, t TypeRef) Set {
func newSetFromData(m setData, t Type) Set {
return Set{m, t, &ref.Ref{}}
}
+7 -7
View File
@@ -229,31 +229,31 @@ func TestSetFilter(t *testing.T) {
func TestSetTypeRef(t *testing.T) {
assert := assert.New(t)
s := NewSet()
assert.True(s.TypeRef().Equals(MakeCompoundTypeRef(SetKind, MakePrimitiveTypeRef(ValueKind))))
assert.True(s.Type().Equals(MakeCompoundTypeRef(SetKind, MakePrimitiveTypeRef(ValueKind))))
tr := MakeCompoundTypeRef(SetKind, MakePrimitiveTypeRef(UInt64Kind))
s = newSetFromData(setData{}, tr)
assert.Equal(tr, s.TypeRef())
assert.Equal(tr, s.Type())
s2 := s.Remove(UInt64(1))
assert.True(tr.Equals(s2.TypeRef()))
assert.True(tr.Equals(s2.Type()))
s2 = s.Subtract(s)
assert.True(tr.Equals(s2.TypeRef()))
assert.True(tr.Equals(s2.Type()))
s2 = s.Filter(func(v Value) bool {
return true
})
assert.True(tr.Equals(s2.TypeRef()))
assert.True(tr.Equals(s2.Type()))
s2 = s.Insert(UInt64(0), UInt64(1))
assert.True(tr.Equals(s2.TypeRef()))
assert.True(tr.Equals(s2.Type()))
s3 := NewSet(UInt64(2))
s3.t = s2.t
s2 = s.Union(s3)
assert.True(tr.Equals(s2.TypeRef()))
assert.True(tr.Equals(s2.Type()))
assert.Panics(func() { s.Insert(Bool(true)) })
assert.Panics(func() { s.Insert(UInt64(3), Bool(true)) })
+1 -1
View File
@@ -36,6 +36,6 @@ func (fs String) ChildValues() []Value {
var typeRefForString = MakePrimitiveTypeRef(StringKind)
func (fs String) TypeRef() TypeRef {
func (fs String) Type() Type {
return typeRefForString
}
+1 -1
View File
@@ -29,5 +29,5 @@ func TestStringString(t *testing.T) {
}
func TestStringTypeRef(t *testing.T) {
assert.True(t, NewString("hi").TypeRef().Equals(MakePrimitiveTypeRef(StringKind)))
assert.True(t, NewString("hi").Type().Equals(MakePrimitiveTypeRef(StringKind)))
}
+8 -8
View File
@@ -9,14 +9,14 @@ type structData map[string]Value
type Struct struct {
data structData
t TypeRef
typeDef TypeRef
t Type
typeDef Type
unionIndex uint32
unionValue Value
ref *ref.Ref
}
func newStructFromData(data structData, unionIndex uint32, unionValue Value, typeRef, typeDef TypeRef) Struct {
func newStructFromData(data structData, unionIndex uint32, unionValue Value, typeRef, typeDef Type) Struct {
d.Chk.Equal(typeRef.Kind(), UnresolvedKind)
d.Chk.True(typeRef.HasPackageRef())
d.Chk.True(typeRef.HasOrdinal())
@@ -24,7 +24,7 @@ func newStructFromData(data structData, unionIndex uint32, unionValue Value, typ
return Struct{data, typeRef, typeDef, unionIndex, unionValue, &ref.Ref{}}
}
func NewStruct(typeRef, typeDef TypeRef, data structData) Struct {
func NewStruct(typeRef, typeDef Type, data structData) Struct {
newData := make(structData)
unionIndex := uint32(0)
var unionValue Value
@@ -49,7 +49,7 @@ func NewStruct(typeRef, typeDef TypeRef, data structData) Struct {
}
func (s Struct) Equals(other Value) bool {
return other != nil && s.t.Equals(other.TypeRef()) && s.Ref() == other.Ref()
return other != nil && s.t.Equals(other.Type()) && s.Ref() == other.Ref()
}
func (s Struct) Ref() ref.Ref {
@@ -88,7 +88,7 @@ func (s Struct) ChildValues() (res []Value) {
return
}
func (s Struct) TypeRef() TypeRef {
func (s Struct) Type() Type {
return s.t
}
@@ -170,7 +170,7 @@ func (s Struct) findField(n string) (Field, int32, bool) {
return Field{}, -1, false
}
func structBuilder(values []Value, typeRef, typeDef TypeRef) Value {
func structBuilder(values []Value, typeRef, typeDef Type) Value {
i := 0
desc := typeDef.Desc.(StructDesc)
data := structData{}
@@ -200,7 +200,7 @@ func structBuilder(values []Value, typeRef, typeDef TypeRef) Value {
return newStructFromData(data, unionIndex, unionValue, typeRef, typeDef)
}
func structReader(s Struct, typeRef, typeDef TypeRef) []Value {
func structReader(s Struct, typeRef, typeDef Type) []Value {
values := []Value{}
desc := typeDef.Desc.(StructDesc)
+8 -8
View File
@@ -14,7 +14,7 @@ func TestGenericStructEquals(t *testing.T) {
Field{"x", MakePrimitiveTypeRef(BoolKind), false},
Field{"o", MakePrimitiveTypeRef(StringKind), true},
}, Choices{})
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
typeRef := MakeTypeRef(pkgRef, 0)
@@ -33,7 +33,7 @@ func TestGenericStructChunks(t *testing.T) {
typeDef := MakeStructTypeRef("S1", []Field{
Field{"r", MakeCompoundTypeRef(RefKind, MakePrimitiveTypeRef(BoolKind)), false},
}, Choices{})
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
typeRef := MakeTypeRef(pkgRef, 0)
@@ -53,7 +53,7 @@ func TestGenericStructChunksOptional(t *testing.T) {
typeDef := MakeStructTypeRef("S1", []Field{
Field{"r", MakeCompoundTypeRef(RefKind, MakePrimitiveTypeRef(BoolKind)), true},
}, Choices{})
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
typeRef := MakeTypeRef(pkgRef, 0)
@@ -80,7 +80,7 @@ func TestGenericStructChunksUnion(t *testing.T) {
Field{"r", MakeCompoundTypeRef(RefKind, MakePrimitiveTypeRef(BoolKind)), false},
Field{"s", MakePrimitiveTypeRef(StringKind), false},
})
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
typeRef := MakeTypeRef(pkgRef, 0)
@@ -105,7 +105,7 @@ func TestGenericStructNew(t *testing.T) {
Field{"b", MakePrimitiveTypeRef(BoolKind), false},
Field{"o", MakePrimitiveTypeRef(StringKind), true},
}, Choices{})
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
typeRef := MakeTypeRef(pkgRef, 0)
@@ -134,7 +134,7 @@ func TestGenericStructNewUnion(t *testing.T) {
Field{"b", MakePrimitiveTypeRef(BoolKind), false},
Field{"o", MakePrimitiveTypeRef(StringKind), false},
})
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
typeRef := MakeTypeRef(pkgRef, 0)
@@ -151,7 +151,7 @@ func TestGenericStructSet(t *testing.T) {
Field{"b", MakePrimitiveTypeRef(BoolKind), false},
Field{"o", MakePrimitiveTypeRef(StringKind), true},
}, Choices{})
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
typeRef := MakeTypeRef(pkgRef, 0)
@@ -172,7 +172,7 @@ func TestGenericStructSetUnion(t *testing.T) {
Field{"b", MakePrimitiveTypeRef(BoolKind), false},
Field{"s", MakePrimitiveTypeRef(StringKind), false},
})
pkg := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg := NewPackage([]Type{typeDef}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
typeRef := MakeTypeRef(pkgRef, 0)
+5 -5
View File
@@ -26,7 +26,7 @@ type TypeDesc interface {
// Int8
// Package
// String
// TypeRef
// Type
// UInt16
// UInt32
// UInt64
@@ -61,7 +61,7 @@ var KindToString = map[NomsKind]string{
RefKind: "Ref",
SetKind: "Set",
StringKind: "String",
TypeRefKind: "TypeRef",
TypeRefKind: "Type",
UInt16Kind: "UInt16",
UInt32Kind: "UInt32",
UInt64Kind: "UInt64",
@@ -104,7 +104,7 @@ func (u UnresolvedDesc) Describe() string {
// ElemTypes indicates what type or types are in the container indicated by kind, e.g. Map key and value or Set element.
type CompoundDesc struct {
kind NomsKind
ElemTypes []TypeRef
ElemTypes []Type
}
func (c CompoundDesc) Kind() NomsKind {
@@ -224,10 +224,10 @@ func (s StructDesc) Describe() (out string) {
}
// Field represents a Struct field or a Union choice.
// Neither Name nor T is allowed to be a zero-value, though T may be an unresolved TypeRef.
// Neither Name nor T is allowed to be a zero-value, though T may be an unresolved Type.
type Field struct {
Name string
T TypeRef
T Type
Optional bool
}
+37 -41
View File
@@ -5,15 +5,15 @@ import (
"github.com/attic-labs/noms/ref"
)
// TypeRef structs define and describe Noms types, both custom and built-in.
// name is required for StructKind and EnumKind types, and may be allowed for others if we do type aliases. Named types are 'exported' in that they can be addressed from other type packages.
// Desc provided more details of the type. It may contain only a types.NomsKind, in the case of primitives, or it may contain additional information -- e.g. element TypeRefs for compound type specializations, field descriptions for structs, etc. Either way, checking Kind() allows code to understand how to interpret the rest of the data.
// If Kind() refers to a primitive, then Desc is empty.
// If Kind() refers to List, Map, Set or Ref, then Desc is a list of TypeRefs describing the element type(s).
// If Kind() refers to Struct, then Desc is {[name, type, ...], [name, type, ...]}.
// If Kind() refers to Enum, then Desc is a List(String) describing the enumerated values.
// Type defines and describes Noms types, both custom and built-in.
// StructKind and EnumKind types, and possibly others if we do type aliases, will have a Name(). Named types are 'exported' in that they can be addressed from other type packages.
// Desc provides more details of the type. It may contain only a types.NomsKind, in the case of primitives, or it may contain additional information -- e.g. element Types for compound type specializations, field descriptions for structs, etc. Either way, checking Kind() allows code to understand how to interpret the rest of the data.
// If Kind() refers to a primitive, then Desc has no more info.
// If Kind() refers to List, Map, Set or Ref, then Desc is a list of Types describing the element type(s).
// If Kind() refers to Struct, then Desc contains a []Field and Choices.
// If Kind() refers to Enum, then Desc is a []string describing the enumerated values.
// If Kind() refers to an UnresolvedKind, then Desc contains a PackageRef, which is the Ref of the package where the type definition is defined. The ordinal, if not -1, is the index into the Types list of the package. If the Name is set then the ordinal needs to be found.
type TypeRef struct {
type Type struct {
name name
Desc TypeDesc
@@ -25,7 +25,7 @@ type name struct {
}
func (n name) compose() (out string) {
d.Chk.True(n.namespace == "" || (n.namespace != "" && n.name != ""), "If a TypeRef's namespace is set, so must name be.")
d.Chk.True(n.namespace == "" || (n.namespace != "" && n.name != ""), "If a Type's namespace is set, so must name be.")
if n.namespace != "" {
out = n.namespace + "."
}
@@ -36,18 +36,18 @@ func (n name) compose() (out string) {
}
// IsUnresolved returns true if t doesn't contain description information. The caller should look the type up by Ordinal in the Types of the appropriate Package.
func (t TypeRef) IsUnresolved() bool {
func (t Type) IsUnresolved() bool {
_, ok := t.Desc.(UnresolvedDesc)
return ok
}
func (t TypeRef) HasPackageRef() bool {
func (t Type) HasPackageRef() bool {
return t.IsUnresolved() && !t.PackageRef().IsEmpty()
}
// Describe() methods generate text that should parse into the struct being described.
// TODO: Figure out a way that they can exist only in the test file.
func (t TypeRef) Describe() (out string) {
func (t Type) Describe() (out string) {
if t.name != (name{}) {
out += t.name.compose() + "\n"
}
@@ -57,46 +57,42 @@ func (t TypeRef) Describe() (out string) {
return
}
func (t TypeRef) Kind() NomsKind {
func (t Type) Kind() NomsKind {
return t.Desc.Kind()
}
func (t TypeRef) PackageRef() ref.Ref {
func (t Type) PackageRef() ref.Ref {
desc, ok := t.Desc.(UnresolvedDesc)
d.Chk.True(ok, "PackageRef only works on unresolved type refs")
return desc.pkgRef
}
func (t TypeRef) Ordinal() int16 {
func (t Type) Ordinal() int16 {
d.Chk.True(t.HasOrdinal(), "Ordinal has not been set")
return t.Desc.(UnresolvedDesc).ordinal
}
func (t TypeRef) HasOrdinal() bool {
func (t Type) HasOrdinal() bool {
return t.IsUnresolved() && t.Desc.(UnresolvedDesc).ordinal >= 0
}
func (t TypeRef) Name() string {
func (t Type) Name() string {
return t.name.name
}
func (t TypeRef) NamespacedName() string {
return t.name.compose()
}
func (t TypeRef) Namespace() string {
func (t Type) Namespace() string {
return t.name.namespace
}
func (t TypeRef) Ref() ref.Ref {
func (t Type) Ref() ref.Ref {
return EnsureRef(t.ref, t)
}
func (t TypeRef) Equals(other Value) (res bool) {
func (t Type) Equals(other Value) (res bool) {
return other != nil && t.Ref() == other.Ref()
}
func (t TypeRef) Chunks() (chunks []ref.Ref) {
func (t Type) Chunks() (chunks []ref.Ref) {
if t.IsUnresolved() {
if t.HasPackageRef() {
chunks = append(chunks, t.PackageRef())
@@ -111,7 +107,7 @@ func (t TypeRef) Chunks() (chunks []ref.Ref) {
return
}
func (t TypeRef) ChildValues() (res []Value) {
func (t Type) ChildValues() (res []Value) {
if t.HasPackageRef() {
res = append(res, NewRefOfPackage(t.PackageRef()))
}
@@ -139,21 +135,21 @@ func (t TypeRef) ChildValues() (res []Value) {
return
}
var typeRefForTypeRef = MakePrimitiveTypeRef(TypeRefKind)
var TypeForTypeRef = MakePrimitiveTypeRef(TypeRefKind)
func (t TypeRef) TypeRef() TypeRef {
return typeRefForTypeRef
func (t Type) Type() Type {
return TypeForTypeRef
}
func MakePrimitiveTypeRef(k NomsKind) TypeRef {
func MakePrimitiveTypeRef(k NomsKind) Type {
return buildType("", PrimitiveDesc(k))
}
func MakePrimitiveTypeRefByString(p string) TypeRef {
func MakePrimitiveTypeRefByString(p string) Type {
return buildType("", primitiveToDesc(p))
}
func MakeCompoundTypeRef(kind NomsKind, elemTypes ...TypeRef) TypeRef {
func MakeCompoundTypeRef(kind NomsKind, elemTypes ...Type) Type {
if len(elemTypes) == 1 {
d.Chk.NotEqual(MapKind, kind, "MapKind requires 2 element types.")
} else {
@@ -163,30 +159,30 @@ func MakeCompoundTypeRef(kind NomsKind, elemTypes ...TypeRef) TypeRef {
return buildType("", CompoundDesc{kind, elemTypes})
}
func MakeEnumTypeRef(name string, ids ...string) TypeRef {
func MakeEnumTypeRef(name string, ids ...string) Type {
return buildType(name, EnumDesc{ids})
}
func MakeStructTypeRef(name string, fields []Field, choices Choices) TypeRef {
func MakeStructTypeRef(name string, fields []Field, choices Choices) Type {
return buildType(name, StructDesc{fields, choices})
}
func MakeTypeRef(pkgRef ref.Ref, ordinal int16) TypeRef {
func MakeTypeRef(pkgRef ref.Ref, ordinal int16) Type {
d.Chk.True(ordinal >= 0)
return TypeRef{Desc: UnresolvedDesc{pkgRef, ordinal}, ref: &ref.Ref{}}
return Type{Desc: UnresolvedDesc{pkgRef, ordinal}, ref: &ref.Ref{}}
}
func MakeUnresolvedTypeRef(namespace, n string) TypeRef {
return TypeRef{name: name{namespace, n}, Desc: UnresolvedDesc{ordinal: -1}, ref: &ref.Ref{}}
func MakeUnresolvedTypeRef(namespace, n string) Type {
return Type{name: name{namespace, n}, Desc: UnresolvedDesc{ordinal: -1}, ref: &ref.Ref{}}
}
func buildType(n string, desc TypeDesc) TypeRef {
func buildType(n string, desc TypeDesc) Type {
if IsPrimitiveKind(desc.Kind()) {
return TypeRef{name: name{name: n}, Desc: desc, ref: &ref.Ref{}}
return Type{name: name{name: n}, Desc: desc, ref: &ref.Ref{}}
}
switch desc.Kind() {
case ListKind, RefKind, SetKind, MapKind, EnumKind, StructKind, UnresolvedKind:
return TypeRef{name: name{name: n}, Desc: desc, ref: &ref.Ref{}}
return Type{name: name{name: n}, Desc: desc, ref: &ref.Ref{}}
default:
d.Exp.Fail("Unrecognized Kind:", "%v", desc.Kind())
panic("unreachable")
+2 -2
View File
@@ -45,7 +45,7 @@ func TestTypeWithPkgRef(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
pkg := NewPackage([]TypeRef{MakePrimitiveTypeRef(Float64Kind)}, []ref.Ref{})
pkg := NewPackage([]Type{MakePrimitiveTypeRef(Float64Kind)}, []ref.Ref{})
pkgRef := RegisterPackage(&pkg)
unresolvedType := MakeTypeRef(pkgRef, 42)
@@ -57,5 +57,5 @@ func TestTypeWithPkgRef(t *testing.T) {
}
func TestTypeRefTypeRef(t *testing.T) {
assert.True(t, MakePrimitiveTypeRef(BoolKind).TypeRef().Equals(MakePrimitiveTypeRef(TypeRefKind)))
assert.True(t, MakePrimitiveTypeRef(BoolKind).Type().Equals(MakePrimitiveTypeRef(TypeRefKind)))
}
+2 -2
View File
@@ -8,8 +8,8 @@ import (
type Value interface {
Equals(other Value) bool
Ref() ref.Ref
// Returns the immediate children of this value in the DAG, if any, not including TypeRef().
// Returns the immediate children of this value in the DAG, if any, not including Type().
ChildValues() []Value
Chunks() []ref.Ref
TypeRef() TypeRef
Type() Type
}
+6 -6
View File
@@ -33,9 +33,9 @@ func TestWriteValue(t *testing.T) {
testEncode(fmt.Sprintf("t [%d,\"hi\"]", StringKind), NewString("hi"))
testEncode(fmt.Sprintf("t [%d,[],[]]", PackageKind), Package{types: []TypeRef{}, dependencies: []ref.Ref{}, ref: &ref.Ref{}})
ref1 := testEncode(fmt.Sprintf("t [%d,[%d],[]]", PackageKind, BoolKind), Package{types: []TypeRef{MakePrimitiveTypeRef(BoolKind)}, dependencies: []ref.Ref{}, ref: &ref.Ref{}})
testEncode(fmt.Sprintf("t [%d,[],[\"%s\"]]", PackageKind, ref1), Package{types: []TypeRef{}, dependencies: []ref.Ref{ref1}, ref: &ref.Ref{}})
testEncode(fmt.Sprintf("t [%d,[],[]]", PackageKind), Package{types: []Type{}, dependencies: []ref.Ref{}, ref: &ref.Ref{}})
ref1 := testEncode(fmt.Sprintf("t [%d,[%d],[]]", PackageKind, BoolKind), Package{types: []Type{MakePrimitiveTypeRef(BoolKind)}, dependencies: []ref.Ref{}, ref: &ref.Ref{}})
testEncode(fmt.Sprintf("t [%d,[],[\"%s\"]]", PackageKind, ref1), Package{types: []Type{}, dependencies: []ref.Ref{ref1}, ref: &ref.Ref{}})
}
func TestWriteBlobLeaf(t *testing.T) {
@@ -68,7 +68,7 @@ func TestWritePackageWhenValueIsWritten(t *testing.T) {
typeDef := MakeStructTypeRef("S", []Field{
Field{"X", MakePrimitiveTypeRef(Int32Kind), false},
}, Choices{})
pkg1 := NewPackage([]TypeRef{typeDef}, []ref.Ref{})
pkg1 := NewPackage([]Type{typeDef}, []ref.Ref{})
// Don't write package
pkgRef1 := RegisterPackage(&pkg1)
typeRef := MakeTypeRef(pkgRef1, 0)
@@ -84,11 +84,11 @@ func TestWritePackageDepWhenPackageIsWritten(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
pkg1 := NewPackage([]TypeRef{}, []ref.Ref{})
pkg1 := NewPackage([]Type{}, []ref.Ref{})
// Don't write package
pkgRef1 := RegisterPackage(&pkg1)
pkg2 := NewPackage([]TypeRef{}, []ref.Ref{pkgRef1})
pkg2 := NewPackage([]Type{}, []ref.Ref{pkgRef1})
WriteValue(pkg2, cs)
pkg3 := ReadValue(pkgRef1, cs)