コード例 #1
0
ファイル: commit.go プロジェクト: Richardphp/noms
func makeCommitType(valueType *types.Type, parentsValueTypes []*types.Type, metaType *types.Type, parentsMetaTypes []*types.Type) *types.Type {
	tmp := make([]*types.Type, len(parentsValueTypes), len(parentsValueTypes)+1)
	copy(tmp, parentsValueTypes)
	tmp = append(tmp, valueType)
	parentsValueUnionType := types.MakeUnionType(tmp...)

	tmp2 := make([]*types.Type, len(parentsMetaTypes), len(parentsMetaTypes)+1)
	copy(tmp2, parentsMetaTypes)
	tmp2 = append(tmp2, metaType)
	parentsMetaUnionType := types.MakeUnionType(tmp2...)

	fieldNames := []string{MetaField, ParentsField, ValueField}
	var parentsType *types.Type
	if parentsValueUnionType.Equals(valueType) && parentsMetaUnionType.Equals(metaType) {
		parentsType = types.MakeSetType(types.MakeRefType(types.MakeCycleType(0)))
	} else {
		parentsType = types.MakeSetType(types.MakeRefType(
			types.MakeStructType("Commit", fieldNames, []*types.Type{
				parentsMetaUnionType,
				types.MakeSetType(types.MakeRefType(types.MakeCycleType(0))),
				parentsValueUnionType,
			})))
	}
	fieldTypes := []*types.Type{
		metaType,
		parentsType,
		valueType,
	}

	return types.MakeStructType("Commit", fieldNames, fieldTypes)
}
コード例 #2
0
ファイル: commit_test.go プロジェクト: Richardphp/noms
func TestNewCommit(t *testing.T) {
	assert := assert.New(t)

	commitFieldNames := []string{MetaField, ParentsField, ValueField}

	assertTypeEquals := func(e, a *types.Type) {
		assert.True(a.Equals(e), "Actual: %s\nExpected %s", a.Describe(), e.Describe())
	}

	commit := NewCommit(types.Number(1), types.NewSet(), types.EmptyStruct)
	at := commit.Type()
	et := types.MakeStructType("Commit", commitFieldNames, []*types.Type{
		types.EmptyStructType,
		types.MakeSetType(types.MakeRefType(types.MakeCycleType(0))),
		types.NumberType,
	})
	assertTypeEquals(et, at)

	// Commiting another Number
	commit2 := NewCommit(types.Number(2), types.NewSet(types.NewRef(commit)), types.EmptyStruct)
	at2 := commit2.Type()
	et2 := et
	assertTypeEquals(et2, at2)

	// Now commit a String
	commit3 := NewCommit(types.String("Hi"), types.NewSet(types.NewRef(commit2)), types.EmptyStruct)
	at3 := commit3.Type()
	et3 := types.MakeStructType("Commit", commitFieldNames, []*types.Type{
		types.EmptyStructType,
		types.MakeSetType(types.MakeRefType(types.MakeStructType("Commit", commitFieldNames, []*types.Type{
			types.EmptyStructType,
			types.MakeSetType(types.MakeRefType(types.MakeCycleType(0))),
			types.MakeUnionType(types.NumberType, types.StringType),
		}))),
		types.StringType,
	})
	assertTypeEquals(et3, at3)

	// Now commit a String with MetaInfo
	meta := types.NewStruct("Meta", types.StructData{"date": types.String("some date"), "number": types.Number(9)})
	metaType := types.MakeStructType("Meta", []string{"date", "number"}, []*types.Type{types.StringType, types.NumberType})
	assertTypeEquals(metaType, meta.Type())
	commit4 := NewCommit(types.String("Hi"), types.NewSet(types.NewRef(commit2)), meta)
	at4 := commit4.Type()
	et4 := types.MakeStructType("Commit", commitFieldNames, []*types.Type{
		metaType,
		types.MakeSetType(types.MakeRefType(types.MakeStructType("Commit", commitFieldNames, []*types.Type{
			types.MakeUnionType(types.EmptyStructType, metaType),
			types.MakeSetType(types.MakeRefType(types.MakeCycleType(0))),
			types.MakeUnionType(types.NumberType, types.StringType),
		}))),
		types.StringType,
	})
	assertTypeEquals(et4, at4)
}
コード例 #3
0
ファイル: nomsfs.go プロジェクト: Richardphp/noms
func init() {
	inodeType = types.MakeStructType("Inode", []string{"attr", "contents"}, []*types.Type{
		types.MakeStructType("Attr", []string{"ctime", "gid", "mode", "mtime", "uid", "xattr"}, []*types.Type{types.NumberType, types.NumberType, types.NumberType, types.NumberType, types.NumberType, types.MakeMapType(types.StringType, types.BlobType)}),
		types.MakeUnionType(types.MakeStructType("Directory", []string{"entries"}, []*types.Type{
			types.MakeMapType(types.StringType, types.MakeCycleType(1))}),
			types.MakeStructType("File", []string{"data"}, []*types.Type{types.MakeRefType(types.BlobType)}),
			types.MakeStructType("Symlink", []string{"targetPath"}, []*types.Type{types.StringType}),
		),
	})

	// Root around for some useful types.
	attrType = inodeType.Desc.(types.StructDesc).Field("attr")
	for _, elemType := range inodeType.Desc.(types.StructDesc).Field("contents").Desc.(types.CompoundDesc).ElemTypes {
		switch elemType.Desc.(types.StructDesc).Name {
		case "Directory":
			directoryType = elemType
		case "File":
			fileType = elemType
		case "Symlink":
			symlinkType = elemType
		}
	}

	fsType = types.MakeStructType("Filesystem", []string{"root"}, []*types.Type{inodeType})
}
コード例 #4
0
ファイル: commit.go プロジェクト: willhite/noms-old
func init() {
	structName := "Commit"

	// struct Commit {
	//   parents: Set<Ref<Commit>>
	//   value: Value
	// }

	fieldTypes := types.TypeMap{
		ParentsField: nil,
		ValueField:   types.ValueType,
	}
	commitType = types.MakeStructType(structName, fieldTypes)
	commitType.Desc.(types.StructDesc).SetField(ParentsField, types.MakeSetType(types.MakeRefType(commitType)))
	refOfCommitType = types.MakeRefType(commitType)
}
コード例 #5
0
ファイル: database_test.go プロジェクト: Richardphp/noms
func (suite *DatabaseSuite) TestDatabaseHeightOfCollections() {
	setOfStringType := types.MakeSetType(types.StringType)
	setOfRefOfStringType := types.MakeSetType(types.MakeRefType(types.StringType))

	// Set<String>
	v1 := types.String("hello")
	v2 := types.String("world")
	s1 := types.NewSet(v1, v2)
	suite.Equal(uint64(1), suite.ds.WriteValue(s1).Height())

	// Set<Ref<String>>
	s2 := types.NewSet(suite.ds.WriteValue(v1), suite.ds.WriteValue(v2))
	suite.Equal(uint64(2), suite.ds.WriteValue(s2).Height())

	// List<Set<String>>
	v3 := types.String("foo")
	v4 := types.String("bar")
	s3 := types.NewSet(v3, v4)
	l1 := types.NewList(s1, s3)
	suite.Equal(uint64(1), suite.ds.WriteValue(l1).Height())

	// List<Ref<Set<String>>
	l2 := types.NewList(suite.ds.WriteValue(s1), suite.ds.WriteValue(s3))
	suite.Equal(uint64(2), suite.ds.WriteValue(l2).Height())

	// List<Ref<Set<Ref<String>>>
	s4 := types.NewSet(suite.ds.WriteValue(v3), suite.ds.WriteValue(v4))
	l3 := types.NewList(suite.ds.WriteValue(s4))
	suite.Equal(uint64(3), suite.ds.WriteValue(l3).Height())

	// List<Set<String> | RefValue<Set<String>>>
	l4 := types.NewList(s1, suite.ds.WriteValue(s3))
	suite.Equal(uint64(2), suite.ds.WriteValue(l4).Height())
	l5 := types.NewList(suite.ds.WriteValue(s1), s3)
	suite.Equal(uint64(2), suite.ds.WriteValue(l5).Height())

	// Familiar with the "New Jersey Turnpike" drink? Here's the noms version of that...
	everything := []types.Value{v1, v2, s1, s2, v3, v4, s3, l1, l2, s4, l3, l4, l5}
	andMore := make([]types.Value, 0, len(everything)*3+2)
	for _, v := range everything {
		andMore = append(andMore, v, v.Type(), suite.ds.WriteValue(v))
	}
	andMore = append(andMore, setOfStringType, setOfRefOfStringType)

	suite.ds.WriteValue(types.NewList(andMore...))
}
コード例 #6
0
ファイル: parse.go プロジェクト: willhite/noms-old
// resolveReferences replaces references with the actual Type
func resolveReferences(i *intermediate, aliases map[string][]*types.Type) {
	var rec func(t *types.Type) *types.Type
	resolveFields := func(desc types.StructDesc) *types.Type {
		fields := make(types.TypeMap, desc.Len())
		desc.IterFields(func(name string, t *types.Type) {
			fields[name] = rec(t)
		})
		return types.MakeStructType(desc.Name, fields)
	}
	rec = func(t *types.Type) *types.Type {
		switch t.Kind() {
		case UnresolvedKind:
			desc := t.Desc.(UnresolvedDesc)
			if desc.Namespace == "" {
				return findType(desc.Name, i.Types)
			}
			ts, ok := aliases[desc.Namespace]
			d.Exp.True(ok, "No such namespace: %s", desc.Namespace)
			return findType(desc.Name, ts)
		case types.ListKind:
			return types.MakeListType(rec(t.Desc.(types.CompoundDesc).ElemTypes[0]))
		case types.SetKind:
			return types.MakeSetType(rec(t.Desc.(types.CompoundDesc).ElemTypes[0]))
		case types.RefKind:
			return types.MakeRefType(rec(t.Desc.(types.CompoundDesc).ElemTypes[0]))
		case types.MapKind:
			elemTypes := t.Desc.(types.CompoundDesc).ElemTypes
			return types.MakeMapType(rec(elemTypes[0]), rec(elemTypes[1]))
		case types.StructKind:
			return resolveFields(t.Desc.(types.StructDesc))

		}
		return t
	}

	for idx, t := range i.Types {
		i.Types[idx] = rec(t)
	}
}
コード例 #7
0
ファイル: integration_test.go プロジェクト: Richardphp/noms
func (s *testSuite) Teardown() {
	out := s.NodeOutput()
	s.Contains(out, "1 of 1 entries")
	s.Contains(out, "done")

	db := s.Database()
	defer db.Close()
	ds := dataset.NewDataset(db, dsName)
	v := ds.HeadValue()
	s.True(v.Type().Equals(types.MakeStructType("File",
		[]string{"content"},
		[]*types.Type{
			types.MakeRefType(types.BlobType),
		},
	)))
	s.Equal("File", v.(types.Struct).Type().Desc.(types.StructDesc).Name)
	b := v.(types.Struct).Get("content").(types.Ref).TargetValue(db).(types.Blob)

	bs, err := ioutil.ReadAll(b.Reader())
	s.NoError(err)
	s.Equal([]byte("Hello World!\n"), bs)
}
コード例 #8
0
ファイル: grammar.peg.go プロジェクト: willhite/noms-old
func (c *current) onCompoundType40(t interface{}) (interface{}, error) {
	return types.MakeRefType(t.(*types.Type)), nil
}