func (suite *WalkAllTestSuite) TestWalkComposites() { suite.walkWorker(suite.storeAndRef(types.NewList()), 2) suite.walkWorker(suite.storeAndRef(types.NewList(types.Bool(false), types.Int32(8))), 4) suite.walkWorker(suite.storeAndRef(types.NewSet()), 2) suite.walkWorker(suite.storeAndRef(types.NewSet(types.Bool(false), types.Int32(8))), 4) suite.walkWorker(suite.storeAndRef(types.NewMap()), 2) suite.walkWorker(suite.storeAndRef(types.NewMap(types.Int32(8), types.Bool(true), types.Int32(0), types.Bool(false))), 6) }
func (suite *WalkTestSuite) SkipTestSkipSetElement() { wholeSet := types.NewSet(suite.mustSkip, suite.shouldSee).Insert(suite.shouldSee) reached := suite.skipWorker(wholeSet) for _, v := range []types.Value{wholeSet, suite.mustSkip, suite.shouldSee, suite.shouldSeeItem} { suite.Contains(reached, v, "Doesn't contain %+v", v) } suite.Len(reached, 4) }
func (suite *WalkTestSuite) TestStopWalkImmediately() { actual := 0 SomeP(types.NewList(types.NewSet(), types.NewList()), suite.vs, func(v types.Value) bool { actual++ return true }, 1) suite.Equal(1, actual) }
func (suite *WalkTestSuite) SkipTestSkipMapValue() { shouldAlsoSeeItem := types.NewString("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) }
func pullDeepRef(t *testing.T, topdown bool) { assert := assert.New(t) sink := createTestDataset("sink") source := createTestDataset("source") sourceInitialValue := types.NewList( types.NewList(NewList(source)), types.NewSet(NewSet(source)), types.NewMap(NewMap(source), NewMap(source))) source, err := source.Commit(sourceInitialValue) assert.NoError(err) sink, err = sink.pull(source.Store(), source.Head().Ref(), 1, topdown) assert.NoError(err) assert.True(source.Head().Equals(sink.Head())) }
func (suite *WalkAllTestSuite) TestWalkNestedComposites() { cs := chunks.NewMemoryStore() suite.walkWorker(suite.storeAndRef(types.NewList(suite.NewSet(cs), types.Int32(8))), 5) suite.walkWorker(suite.storeAndRef(types.NewSet(suite.NewList(cs), suite.NewSet(cs))), 6) // {"string": "string", // "list": [false true], // "map": {"nested": "string"} // "mtlist": [] // "set": [5 7 8] // []: "wow" // } nested := types.NewMap( types.NewString("string"), types.NewString("string"), types.NewString("list"), suite.NewList(cs, types.Bool(false), types.Bool(true)), types.NewString("map"), suite.NewMap(cs, types.NewString("nested"), types.NewString("string")), types.NewString("mtlist"), suite.NewList(cs), types.NewString("set"), suite.NewSet(cs, types.Int32(5), types.Int32(7), types.Int32(8)), suite.NewList(cs), types.NewString("wow"), // note that the dupe list chunk is skipped ) suite.walkWorker(suite.storeAndRef(nested), 25) }
func (suite *WalkAllTestSuite) NewSet(cs chunks.ChunkStore, vs ...types.Value) types.RefBase { v := types.NewSet(vs...) return suite.vs.WriteValue(v) }
func NewSet(ds Dataset, vs ...types.Value) types.RefBase { v := types.NewSet(vs...) return ds.Store().WriteValue(v) }