本文整理汇总了Golang中github.com/attic-labs/noms/go/types.NewMap函数的典型用法代码示例。如果您正苦于以下问题:Golang NewMap函数的具体用法?Golang NewMap怎么用?Golang NewMap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewMap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestCompositeTypes
func (suite *LibTestSuite) TestCompositeTypes() {
// [false true]
suite.EqualValues(
types.NewList().Append(types.Bool(false)).Append(types.Bool(true)),
NomsValueFromDecodedJSON([]interface{}{false, true}, false))
// [[false true]]
suite.EqualValues(
types.NewList().Append(
types.NewList().Append(types.Bool(false)).Append(types.Bool(true))),
NomsValueFromDecodedJSON([]interface{}{[]interface{}{false, true}}, false))
// {"string": "string",
// "list": [false true],
// "map": {"nested": "string"}
// }
m := types.NewMap(
types.String("string"),
types.String("string"),
types.String("list"),
types.NewList().Append(types.Bool(false)).Append(types.Bool(true)),
types.String("map"),
types.NewMap(
types.String("nested"),
types.String("string")))
o := NomsValueFromDecodedJSON(map[string]interface{}{
"string": "string",
"list": []interface{}{false, true},
"map": map[string]interface{}{"nested": "string"},
}, false)
suite.True(m.Equals(o))
}
示例2: TestWalkComposites
func (suite *WalkAllTestSuite) TestWalkComposites() {
suite.walkWorker(suite.storeAndRef(types.NewList()), 2)
suite.walkWorker(suite.storeAndRef(types.NewList(types.Bool(false), types.Number(8))), 4)
suite.walkWorker(suite.storeAndRef(types.NewSet()), 2)
suite.walkWorker(suite.storeAndRef(types.NewSet(types.Bool(false), types.Number(8))), 4)
suite.walkWorker(suite.storeAndRef(types.NewMap()), 2)
suite.walkWorker(suite.storeAndRef(types.NewMap(types.Number(8), types.Bool(true), types.Number(0), types.Bool(false))), 6)
}
示例3: TestHandlePostRoot
func TestHandlePostRoot(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
vs := types.NewValueStore(types.NewBatchStoreAdaptor(cs))
commit := NewCommit(types.String("head"), types.NewSet(), types.NewStruct("Meta", types.StructData{}))
newHead := types.NewMap(types.String("dataset1"), vs.WriteValue(commit))
chnx := []chunks.Chunk{
chunks.NewChunk([]byte("abc")),
types.EncodeValue(newHead, nil),
}
err := cs.PutMany(chnx)
assert.NoError(err)
// First attempt should fail, as 'last' won't match.
u := &url.URL{}
queryParams := url.Values{}
queryParams.Add("last", chnx[0].Hash().String())
queryParams.Add("current", chnx[1].Hash().String())
u.RawQuery = queryParams.Encode()
url := u.String()
w := httptest.NewRecorder()
HandleRootPost(w, newRequest("POST", "", url, nil, nil), params{}, cs)
assert.Equal(http.StatusConflict, w.Code, "Handler error:\n%s", string(w.Body.Bytes()))
// Now, update the root manually to 'last' and try again.
assert.True(cs.UpdateRoot(chnx[0].Hash(), hash.Hash{}))
w = httptest.NewRecorder()
HandleRootPost(w, newRequest("POST", "", url, nil, nil), params{}, cs)
assert.Equal(http.StatusOK, w.Code, "Handler error:\n%s", string(w.Body.Bytes()))
}
示例4: start
func start(dataset string, mount mount) {
ds, err := spec.GetDataset(dataset)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not create dataset: %s\n", err)
return
}
hv, ok := ds.MaybeHeadValue()
if ok {
if !types.IsSubtype(fsType, hv.Type()) {
fmt.Fprintf(os.Stderr, "Invalid dataset head: expected type '%s' but found type '%s'\n", fsType.Desc.(types.StructDesc).Name, hv.Type().Desc.(types.StructDesc).Name)
return
}
} else {
rootAttr := makeAttr(0777) // create the root directory with maximally permissive permissions
rootDir := types.NewStructWithType(directoryType, types.ValueSlice{types.NewMap()})
rootInode := types.NewStructWithType(inodeType, types.ValueSlice{rootAttr, rootDir})
hv = types.NewStructWithType(fsType, types.ValueSlice{rootInode})
}
mount(&nomsFS{
FileSystem: pathfs.NewDefaultFileSystem(),
ds: ds,
head: hv.(types.Struct),
mdLock: &sync.Mutex{},
nodes: make(map[hash.Hash]*nNode),
})
}
示例5: getPersons
func getPersons(ds dataset.Dataset) types.Map {
hv, ok := ds.MaybeHeadValue()
if ok {
return hv.(types.Map)
} else {
return types.NewMap()
}
}
示例6: buildMap
func buildMap(count uint64, createFn createValueFn) types.Collection {
values := make([]types.Value, count*2)
for i := uint64(0); i < count*2; i++ {
values[i] = createFn(i)
}
return types.NewMap(values...)
}
示例7: SkipTestSkipMapKey
func (suite *WalkTestSuite) SkipTestSkipMapKey() {
wholeMap := types.NewMap(suite.mustSkip, suite.shouldSee, suite.shouldSee, suite.shouldSee)
reached := suite.skipWorker(wholeMap)
for _, v := range []types.Value{wholeMap, suite.mustSkip, suite.shouldSee, suite.shouldSeeItem} {
suite.Contains(reached, v, "Doesn't contain %+v", v)
}
suite.Len(reached, 8)
}
示例8: TestUpdateRootWithParams
func (suite *HTTPBatchStoreSuite) TestUpdateRootWithParams() {
u := fmt.Sprintf("http://localhost:9000?access_token=%s&other=19", testAuthToken)
store := newAuthenticatingHTTPBatchStoreForTest(suite, u)
c := types.EncodeValue(types.NewMap(), nil)
suite.cs.Put(c)
suite.True(store.UpdateRoot(c.Hash(), hash.Hash{}))
suite.Equal(c.Hash(), suite.cs.Root())
}
示例9: Mkdir
func (fs *nomsFS) Mkdir(path string, mode uint32, context *fuse.Context) fuse.Status {
fs.mdLock.Lock()
defer fs.mdLock.Unlock()
_, code := fs.createCommon(path, mode, func() types.Value {
return types.NewStructWithType(directoryType, types.ValueSlice{types.NewMap()})
})
return code
}
示例10: buildMapIncrementally
func buildMapIncrementally(count uint64, createFn createValueFn) types.Collection {
m := types.NewMap()
for i := uint64(0); i < count*2; i += 2 {
m = m.Set(createFn(i), createFn(i+1))
}
return m
}
示例11: SkipTestSkipMapValue
func (suite *WalkTestSuite) SkipTestSkipMapValue() {
shouldAlsoSeeItem := types.String("Also good")
shouldAlsoSee := types.NewSet(shouldAlsoSeeItem)
wholeMap := types.NewMap(suite.shouldSee, suite.mustSkip, shouldAlsoSee, suite.shouldSee)
reached := suite.skipWorker(wholeMap)
for _, v := range []types.Value{wholeMap, suite.shouldSee, suite.shouldSeeItem, suite.mustSkip, shouldAlsoSee, shouldAlsoSeeItem} {
suite.Contains(reached, v, "Doesn't contain %+v", v)
}
suite.Len(reached, 8)
}
示例12: Datasets
func (ds *databaseCommon) Datasets() types.Map {
if ds.datasets == nil {
if ds.rootRef.IsEmpty() {
emptyMap := types.NewMap()
ds.datasets = &emptyMap
} else {
ds.datasets = ds.datasetsFromRef(ds.rootRef)
}
}
return *ds.datasets
}
示例13: TestPullTopDown
func TestPullTopDown(t *testing.T) {
assert := assert.New(t)
sink := createTestDataset("sink")
source := createTestDataset("source")
// Give sink and source some initial shared context.
sourceInitialValue := types.NewMap(
types.String("first"), NewList(source),
types.String("second"), NewList(source, types.Number(2)))
sinkInitialValue := types.NewMap(
types.String("first"), NewList(sink),
types.String("second"), NewList(sink, types.Number(2)))
var err error
source, err = source.Commit(sourceInitialValue)
assert.NoError(err)
sink, err = sink.Commit(sinkInitialValue)
assert.NoError(err)
// Add some new stuff to source.
updatedValue := sourceInitialValue.Set(
types.String("third"), NewList(source, types.Number(3)))
source, err = source.Commit(updatedValue)
assert.NoError(err)
// Add some more stuff, so that source isn't directly ahead of sink.
updatedValue = updatedValue.Set(
types.String("fourth"), NewList(source, types.Number(4)))
source, err = source.Commit(updatedValue)
assert.NoError(err)
sink, err = sink.pull(source.Database(), types.NewRef(source.Head()), 1)
assert.NoError(err)
assert.True(source.Head().Equals(sink.Head()))
}
示例14: NomsValueFromDecodedJSON
// NomsValueFromDecodedJSON takes a generic Go interface{} and recursively
// tries to resolve the types within so that it can build up and return
// a Noms Value with the same structure.
//
// Currently, the only types supported are the Go versions of legal JSON types:
// Primitives:
// - float64
// - bool
// - string
// - nil
//
// Composites:
// - []interface{}
// - map[string]interface{}
func NomsValueFromDecodedJSON(o interface{}, useStruct bool) types.Value {
switch o := o.(type) {
case string:
return types.String(o)
case bool:
return types.Bool(o)
case float64:
return types.Number(o)
case nil:
return nil
case []interface{}:
items := make([]types.Value, 0, len(o))
for _, v := range o {
nv := NomsValueFromDecodedJSON(v, useStruct)
if nv != nil {
items = append(items, nv)
}
}
return types.NewList(items...)
case map[string]interface{}:
var v types.Value
if useStruct {
fields := make(map[string]types.Value, len(o))
for k, v := range o {
nv := NomsValueFromDecodedJSON(v, useStruct)
if nv != nil {
k := types.EscapeStructField(k)
fields[k] = nv
}
}
v = types.NewStruct("", fields)
} else {
kv := make([]types.Value, 0, len(o)*2)
for k, v := range o {
nv := NomsValueFromDecodedJSON(v, useStruct)
if nv != nil {
kv = append(kv, types.String(k), nv)
}
}
v = types.NewMap(kv...)
}
return v
default:
d.Chk.Fail("Nomsification failed.", "I don't understand %+v, which is of type %s!\n", o, reflect.TypeOf(o).String())
}
return nil
}
示例15: ReadToMap
func ReadToMap(r *csv.Reader, headers_raw []string, pkIdx int, kinds KindSlice, vrw types.ValueReadWriter) (m types.Map) {
headers := make([]string, 0, len(headers_raw)-1)
for i, h := range headers_raw {
if i != pkIdx {
headers = append(headers, types.EscapeStructField(h))
}
}
var pkKind types.NomsKind
if len(kinds) == 0 {
pkKind = types.StringKind
} else {
pkKind = kinds[pkIdx]
kinds = append(kinds[:pkIdx], kinds[pkIdx+1:]...)
}
t := MakeStructTypeFromHeaders(headers, "", kinds)
kindMap := make(map[string]types.NomsKind, len(headers))
t.Desc.(types.StructDesc).IterFields(func(name string, t *types.Type) {
kindMap[name] = t.Kind()
})
m = types.NewMap()
fields := map[string]types.Value{}
var pk types.Value
for {
row, err := r.Read()
if err == io.EOF {
break
} else if err != nil {
panic(err)
}
fieldIndex := 0
for x, v := range row {
if x == pkIdx {
pk = StringToType(v, pkKind)
} else if fieldIndex < len(headers) {
name := headers[fieldIndex]
fields[name] = StringToType(v, kindMap[name])
fieldIndex++
}
}
m = m.Set(pk, types.NewStructWithType(t, fields))
}
return
}