コード例 #1
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})
}
コード例 #2
0
ファイル: read_test.go プロジェクト: willhite/noms-old
func TestReadToMap(t *testing.T) {
	assert := assert.New(t)
	ds := datas.NewDatabase(chunks.NewMemoryStore())

	dataString := `a,1,true
b,2,false
`
	r := NewCSVReader(bytes.NewBufferString(dataString), ',')

	headers := []string{"A", "B", "C"}
	kinds := KindSlice{types.StringKind, types.NumberKind, types.BoolKind}
	m := ReadToMap(r, headers, 0, kinds, ds)

	assert.Equal(uint64(2), m.Len())
	assert.True(m.Type().Equals(
		types.MakeMapType(types.StringType, types.MakeStructType("", map[string]*types.Type{
			"B": types.NumberType,
			"C": types.BoolType,
		}))))

	assert.True(m.Get(types.String("a")).Equals(types.NewStruct("", map[string]types.Value{
		"B": types.Number(1),
		"C": types.Bool(true),
	})))
	assert.True(m.Get(types.String("b")).Equals(types.NewStruct("", map[string]types.Value{
		"B": types.Number(2),
		"C": types.Bool(false),
	})))
}
コード例 #3
0
ファイル: parse_test.go プロジェクト: willhite/noms-old
func (suite *ParsedResultTestSuite) SetupTest() {
	suite.prim = newTestField("a", types.NumberType, "")
	suite.prim2 = newTestField("b", types.StringType, "")
	suite.compound = newTestField("set", types.MakeSetType(types.StringType), "")
	suite.compoundOfCompound = newTestField("listOfSet", types.MakeListType(types.MakeSetType(types.StringType)), "")
	suite.namedType = newTestField("otherStruct", makeUnresolvedType("", "Other"), "Other")
	suite.namespacedType = newTestField("namespacedStruct", makeUnresolvedType("Elsewhere", "Other"), "Elsewhere.Other")
	suite.mapOfNamedType = newTestField("mapOfStructToOther", types.MakeMapType(makeUnresolvedType("", "Struct"), makeUnresolvedType("Elsewhere", "Other")), "Map<Struct, Elsewhere.Other>")
}
コード例 #4
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)
	}
}
コード例 #5
0
ファイル: commit.go プロジェクト: willhite/noms-old
func typeForMapOfStringToRefOfCommit() *types.Type {
	return types.MakeMapType(types.StringType, refOfCommitType)
}
コード例 #6
0
ファイル: grammar.peg.go プロジェクト: willhite/noms-old
func (c *current) onCompoundType13(k, v interface{}) (interface{}, error) {
	return types.MakeMapType(k.(*types.Type), v.(*types.Type)), nil
}