dolt/go/store: types: List takes *Format in constructors.

This commit is contained in:
Aaron Son
2019-06-27 15:45:01 -07:00
committed by Brian Hendriks
parent f6fa340119
commit 0749018e83
44 changed files with 473 additions and 312 deletions
+2 -2
View File
@@ -63,11 +63,11 @@ func (s *nomsDiffTestSuite) TestNomsDiffStat() {
out, _ = s.MustRun(main, []string{"diff", "--stat", r1 + ".value", r2 + ".value"})
s.NotContains(out, "Comparing commit values")
ds, err = db.CommitValue(context.Background(), ds, types.NewList(context.Background(), db, types.Float(1), types.Float(2), types.Float(3), types.Float(4)))
ds, err = db.CommitValue(context.Background(), ds, types.NewList(context.Background(), types.Format_7_18, db, types.Float(1), types.Float(2), types.Float(3), types.Float(4)))
s.NoError(err)
r3 := spec.CreateHashSpecString("nbs", s.DBDir, ds.HeadRef().TargetHash()) + ".value"
ds, err = db.CommitValue(context.Background(), ds, types.NewList(context.Background(), db, types.Float(1), types.Float(222), types.Float(4)))
ds, err = db.CommitValue(context.Background(), ds, types.NewList(context.Background(), types.Format_7_18, db, types.Float(1), types.Float(222), types.Float(4)))
s.NoError(err)
r4 := spec.CreateHashSpecString("nbs", s.DBDir, ds.HeadRef().TargetHash()) + ".value"
+1 -1
View File
@@ -57,7 +57,7 @@ func nomsList(ctx context.Context, noms *kingpin.Application) (*kingpin.CmdClaus
func nomsListNew(ctx context.Context, dbStr string, args []string) int {
sp, err := spec.ForDatabase(dbStr)
d.PanicIfError(err)
applyListInserts(ctx, sp, types.NewList(ctx, sp.GetDatabase(ctx)), nil, 0, args)
applyListInserts(ctx, sp, types.NewList(ctx, types.Format_7_18, sp.GetDatabase(ctx)), nil, 0, args)
return 0
}
+1 -1
View File
@@ -293,7 +293,7 @@ func (s *nomsLogTestSuite) TestTruncation() {
for _, v := range l {
nv = append(nv, types.String(v))
}
return types.NewList(context.Background(), db, nv...)
return types.NewList(context.Background(), types.Format_7_18, db, nv...)
}
t := db.GetDataset(context.Background(), "truncate")
+4 -4
View File
@@ -49,7 +49,7 @@ func (s *nomsMergeTestSuite) TestNomsMerge_Success() {
types.StructData{
"num": types.Float(42),
"str": types.String("foobar"),
"lst": types.NewList(context.Background(), parentSpec.GetDatabase(context.Background()), types.Float(1), types.String("foo")),
"lst": types.NewList(context.Background(), types.Format_7_18, parentSpec.GetDatabase(context.Background()), types.Float(1), types.String("foo")),
"map": types.NewMap(context.Background(), parentSpec.GetDatabase(context.Background()), types.Float(1), types.String("foo"),
types.String("foo"), types.Float(1)),
},
@@ -60,7 +60,7 @@ func (s *nomsMergeTestSuite) TestNomsMerge_Success() {
types.StructData{
"num": types.Float(42),
"str": types.String("foobaz"),
"lst": types.NewList(context.Background(), leftSpec.GetDatabase(context.Background()), types.Float(1), types.String("foo")),
"lst": types.NewList(context.Background(), types.Format_7_18, leftSpec.GetDatabase(context.Background()), types.Float(1), types.String("foo")),
"map": types.NewMap(context.Background(), leftSpec.GetDatabase(context.Background()), types.Float(1), types.String("foo"),
types.String("foo"), types.Float(1)),
},
@@ -71,7 +71,7 @@ func (s *nomsMergeTestSuite) TestNomsMerge_Success() {
types.StructData{
"num": types.Float(42),
"str": types.String("foobar"),
"lst": types.NewList(context.Background(), rightSpec.GetDatabase(context.Background()), types.Float(1), types.String("foo")),
"lst": types.NewList(context.Background(), types.Format_7_18, rightSpec.GetDatabase(context.Background()), types.Float(1), types.String("foo")),
"map": types.NewMap(context.Background(), rightSpec.GetDatabase(context.Background()), types.Float(1), types.String("foo"),
types.String("foo"), types.Float(1), types.Float(2), types.String("bar")),
},
@@ -80,7 +80,7 @@ func (s *nomsMergeTestSuite) TestNomsMerge_Success() {
expected := types.NewStruct("", types.StructData{
"num": types.Float(42),
"str": types.String("foobaz"),
"lst": types.NewList(context.Background(), parentSpec.GetDatabase(context.Background()), types.Float(1), types.String("foo")),
"lst": types.NewList(context.Background(), types.Format_7_18, parentSpec.GetDatabase(context.Background()), types.Float(1), types.String("foo")),
"map": types.NewMap(context.Background(), parentSpec.GetDatabase(context.Background()), types.Float(1), types.String("foo"),
types.String("foo"), types.Float(1), types.Float(2), types.String("bar")),
})
+2 -2
View File
@@ -65,7 +65,7 @@ func (s *nomsShowTestSuite) TestNomsShow() {
sp := s.spec(str)
defer sp.Close()
list := types.NewList(context.Background(), sp.GetDatabase(context.Background()), types.String("elem1"), types.Float(2), types.String("elem3"))
list := types.NewList(context.Background(), types.Format_7_18, sp.GetDatabase(context.Background()), types.String("elem1"), types.Float(2), types.String("elem3"))
r = s.writeTestData(str, list)
res, _ = s.MustRun(main, []string{"show", str})
test.EqualsIgnoreHashes(s.T(), res3, res)
@@ -120,7 +120,7 @@ func (s *nomsShowTestSuite) TestNomsShowRaw() {
for i := 0; i < len(items); i++ {
items[i] = types.Float(i)
}
l := types.NewList(context.Background(), db, items...)
l := types.NewList(context.Background(), types.Format_7_18, db, items...)
numChildChunks := 0
l.WalkRefs(func(r types.Ref) {
numChildChunks++
+6 -6
View File
@@ -548,22 +548,22 @@ func (suite *DatabaseSuite) TestDatabaseHeightOfCollections() {
v3 := types.String("foo")
v4 := types.String("bar")
s3 := types.NewSet(context.Background(), suite.db, v3, v4)
l1 := types.NewList(context.Background(), suite.db, s1, s3)
l1 := types.NewList(context.Background(), types.Format_7_18, suite.db, s1, s3)
suite.Equal(uint64(1), suite.db.WriteValue(context.Background(), l1).Height())
// List<Ref<Set<String>>
l2 := types.NewList(context.Background(), suite.db, suite.db.WriteValue(context.Background(), s1), suite.db.WriteValue(context.Background(), s3))
l2 := types.NewList(context.Background(), types.Format_7_18, suite.db, suite.db.WriteValue(context.Background(), s1), suite.db.WriteValue(context.Background(), s3))
suite.Equal(uint64(2), suite.db.WriteValue(context.Background(), l2).Height())
// List<Ref<Set<Ref<String>>>
s4 := types.NewSet(context.Background(), suite.db, suite.db.WriteValue(context.Background(), v3), suite.db.WriteValue(context.Background(), v4))
l3 := types.NewList(context.Background(), suite.db, suite.db.WriteValue(context.Background(), s4))
l3 := types.NewList(context.Background(), types.Format_7_18, suite.db, suite.db.WriteValue(context.Background(), s4))
suite.Equal(uint64(3), suite.db.WriteValue(context.Background(), l3).Height())
// List<Set<String> | RefValue<Set<String>>>
l4 := types.NewList(context.Background(), suite.db, s1, suite.db.WriteValue(context.Background(), s3))
l4 := types.NewList(context.Background(), types.Format_7_18, suite.db, s1, suite.db.WriteValue(context.Background(), s3))
suite.Equal(uint64(2), suite.db.WriteValue(context.Background(), l4).Height())
l5 := types.NewList(context.Background(), suite.db, suite.db.WriteValue(context.Background(), s1), s3)
l5 := types.NewList(context.Background(), types.Format_7_18, suite.db, suite.db.WriteValue(context.Background(), s1), s3)
suite.Equal(uint64(2), suite.db.WriteValue(context.Background(), l5).Height())
// Familiar with the "New Jersey Turnpike" drink? Here's the noms version of that...
@@ -574,7 +574,7 @@ func (suite *DatabaseSuite) TestDatabaseHeightOfCollections() {
}
andMore = append(andMore, setOfStringType, setOfRefOfStringType)
suite.db.WriteValue(context.Background(), types.NewList(context.Background(), suite.db, andMore...))
suite.db.WriteValue(context.Background(), types.NewList(context.Background(), types.Format_7_18, suite.db, andMore...))
}
func (suite *DatabaseSuite) TestMetaOption() {
+7 -7
View File
@@ -233,9 +233,9 @@ func (suite *PullSuite) TestPullDivergentHistory() {
srcL := buildListOfHeight(3, suite.source)
sourceRef := suite.commitToSource(srcL, types.NewSet(context.Background(), suite.source))
sinkL = sinkL.Edit().Append(types.String("oy!")).List(context.Background())
sinkL = sinkL.Edit(types.Format_7_18).Append(types.String("oy!")).List(context.Background())
sinkRef = suite.commitToSink(sinkL, types.NewSet(context.Background(), suite.sink, sinkRef))
srcL = srcL.Edit().Set(1, buildListOfHeight(5, suite.source)).List(context.Background())
srcL = srcL.Edit(types.Format_7_18).Set(1, buildListOfHeight(5, suite.source)).List(context.Background())
sourceRef = suite.commitToSource(srcL, types.NewSet(context.Background(), suite.source, sourceRef))
preReads := suite.sinkCS.Reads
@@ -276,9 +276,9 @@ func (suite *PullSuite) TestPullUpdates() {
sourceRef := suite.commitToSource(srcL, types.NewSet(context.Background(), suite.source))
L3 := srcL.Get(context.Background(), 1).(types.Ref).TargetValue(context.Background(), suite.source).(types.List)
L2 := L3.Get(context.Background(), 1).(types.Ref).TargetValue(context.Background(), suite.source).(types.List)
L2 = L2.Edit().Append(suite.source.WriteValue(context.Background(), types.String("oy!"))).List(context.Background())
L3 = L3.Edit().Set(1, suite.source.WriteValue(context.Background(), L2)).List(context.Background())
srcL = srcL.Edit().Set(1, suite.source.WriteValue(context.Background(), L3)).List(context.Background())
L2 = L2.Edit(types.Format_7_18).Append(suite.source.WriteValue(context.Background(), types.String("oy!"))).List(context.Background())
L3 = L3.Edit(types.Format_7_18).Set(1, suite.source.WriteValue(context.Background(), L2)).List(context.Background())
srcL = srcL.Edit(types.Format_7_18).Set(1, suite.source.WriteValue(context.Background(), L3)).List(context.Background())
sourceRef = suite.commitToSource(srcL, types.NewSet(context.Background(), suite.source, sourceRef))
pt := startProgressTracker()
@@ -309,13 +309,13 @@ func (suite *PullSuite) commitToSink(v types.Value, p types.Set) types.Ref {
func buildListOfHeight(height int, vrw types.ValueReadWriter) types.List {
unique := 0
l := types.NewList(context.Background(), vrw, types.Float(unique), types.Float(unique+1))
l := types.NewList(context.Background(), types.Format_7_18, vrw, types.Float(unique), types.Float(unique+1))
unique += 2
for i := 0; i < height; i++ {
r1, r2 := vrw.WriteValue(context.Background(), types.Float(unique)), vrw.WriteValue(context.Background(), l)
unique++
l = types.NewList(context.Background(), vrw, r1, r2)
l = types.NewList(context.Background(), types.Format_7_18, vrw, r1, r2)
}
return l
}
+4 -4
View File
@@ -129,14 +129,14 @@ func (stack *patchStack) updateNode(ctx context.Context, top *stackElem, parent
switch top.changeType {
case types.DiffChangeAdded:
if realIdx > el.Len() {
nv = el.Edit().Append(top.newValue).List(ctx)
nv = el.Edit(types.Format_7_18).Append(top.newValue).List(ctx)
} else {
nv = el.Edit().Insert(realIdx, top.newValue).List(ctx)
nv = el.Edit(types.Format_7_18).Insert(realIdx, top.newValue).List(ctx)
}
case types.DiffChangeRemoved:
nv = el.Edit().RemoveAt(realIdx).List(ctx)
nv = el.Edit(types.Format_7_18).RemoveAt(realIdx).List(ctx)
case types.DiffChangeModified:
nv = el.Edit().Set(realIdx, top.newValue).List(ctx)
nv = el.Edit(types.Format_7_18).Set(realIdx, top.newValue).List(ctx)
}
return nv
case types.Map:
+3 -3
View File
@@ -169,8 +169,8 @@ func TestNestedLists(t *testing.T) {
ol2 := mustMarshal([]int{2, 3})
nl2 := mustMarshal([]int{1, 2, 3, 4})
nl3 := mustMarshal([]bool{true, false, true})
g1 := types.NewList(context.Background(), vs, ol1, ol2)
g2 := types.NewList(context.Background(), vs, nl1, nl2, nl3)
g1 := types.NewList(context.Background(), types.Format_7_18, vs, ol1, ol2)
g2 := types.NewList(context.Background(), types.Format_7_18, vs, nl1, nl2, nl3)
checkApplyPatch(assert, g1, g2, "g1", "g2")
}
@@ -198,7 +198,7 @@ func TestUpdateNode(t *testing.T) {
return parent.(types.Struct).Get("f2")
})
l1 := types.NewList(context.Background(), vs, types.String("one"), oldVal, types.String("three"))
l1 := types.NewList(context.Background(), types.Format_7_18, vs, types.String("one"), oldVal, types.String("three"))
pp = types.IndexPath{Index: types.Float(1)}
doTest(pp, l1, oldVal, newVal, newVal, func(parent types.Value) types.Value {
return parent.(types.List).Get(context.Background(), 1)
+1 -1
View File
@@ -68,7 +68,7 @@ func createList(kv ...interface{}) types.List {
vs := newTestValueStore()
defer vs.Close()
keyValues := valsToTypesValues(kv...)
return types.NewList(context.Background(), vs, keyValues...)
return types.NewList(context.Background(), types.Format_7_18, vs, keyValues...)
}
func createStruct(name string, kv ...interface{}) types.Struct {
+48 -24
View File
@@ -118,7 +118,8 @@ func TestDecode(tt *testing.T) {
}
var list types.List
list2 := types.NewList(context.Background(), vs, types.Float(42))
// TODO(binformat)
list2 := types.NewList(context.Background(), types.Format_7_18, vs, types.Float(42))
t(list2, &list, list2)
var m types.Map
@@ -233,13 +234,15 @@ func TestDecodeStructWithNomsValue(t *testing.T) {
"b": types.Bool(false),
"c": types.String("bye"),
}),
"def": types.NewList(context.Background(), vs, types.Float(42)),
// TODO(binformat)
"def": types.NewList(context.Background(), types.Format_7_18, vs, types.Float(42)),
})
var t2 T2
MustUnmarshal(context.Background(), v, &t2)
assert.IsType(t, T2{}, t2)
assert.Equal(t, TestStruct{false, 1, "bye"}, t2.Abc)
assert.True(t, t2.Def.Equals(types.NewList(context.Background(), vs, types.Float(42))))
// TODO(binformat)
assert.True(t, t2.Def.Equals(types.NewList(context.Background(), types.Format_7_18, vs, types.Float(42))))
}
func TestDecodeNilPointer(t *testing.T) {
@@ -271,7 +274,8 @@ func TestDecodeTypeMismatch(t *testing.T) {
assertDecodeErrorMessage(t, types.Float(42), &b, "Cannot unmarshal Float into Go value of type bool")
var blob types.Blob
assertDecodeErrorMessage(t, types.NewList(context.Background(), vs), &blob, "Cannot unmarshal List<> into Go value of type types.Blob")
// TODO(binformat)
assertDecodeErrorMessage(t, types.NewList(context.Background(), types.Format_7_18, vs), &blob, "Cannot unmarshal List<> into Go value of type types.Blob")
type S struct {
X int
@@ -573,7 +577,8 @@ func TestDecodeSlice(t *testing.T) {
var s []string
err := Unmarshal(context.Background(), types.NewList(context.Background(), vs, types.String("a"), types.String("b"), types.String("c")), &s)
// TODO(binformat)
err := Unmarshal(context.Background(), types.NewList(context.Background(), types.Format_7_18, vs, types.String("a"), types.String("b"), types.String("c")), &s)
assert.NoError(err)
assert.Equal([]string{"a", "b", "c"}, s)
@@ -590,7 +595,8 @@ func TestDecodeSliceEmpty(t *testing.T) {
var s []string
err := Unmarshal(context.Background(), types.NewList(context.Background(), vs), &s)
// TODO(binformat)
err := Unmarshal(context.Background(), types.NewList(context.Background(), types.Format_7_18, vs), &s)
assert.NoError(err)
assert.Equal([]string(nil), s)
@@ -599,7 +605,8 @@ func TestDecodeSliceEmpty(t *testing.T) {
assert.Equal([]string(nil), s)
s2 := []string{}
err = Unmarshal(context.Background(), types.NewList(context.Background(), vs), &s2)
// TODO(binformat)
err = Unmarshal(context.Background(), types.NewList(context.Background(), types.Format_7_18, vs), &s2)
assert.NoError(err)
assert.Equal([]string{}, s2)
@@ -616,11 +623,13 @@ func TestDecodeSliceReuse(t *testing.T) {
s := []string{"A", "B", "C", "D"}
s2 := s[1:3]
err := Unmarshal(context.Background(), types.NewList(context.Background(), vs, types.String("a"), types.String("b")), &s)
// TODO(binformat)
err := Unmarshal(context.Background(), types.NewList(context.Background(), types.Format_7_18, vs, types.String("a"), types.String("b")), &s)
assert.NoError(err)
assert.Equal([]string{"a", "b"}, s)
assert.Equal([]string{"b", "C"}, s2)
// TODO(binformat)
err = Unmarshal(context.Background(), types.NewSet(context.Background(), vs, types.String("a"), types.String("b")), &s)
assert.NoError(err)
assert.Equal([]string{"a", "b"}, s)
@@ -635,10 +644,12 @@ func TestDecodeArray(t *testing.T) {
s := [3]string{"", "", ""}
err := Unmarshal(context.Background(), types.NewList(context.Background(), vs, types.String("a"), types.String("b"), types.String("c")), &s)
// TODO(binformat)
err := Unmarshal(context.Background(), types.NewList(context.Background(), types.Format_7_18, vs, types.String("a"), types.String("b"), types.String("c")), &s)
assert.NoError(err)
assert.Equal([3]string{"a", "b", "c"}, s)
// TODO(binformat)
err = Unmarshal(context.Background(), types.NewSet(context.Background(), vs, types.String("a"), types.String("b"), types.String("c")), &s)
assert.NoError(err)
assert.Equal([3]string{"a", "b", "c"}, s)
@@ -652,7 +663,8 @@ func TestDecodeArrayEmpty(t *testing.T) {
var s [0]string
err := Unmarshal(context.Background(), types.NewList(context.Background(), vs), &s)
// TODO(binformat)
err := Unmarshal(context.Background(), types.NewList(context.Background(), types.Format_7_18, vs), &s)
assert.NoError(err)
assert.Equal([0]string{}, s)
@@ -672,7 +684,8 @@ func TestDecodeStructWithSlice(t *testing.T) {
}
var s S
err := Unmarshal(context.Background(), types.NewStruct("S", types.StructData{
"list": types.NewList(context.Background(), vs, types.Float(1), types.Float(2), types.Float(3)),
// TODO(binformat)
"list": types.NewList(context.Background(), types.Format_7_18, vs, types.Float(1), types.Float(2), types.Float(3)),
}), &s)
assert.NoError(err)
assert.Equal(S{[]int{1, 2, 3}}, s)
@@ -695,7 +708,8 @@ func TestDecodeStructWithArrayOfNomsValue(t *testing.T) {
}
var s S
err := Unmarshal(context.Background(), types.NewStruct("S", types.StructData{
"list": types.NewList(context.Background(), vs, types.NewSet(context.Background(), vs, types.Bool(true))),
// TODO(binformat)
"list": types.NewList(context.Background(), types.Format_7_18, vs, types.NewSet(context.Background(), vs, types.Bool(true))),
}), &s)
assert.NoError(err)
assert.Equal(S{[1]types.Set{types.NewSet(context.Background(), vs, types.Bool(true))}}, s)
@@ -706,7 +720,8 @@ func TestDecodeWrongArrayLength(t *testing.T) {
defer vs.Close()
var l [2]string
assertDecodeErrorMessage(t, types.NewList(context.Background(), vs, types.String("hi")), &l, "Cannot unmarshal List<String> into Go value of type [2]string, length does not match")
// TODO(binformat)
assertDecodeErrorMessage(t, types.NewList(context.Background(), types.Format_7_18, vs, types.String("hi")), &l, "Cannot unmarshal List<String> into Go value of type [2]string, length does not match")
}
func TestDecodeWrongArrayType(t *testing.T) {
@@ -714,7 +729,8 @@ func TestDecodeWrongArrayType(t *testing.T) {
defer vs.Close()
var l [1]string
assertDecodeErrorMessage(t, types.NewList(context.Background(), vs, types.Float(1)), &l, "Cannot unmarshal Float into Go value of type string")
// TODO(binformat)
assertDecodeErrorMessage(t, types.NewList(context.Background(), types.Format_7_18, vs, types.Float(1)), &l, "Cannot unmarshal Float into Go value of type string")
}
func TestDecodeWrongSliceType(t *testing.T) {
@@ -722,7 +738,8 @@ func TestDecodeWrongSliceType(t *testing.T) {
defer vs.Close()
var l []string
assertDecodeErrorMessage(t, types.NewList(context.Background(), vs, types.Float(1)), &l, "Cannot unmarshal Float into Go value of type string")
// TODO(binformat)
assertDecodeErrorMessage(t, types.NewList(context.Background(), types.Format_7_18, vs, types.Float(1)), &l, "Cannot unmarshal Float into Go value of type string")
}
func TestDecodeSliceWrongNomsType(t *testing.T) {
@@ -752,15 +769,17 @@ func TestDecodeRecursive(t *testing.T) {
Children []Node
}
// TODO(binformat)
v := types.NewStruct("Node", types.StructData{
"children": types.NewList(context.Background(),
types.Format_7_18,
vs,
types.NewStruct("Node", types.StructData{
"children": types.NewList(context.Background(), vs),
"children": types.NewList(context.Background(), types.Format_7_18, vs),
"value": types.Float(2),
}),
types.NewStruct("Node", types.StructData{
"children": types.NewList(context.Background(), vs),
"children": types.NewList(context.Background(), types.Format_7_18, vs),
"value": types.Float(3),
}),
),
@@ -840,7 +859,8 @@ func TestDecodeMapWrongNomsType(t *testing.T) {
defer vs.Close()
var m map[string]int
assertDecodeErrorMessage(t, types.NewList(context.Background(), vs, types.String("a"), types.Float(1)), &m, "Cannot unmarshal List<Float | String> into Go value of type map[string]int")
// TODO(binformat)
assertDecodeErrorMessage(t, types.NewList(context.Background(), types.Format_7_18, vs, types.String("a"), types.Float(1)), &m, "Cannot unmarshal List<Float | String> into Go value of type map[string]int")
}
func TestDecodeOntoInterface(t *testing.T) {
@@ -862,7 +882,8 @@ func TestDecodeOntoInterface(t *testing.T) {
assert.NoError(err)
assert.Equal(true, i)
err = Unmarshal(context.Background(), types.NewList(context.Background(), vs, types.String("abc")), &i)
// TODO(binformat)
err = Unmarshal(context.Background(), types.NewList(context.Background(), types.Format_7_18, vs, types.String("abc")), &i)
assert.NoError(err)
assert.Equal([]string{"abc"}, i)
@@ -870,11 +891,13 @@ func TestDecodeOntoInterface(t *testing.T) {
assert.NoError(err)
assert.Equal(map[string]float64{"abc": float64(1)}, i)
err = Unmarshal(context.Background(), types.NewList(context.Background(), vs, types.String("a"), types.Bool(true), types.Float(42)), &i)
// TODO(binformat)
err = Unmarshal(context.Background(), types.NewList(context.Background(), types.Format_7_18, vs, types.String("a"), types.Bool(true), types.Float(42)), &i)
assert.NoError(err)
assert.Equal([]interface{}{"a", true, float64(42)}, i)
err = Unmarshal(context.Background(), types.NewMap(context.Background(), vs, types.String("a"), types.Bool(true), types.Float(42), types.NewList(context.Background(), vs)), &i)
// TODO(binformat)
err = Unmarshal(context.Background(), types.NewMap(context.Background(), vs, types.String("a"), types.Bool(true), types.Float(42), types.NewList(context.Background(), types.Format_7_18, vs)), &i)
assert.NoError(err)
assert.Equal(map[interface{}]interface{}{"a": true, float64(42): []interface{}(nil)}, i)
}
@@ -909,6 +932,7 @@ func TestDecodeSet(t *testing.T) {
G []int
}
// TODO(binformat)
ns := types.NewStruct("T", types.StructData{
"a": types.NewSet(context.Background(), vs, types.Float(0), types.Float(1), types.Float(2)),
"b": types.NewMap(context.Background(), vs, types.Float(3), types.EmptyStruct, types.Float(4), types.EmptyStruct, types.Float(5), types.EmptyStruct),
@@ -916,7 +940,7 @@ func TestDecodeSet(t *testing.T) {
"d": types.NewMap(context.Background(), vs, types.String("3"), types.EmptyStruct, types.String("4"), types.EmptyStruct, types.String("5"), types.EmptyStruct),
"e": types.NewSet(context.Background(), vs, types.Float(6), types.Float(7), types.Float(8)),
"f": types.NewSet(context.Background(), vs, types.Float(9), types.Float(10), types.Float(11)),
"g": types.NewList(context.Background(), vs, types.Float(12), types.Float(13), types.Float(14)),
"g": types.NewList(context.Background(), types.Format_7_18, vs, types.Float(12), types.Float(13), types.Float(14)),
})
gs := T{}
@@ -938,7 +962,7 @@ func TestDecodeSet(t *testing.T) {
"d": types.NewMap(context.Background(), vs),
"e": types.NewSet(context.Background(), vs),
"f": types.NewSet(context.Background(), vs),
"g": types.NewList(context.Background(), vs),
"g": types.NewList(context.Background(), types.Format_7_18, vs),
})
gs2 := T{
@@ -1258,7 +1282,7 @@ func TestUnmarshalerComplexStructType(t *testing.T) {
r := regexp.MustCompile(s)
v := types.NewStruct("TestComplexStructType", types.StructData{
"p": types.Float(43),
"ps": types.NewList(context.Background(), vs, types.Float(2), types.Float(3)),
"ps": types.NewList(context.Background(), types.Format_7_18, vs, types.Float(2), types.Float(3)),
"pm": types.NewMap(context.Background(), vs, types.String("x"), types.Float(101), types.String("y"), types.Float(102)),
"pslice": types.String("a,b,c"),
"pmap": types.NewSet(context.Background(), vs, types.String("c,123"), types.String("d,456")),
+2 -1
View File
@@ -541,7 +541,8 @@ func listEncoder(t reflect.Type, seenStructs map[string]reflect.Type) encoderFun
for i := 0; i < v.Len(); i++ {
values[i] = elemEncoder(ctx, v.Index(i), vrw)
}
return types.NewList(ctx, vrw, values...)
// TODO(binformat)
return types.NewList(ctx, types.Format_7_18, vrw, values...)
}
encoderCache.set(t, e)
+16 -15
View File
@@ -97,7 +97,7 @@ func TestEncode(tt *testing.T) {
t(types.String(s), s)
}
t(types.NewList(context.Background(), vs, types.Float(42)), types.NewList(context.Background(), vs, types.Float(42)))
t(types.NewList(context.Background(), types.Format_7_18, vs, types.Float(42)), types.NewList(context.Background(), types.Format_7_18, vs, types.Float(42)))
t(types.NewMap(context.Background(), vs, types.Float(42), types.String("hi")), types.NewMap(context.Background(), vs, types.Float(42), types.String("hi")))
t(types.NewSet(context.Background(), vs, types.String("bye")), types.NewSet(context.Background(), vs, types.String("bye")))
// TODO(binformat)
@@ -132,14 +132,14 @@ func TestEncode(tt *testing.T) {
C float64
}
t(types.NewStruct("TestNestedStruct", types.StructData{
"a": types.NewList(context.Background(), vs, types.String("hi")),
"a": types.NewList(context.Background(), types.Format_7_18, vs, types.String("hi")),
"b": types.NewStruct("TestStruct", types.StructData{
"str": types.String("bye"),
"num": types.Float(5678),
}),
"c": types.Float(1234),
}), TestNestedStruct{
A: types.NewList(context.Background(), vs, types.String("hi")),
A: types.NewList(context.Background(), types.Format_7_18, vs, types.String("hi")),
B: TestStruct{
Str: "bye",
Num: 5678,
@@ -421,7 +421,7 @@ func TestEncodeOmitEmpty(t *testing.T) {
v3, err := Marshal(context.Background(), vs, s3)
assert.NoError(err)
assert.True(types.NewStruct("S2", types.StructData{
"slice": types.NewList(context.Background(), vs, types.Float(0)),
"slice": types.NewList(context.Background(), types.Format_7_18, vs, types.Float(0)),
"map": types.NewMap(context.Background(), vs, types.Float(0), types.Float(0)),
}).Equals(v3))
@@ -446,13 +446,13 @@ func TestEncodeOmitEmpty(t *testing.T) {
Value types.Value `noms:",omitempty"`
}
s6 := S3{
List: types.NewList(context.Background(), vs),
List: types.NewList(context.Background(), types.Format_7_18, vs),
Value: types.Float(0),
}
v6, err := Marshal(context.Background(), vs, s6)
assert.NoError(err)
assert.True(types.NewStruct("S3", types.StructData{
"list": types.NewList(context.Background(), vs),
"list": types.NewList(context.Background(), types.Format_7_18, vs),
"value": types.Float(0),
}).Equals(v6))
@@ -511,7 +511,7 @@ func TestEncodeSlice(t *testing.T) {
v, err := Marshal(context.Background(), vs, []string{"a", "b", "c"})
assert.NoError(err)
assert.True(types.NewList(context.Background(), vs, types.String("a"), types.String("b"), types.String("c")).Equals(v))
assert.True(types.NewList(context.Background(), types.Format_7_18, vs, types.String("a"), types.String("b"), types.String("c")).Equals(v))
}
func TestEncodeArray(t *testing.T) {
@@ -522,7 +522,7 @@ func TestEncodeArray(t *testing.T) {
v, err := Marshal(context.Background(), vs, [3]int{1, 2, 3})
assert.NoError(err)
assert.True(types.NewList(context.Background(), vs, types.Float(1), types.Float(2), types.Float(3)).Equals(v))
assert.True(types.NewList(context.Background(), types.Format_7_18, vs, types.Float(1), types.Float(2), types.Float(3)).Equals(v))
}
func TestEncodeStructWithSlice(t *testing.T) {
@@ -537,7 +537,7 @@ func TestEncodeStructWithSlice(t *testing.T) {
v, err := Marshal(context.Background(), vs, S{[]int{1, 2, 3}})
assert.NoError(err)
assert.True(types.NewStruct("S", types.StructData{
"list": types.NewList(context.Background(), vs, types.Float(1), types.Float(2), types.Float(3)),
"list": types.NewList(context.Background(), types.Format_7_18, vs, types.Float(1), types.Float(2), types.Float(3)),
}).Equals(v))
}
@@ -553,7 +553,7 @@ func TestEncodeStructWithArrayOfNomsValue(t *testing.T) {
v, err := Marshal(context.Background(), vs, S{[1]types.Set{types.NewSet(context.Background(), vs, types.Bool(true))}})
assert.NoError(err)
assert.True(types.NewStruct("S", types.StructData{
"list": types.NewList(context.Background(), vs, types.NewSet(context.Background(), vs, types.Bool(true))),
"list": types.NewList(context.Background(), types.Format_7_18, vs, types.NewSet(context.Background(), vs, types.Bool(true))),
}).Equals(v))
}
@@ -617,13 +617,14 @@ func TestEncodeRecursive(t *testing.T) {
assert.True(types.NewStruct("Node", types.StructData{
"children": types.NewList(context.Background(),
types.Format_7_18,
vs,
types.NewStruct("Node", types.StructData{
"children": types.NewList(context.Background(), vs),
"children": types.NewList(context.Background(), types.Format_7_18, vs),
"value": types.Float(2),
}),
types.NewStruct("Node", types.StructData{
"children": types.NewList(context.Background(), vs),
"children": types.NewList(context.Background(), types.Format_7_18, vs),
"value": types.Float(3),
}),
),
@@ -673,7 +674,7 @@ func TestEncodeInterface(t *testing.T) {
var i interface{} = []string{"a", "b"}
v, err := Marshal(context.Background(), vs, i)
assert.NoError(err)
assert.True(types.NewList(context.Background(), vs, types.String("a"), types.String("b")).Equals(v))
assert.True(types.NewList(context.Background(), types.Format_7_18, vs, types.String("a"), types.String("b")).Equals(v))
i = map[interface{}]interface{}{"a": true, struct{ Name string }{"b"}: 42}
v, err = Marshal(context.Background(), vs, i)
@@ -771,7 +772,7 @@ func TestEncodeOpt(t *testing.T) {
{
[]string{"a", "b"},
Opt{},
types.NewList(context.Background(), vs, types.String("a"), types.String("b")),
types.NewList(context.Background(), types.Format_7_18, vs, types.String("a"), types.String("b")),
},
{
[]string{"a", "b"},
@@ -1105,7 +1106,7 @@ func TestMarshalerComplexStructType(t *testing.T) {
assert.True(types.NewStruct("TestComplexStructType", types.StructData{
"p": types.Float(43),
"ps": types.NewList(context.Background(), vs, types.Float(2), types.Float(3)),
"ps": types.NewList(context.Background(), types.Format_7_18, vs, types.Float(2), types.Float(3)),
"pm": types.NewMap(context.Background(), vs, types.String("x"), types.Float(101), types.String("y"), types.Float(102)),
"pslice": types.String("a,b,c"),
"pmap": types.NewSet(context.Background(), vs, types.String("c,123"), types.String("d,456")),
+1 -1
View File
@@ -281,7 +281,7 @@ func listAssert(ctx context.Context, vrw types.ValueReadWriter, a, b, parent typ
if parent != nil {
pList, pOk = parent.(types.List)
} else {
pList, pOk = types.NewList(ctx, vrw), true
pList, pOk = types.NewList(ctx, types.Format_7_18, vrw), true
}
return aList, bList, pList, aOk && bOk && pOk
}
+1 -1
View File
@@ -121,7 +121,7 @@ func apply(ctx context.Context, source, target types.List, offset uint64, s type
}
toAdd[i] = v
}
return target.Edit().Splice(s.SpAt+offset, s.SpRemoved, toAdd...).List(ctx)
return target.Edit(types.Format_7_18).Splice(s.SpAt+offset, s.SpRemoved, toAdd...).List(ctx)
}
func describeSplice(s types.Splice) string {
+1 -1
View File
@@ -24,7 +24,7 @@ func (s *ThreeWayListMergeSuite) SetupSuite() {
s.create = func(i seq) (val types.Value) {
if i != nil {
items := valsToTypesValues(s.create, i.items()...)
val = types.NewList(context.Background(), s.vs, items...)
val = types.NewList(context.Background(), types.Format_7_18, s.vs, items...)
}
return
}
+2 -1
View File
@@ -368,7 +368,8 @@ func (p *Parser) parseFloat() types.Float {
func (p *Parser) parseList(ctx context.Context) types.List {
// already swallowed '['
le := types.NewList(ctx, p.vrw).Edit()
// TODO(binformat)
le := types.NewList(ctx, types.Format_7_18, p.vrw).Edit(types.Format_7_18)
for p.lex.peek() != ']' {
v := p.parseValue(ctx)
+10 -7
View File
@@ -271,10 +271,11 @@ func TestValuePrimitives(t *testing.T) {
func TestValueList(t *testing.T) {
vs := newTestValueStore()
assertParse(t, vs, "[]", types.NewList(context.Background(), vs))
// TODO(binformat)
assertParse(t, vs, "[]", types.NewList(context.Background(), types.Format_7_18, vs))
assertParse(t, vs, "[42]", types.NewList(context.Background(), vs, types.Float(42)))
assertParse(t, vs, "[42,]", types.NewList(context.Background(), vs, types.Float(42)))
assertParse(t, vs, "[42]", types.NewList(context.Background(), types.Format_7_18, vs, types.Float(42)))
assertParse(t, vs, "[42,]", types.NewList(context.Background(), types.Format_7_18, vs, types.Float(42)))
assertParseError(t, "[", "Unexpected token EOF, example:1:2")
assertParseError(t, "[,", "Unexpected token \",\", example:1:3")
@@ -282,12 +283,13 @@ func TestValueList(t *testing.T) {
assertParseError(t, "[42,", "Unexpected token EOF, example:1:5")
assertParseError(t, "[,]", "Unexpected token \",\", example:1:3")
// TODO(binformat)
assertParse(t, vs, `[42,
Bool,
]`, types.NewList(context.Background(), vs, types.Float(42), types.BoolType))
]`, types.NewList(context.Background(), types.Format_7_18, vs, types.Float(42), types.BoolType))
assertParse(t, vs, `[42,
Bool
]`, types.NewList(context.Background(), vs, types.Float(42), types.BoolType))
]`, types.NewList(context.Background(), types.Format_7_18, vs, types.Float(42), types.BoolType))
}
func TestValueSet(t *testing.T) {
@@ -438,8 +440,9 @@ func TestRoundTrips(t *testing.T) {
test(types.NewEmptyBlob(vs, types.Format_7_18))
test(types.NewBlob(context.Background(), types.Format_7_18, vs, bytes.NewBufferString("abc")))
test(types.NewList(context.Background(), vs))
test(types.NewList(context.Background(), vs, types.Float(42), types.Bool(true), types.String("abc")))
// TODO(binformat)
test(types.NewList(context.Background(), types.Format_7_18, vs))
test(types.NewList(context.Background(), types.Format_7_18, vs, types.Float(42), types.Bool(true), types.String("abc")))
test(types.NewSet(context.Background(), vs))
test(types.NewSet(context.Background(), vs, types.Float(42), types.Bool(true), types.String("abc")))
+2 -2
View File
@@ -154,11 +154,11 @@ func buildList(vrw types.ValueReadWriter, count uint64, createFn createValueFn)
values[i] = createFn(i)
}
return types.NewList(context.Background(), vrw, values...)
return types.NewList(context.Background(), types.Format_7_18, vrw, values...)
}
func buildListIncrementally(vrw types.ValueReadWriter, count uint64, createFn createValueFn) types.Collection {
l := types.NewList(context.Background(), vrw).Edit()
l := types.NewList(context.Background(), types.Format_7_18, vrw).Edit(types.Format_7_18)
for i := uint64(0); i < count; i++ {
l.Append(createFn(i))
}
+3 -1
View File
@@ -87,6 +87,8 @@ import (
"testing"
"time"
"github.com/google/uuid"
"github.com/liquidata-inc/ld/dolt/go/store/chunks"
"github.com/liquidata-inc/ld/dolt/go/store/datas"
"github.com/liquidata-inc/ld/dolt/go/store/marshal"
@@ -255,7 +257,7 @@ func Run(datasetID string, t *testing.T, suiteT perfSuiteT) {
"environment": suite.getEnvironment(db),
"nomsRevision": types.String(suite.getGitHead(path.Join(suite.AtticLabs, "noms"))),
"testdataRevision": types.String(suite.getGitHead(suite.Testdata)),
"reps": types.NewList(context.Background(), db, reps...),
"reps": types.NewList(context.Background(), types.Format_7_18, db, reps...),
})
ds := db.GetDataset(context.Background(), *perfPrefixFlag+datasetID)
+2 -2
View File
@@ -38,7 +38,7 @@ func TestAbsolutePaths(t *testing.T) {
db := datas.NewDatabase(storage.NewView())
s0, s1 := types.String("foo"), types.String("bar")
list := types.NewList(context.Background(), db, s0, s1)
list := types.NewList(context.Background(), types.Format_7_18, db, s0, s1)
emptySet := types.NewSet(context.Background(), db)
db.WriteValue(context.Background(), s0)
@@ -91,7 +91,7 @@ func TestReadAbsolutePaths(t *testing.T) {
db := datas.NewDatabase(storage.NewView())
s0, s1 := types.String("foo"), types.String("bar")
list := types.NewList(context.Background(), db, s0, s1)
list := types.NewList(context.Background(), types.Format_7_18, db, s0, s1)
ds := db.GetDataset(context.Background(), "ds")
_, err := db.CommitValue(context.Background(), ds, list)
+1 -1
View File
@@ -96,7 +96,7 @@ func TestMemDatasetPathSpec(t *testing.T) {
db := spec.GetDatabase(context.Background())
ds := db.GetDataset(context.Background(), "test")
_, err = db.CommitValue(context.Background(), ds, types.NewList(context.Background(), db, types.Float(42)))
_, err = db.CommitValue(context.Background(), ds, types.NewList(context.Background(), types.Format_7_18, db, types.Float(42)))
assert.NoError(err)
assert.Equal(types.Float(42), spec.GetValue(context.Background()))
+1 -1
View File
@@ -305,7 +305,7 @@ func TestCompareDifferentPrimitiveTypes(t *testing.T) {
// TODO(binformat)
blob := NewBlob(context.Background(), Format_7_18, vrw, bytes.NewBuffer([]byte{1, 2, 3}))
nList := NewList(context.Background(), vrw, nums...)
nList := NewList(context.Background(), Format_7_18, vrw, nums...)
nMap := NewMap(context.Background(), vrw, words...)
nRef := NewRef(blob)
nSet := NewSet(context.Background(), vrw, nums...)
+16 -9
View File
@@ -63,7 +63,8 @@ func TestWriteHumanReadableRef(t *testing.T) {
func TestWriteHumanReadableCollections(t *testing.T) {
vrw := newTestValueStore()
l := NewList(context.Background(), vrw, Float(0), Float(1), Float(2), Float(3))
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, vrw, Float(0), Float(1), Float(2), Float(3))
assertWriteHRSEqual(t, "[ // 4 items\n 0,\n 1,\n 2,\n 3,\n]", l)
s := NewSet(context.Background(), vrw, Float(0), Float(1), Float(2), Float(3))
@@ -72,25 +73,29 @@ func TestWriteHumanReadableCollections(t *testing.T) {
m := NewMap(context.Background(), vrw, Float(0), Bool(false), Float(1), Bool(true))
assertWriteHRSEqual(t, "map {\n 0: false,\n 1: true,\n}", m)
l2 := NewList(context.Background(), vrw)
// TODO(binformat)
l2 := NewList(context.Background(), Format_7_18, vrw)
assertWriteHRSEqual(t, "[]", l2)
l3 := NewList(context.Background(), vrw, Float(0))
// TODO(binformat)
l3 := NewList(context.Background(), Format_7_18, vrw, Float(0))
assertWriteHRSEqual(t, "[\n 0,\n]", l3)
nums := make([]Value, 2000)
for i := range nums {
nums[i] = Float(0)
}
l4 := NewList(context.Background(), vrw, nums...)
// TODO(binformat)
l4 := NewList(context.Background(), Format_7_18, vrw, nums...)
assertWriteHRSEqual(t, "[ // 2,000 items\n"+strings.Repeat(" 0,\n", 2000)+"]", l4)
}
func TestWriteHumanReadableNested(t *testing.T) {
vrw := newTestValueStore()
l := NewList(context.Background(), vrw, Float(0), Float(1))
l2 := NewList(context.Background(), vrw, Float(2), Float(3))
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, vrw, Float(0), Float(1))
l2 := NewList(context.Background(), Format_7_18, vrw, Float(2), Float(3))
s := NewSet(context.Background(), vrw, String("a"), String("b"))
s2 := NewSet(context.Background(), vrw, String("c"), String("d"))
@@ -134,7 +139,8 @@ func TestWriteHumanReadableListOfStruct(t *testing.T) {
str3 := NewStruct("S3", StructData{
"x": Float(3),
})
l := NewList(context.Background(), vrw, str1, str2, str3)
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, vrw, str1, str2, str3)
assertWriteHRSEqual(t, `[
struct S3 {
x: 1,
@@ -204,7 +210,7 @@ func TestWriteHumanReadableListOfBlob(t *testing.T) {
0x10,
}))
// TODO(binformat)
l := NewList(context.Background(), vrw, b1, NewEmptyBlob(vrw, Format_7_18), b2, b3)
l := NewList(context.Background(), Format_7_18, vrw, b1, NewEmptyBlob(vrw, Format_7_18), b2, b3)
assertWriteHRSEqual(t, "[ // 4 items\n blob {01},\n blob {},\n blob {02},\n blob { // 17 B\n 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n 10\n },\n]", l)
}
@@ -323,7 +329,8 @@ func TestEncodedValueMaxLines(t *testing.T) {
assert := assert.New(t)
vrw := newTestValueStore()
l1 := NewList(context.Background(), vrw, generateNumbersAsValues(11)...)
// TODO(binformat)
l1 := NewList(context.Background(), Format_7_18, vrw, generateNumbersAsValues(11)...)
expected := strings.Join(strings.SplitAfterN(EncodedValue(context.Background(), l1), "\n", 6)[:5], "")
assert.Equal(expected, EncodedValueMaxLines(context.Background(), l1, 5))
+22 -10
View File
@@ -214,7 +214,8 @@ func TestWriteList(t *testing.T) {
[]interface{}{
ListKind, uint64(0), uint64(4) /* len */, FloatKind, Float(0), FloatKind, Float(1), FloatKind, Float(2), FloatKind, Float(3),
},
NewList(context.Background(), vrw, Float(0), Float(1), Float(2), Float(3)),
// TODO(binformat)
NewList(context.Background(), Format_7_18, vrw, Float(0), Float(1), Float(2), Float(3)),
)
}
func TestWriteTuple(t *testing.T) {
@@ -237,7 +238,10 @@ func TestWriteListOfList(t *testing.T) {
ListKind, uint64(0), uint64(1) /* len */, FloatKind, Float(0),
ListKind, uint64(0), uint64(3) /* len */, FloatKind, Float(1), FloatKind, Float(2), FloatKind, Float(3),
},
NewList(context.Background(), vrw, NewList(context.Background(), vrw, Float(0)), NewList(context.Background(), vrw, Float(1), Float(2), Float(3))),
// TODO(binformat)
NewList(context.Background(), Format_7_18, vrw,
NewList(context.Background(), Format_7_18, vrw, Float(0)),
NewList(context.Background(), Format_7_18, vrw, Float(1), Float(2), Float(3))),
)
}
@@ -365,7 +369,8 @@ func TestWriteStructWithList(t *testing.T) {
StructKind, "S", uint64(1), /* len */
"l", ListKind, uint64(0), uint64(2) /* len */, StringKind, "a", StringKind, "b",
},
NewStruct("S", StructData{"l": NewList(context.Background(), vrw, String("a"), String("b"))}),
// TODO(binformat)
NewStruct("S", StructData{"l": NewList(context.Background(), Format_7_18, vrw, String("a"), String("b"))}),
)
// struct S {l: List<>}({l: []})
@@ -374,7 +379,8 @@ func TestWriteStructWithList(t *testing.T) {
StructKind, "S", uint64(1), /* len */
"l", ListKind, uint64(0), uint64(0), /* len */
},
NewStruct("S", StructData{"l": NewList(context.Background(), vrw)}),
// TODO(binformat)
NewStruct("S", StructData{"l": NewList(context.Background(), Format_7_18, vrw)}),
)
}
@@ -509,7 +515,8 @@ func TestWriteListOfUnion(t *testing.T) {
ListKind, uint64(0),
uint64(4) /* len */, StringKind, "0", FloatKind, Float(1), StringKind, "2", BoolKind, true,
},
NewList(context.Background(), vrw,
// TODO(binformat)
NewList(context.Background(), Format_7_18, vrw,
String("0"),
Float(1),
String("2"),
@@ -526,7 +533,8 @@ func TestWriteListOfStruct(t *testing.T) {
ListKind, uint64(0), uint64(1), /* len */
StructKind, "S", uint64(1) /* len */, "x", FloatKind, Float(42),
},
NewList(context.Background(), vrw, NewStruct("S", StructData{"x": Float(42)})),
// TODO(binformat)
NewList(context.Background(), Format_7_18, vrw, NewStruct("S", StructData{"x": Float(42)})),
)
}
@@ -543,7 +551,8 @@ func TestWriteListOfUnionWithType(t *testing.T) {
TypeKind, TypeKind,
TypeKind, StructKind, "S", uint64(1) /* len */, "x", FloatKind, false,
},
NewList(context.Background(), vrw,
// TODO(binformat)
NewList(context.Background(), Format_7_18, vrw,
Bool(true),
FloaTType,
TypeType,
@@ -571,7 +580,8 @@ func TestWriteListOfTypes(t *testing.T) {
ListKind, uint64(0), uint64(2), /* len */
TypeKind, BoolKind, TypeKind, StringKind,
},
NewList(context.Background(), vrw, BoolType, StringType),
// TODO(binformat)
NewList(context.Background(), Format_7_18, vrw, BoolType, StringType),
)
}
@@ -583,7 +593,8 @@ func TestWriteUnionList(t *testing.T) {
ListKind, uint64(0), uint64(3), /* len */
FloatKind, Float(23), StringKind, "hi", FloatKind, Float(42),
},
NewList(context.Background(), vrw, Float(23), String("hi"), Float(42)),
// TODO(binformat)
NewList(context.Background(), Format_7_18, vrw, Float(23), String("hi"), Float(42)),
)
}
@@ -594,7 +605,8 @@ func TestWriteEmptyUnionList(t *testing.T) {
[]interface{}{
ListKind, uint64(0), uint64(0), /* len */
},
NewList(context.Background(), vrw),
// TODO(binformat)
NewList(context.Background(), Format_7_18, vrw),
)
}
+4 -3
View File
@@ -46,9 +46,10 @@ func TestValueEquals(t *testing.T) {
newMetaTuple(NewRef(b2), orderedKeyFromInt(5), 5),
}, nil))
},
func() Value { return NewList(context.Background(), vrw) },
func() Value { return NewList(context.Background(), vrw, String("foo")) },
func() Value { return NewList(context.Background(), vrw, String("bar")) },
// TODO(binformat)
func() Value { return NewList(context.Background(), Format_7_18, vrw) },
func() Value { return NewList(context.Background(), Format_7_18, vrw, String("foo")) },
func() Value { return NewList(context.Background(), Format_7_18, vrw, String("bar")) },
func() Value { return NewMap(context.Background(), vrw) },
func() Value { return NewMap(context.Background(), vrw, String("a"), String("a")) },
func() Value { return NewSet(context.Background(), vrw) },
+6 -3
View File
@@ -22,7 +22,8 @@ func getTestVals(vrw ValueReadWriter) []Value {
NewBlob(context.Background(), Format_7_18, vrw, bytes.NewReader([]byte("hi"))),
// compoundBlob
NewSet(context.Background(), vrw, String("hi")),
NewList(context.Background(), vrw, String("hi")),
// TODO(binformat)
NewList(context.Background(), Format_7_18, vrw, String("hi")),
NewMap(context.Background(), vrw, String("hi"), String("hi")),
}
}
@@ -41,7 +42,8 @@ func TestIncrementalLoadList(t *testing.T) {
cs := ts.NewView()
vs := NewValueStore(cs)
expected := NewList(context.Background(), vs, getTestVals(vs)...)
// TODO(binformat)
expected := NewList(context.Background(), Format_7_18, vs, getTestVals(vs)...)
hash := vs.WriteValue(context.Background(), expected).TargetHash()
vs.Commit(context.Background(), vs.Root(context.Background()), vs.Root(context.Background()))
@@ -117,7 +119,8 @@ func SkipTestIncrementalAddRef(t *testing.T) {
expectedItem := Float(42)
ref := vs.WriteValue(context.Background(), expectedItem)
expected := NewList(context.Background(), vs, ref)
// TODO(binformat)
expected := NewList(context.Background(), Format_7_18, vs, ref)
ref = vs.WriteValue(context.Background(), expected)
actualVar := vs.ReadValue(context.Background(), ref.TargetHash())
+22 -24
View File
@@ -32,8 +32,8 @@ func newList(seq sequence) List {
// NewList creates a new List where the type is computed from the elements in the list, populated
// with values, chunking if and when needed.
func NewList(ctx context.Context, vrw ValueReadWriter, values ...Value) List {
ch := newEmptyListSequenceChunker(ctx, vrw)
func NewList(ctx context.Context, f *Format, vrw ValueReadWriter, values ...Value) List {
ch := newEmptyListSequenceChunker(ctx, f, vrw)
for _, v := range values {
ch.Append(ctx, v)
}
@@ -43,11 +43,11 @@ func NewList(ctx context.Context, vrw ValueReadWriter, values ...Value) List {
// NewStreamingList creates a new List, populated with values, chunking if and when needed. As
// chunks are created, they're written to vrw -- including the root chunk of the list. Once the
// caller has closed values, the caller can read the completed List from the returned channel.
func NewStreamingList(ctx context.Context, vrw ValueReadWriter, values <-chan Value) <-chan List {
func NewStreamingList(ctx context.Context, f *Format, vrw ValueReadWriter, values <-chan Value) <-chan List {
out := make(chan List, 1)
go func() {
defer close(out)
ch := newEmptyListSequenceChunker(ctx, vrw)
ch := newEmptyListSequenceChunker(ctx, f, vrw)
for v := range values {
ch.Append(ctx, v)
}
@@ -56,8 +56,8 @@ func NewStreamingList(ctx context.Context, vrw ValueReadWriter, values <-chan Va
return out
}
func (l List) Edit() *ListEditor {
return NewListEditor(l)
func (l List) Edit(f *Format) *ListEditor {
return NewListEditor(l, f)
}
// Collection interface
@@ -72,7 +72,8 @@ func (l List) Value(ctx context.Context) Value {
}
func (l List) WalkValues(ctx context.Context, cb ValueCallback) {
iterAll(ctx, l, func(v Value, idx uint64) {
// TODO(binformat)
iterAll(ctx, Format_7_18, l, func(v Value, idx uint64) {
cb(v)
})
}
@@ -88,9 +89,9 @@ func (l List) Get(ctx context.Context, idx uint64) Value {
// Concat returns a new List comprised of this joined with other. It only needs
// to visit the rightmost prolly tree chunks of this List, and the leftmost
// prolly tree chunks of other, so it's efficient.
func (l List) Concat(ctx context.Context, other List) List {
func (l List) Concat(ctx context.Context, f *Format, other List) List {
seq := concat(ctx, l.sequence, other.sequence, func(cur *sequenceCursor, vrw ValueReadWriter) *sequenceChunker {
return l.newChunker(ctx, cur, vrw)
return l.newChunker(ctx, f, cur, vrw)
})
return newList(seq)
}
@@ -109,23 +110,23 @@ func (l List) Iter(ctx context.Context, f func(v Value, index uint64) (stop bool
})
}
func (l List) IterRange(ctx context.Context, startIdx, endIdx uint64, f func(v Value, idx uint64)) {
func (l List) IterRange(ctx context.Context, format *Format, startIdx, endIdx uint64, f func(v Value, idx uint64)) {
idx := uint64(startIdx)
cb := func(v Value) {
f(v, idx)
idx++
}
// TODO(binformat)
iterRange(ctx, Format_7_18, l, startIdx, endIdx, cb)
iterRange(ctx, format, l, startIdx, endIdx, cb)
}
// IterAll iterates over the list and calls f for every element in the list. Unlike Iter there is no
// way to stop the iteration and all elements are visited.
func (l List) IterAll(ctx context.Context, f func(v Value, index uint64)) {
iterAll(ctx, l, f)
// TODO(binformat)
iterAll(ctx, Format_7_18, l, f)
}
func iterAll(ctx context.Context, col Collection, f func(v Value, index uint64)) {
func iterAll(ctx context.Context, format *Format, col Collection, f func(v Value, index uint64)) {
concurrency := 6
vcChan := make(chan chan Value, concurrency)
@@ -149,8 +150,7 @@ func iterAll(ctx context.Context, col Collection, f func(v Value, index uint64))
vcChan <- vc
go func() {
// TODO(binformat)
numBytes := iterRange(ctx, Format_7_18, col, start, start+blockLength, func(v Value) {
numBytes := iterRange(ctx, format, col, start, start+blockLength, func(v Value) {
vc <- v
})
close(vc)
@@ -207,7 +207,6 @@ func iterRange(ctx context.Context, f *Format, col Collection, startIdx, endIdx
endIdx = endIdx - uint64(len(values))/valuesPerIdx - startIdx
startIdx = 0
// TODO(binformat)
numBytes += uint64(len(seq.valueBytes(f))) // note: should really only include |values|
}
return
@@ -254,11 +253,11 @@ func (l List) DiffWithLimit(ctx context.Context, last List, changes chan<- Splic
indexedSequenceDiff(ctx, Format_7_18, last.sequence, 0, l.sequence, 0, changes, closeChan, maxSpliceMatrixSize)
}
func (l List) newChunker(ctx context.Context, cur *sequenceCursor, vrw ValueReadWriter) *sequenceChunker {
return newSequenceChunker(ctx, cur, 0, vrw, makeListLeafChunkFn(vrw), newIndexedMetaSequenceChunkFn(ListKind, vrw), hashValueBytes)
func (l List) newChunker(ctx context.Context, f *Format, cur *sequenceCursor, vrw ValueReadWriter) *sequenceChunker {
return newSequenceChunker(ctx, cur, 0, vrw, makeListLeafChunkFn(vrw, f), newIndexedMetaSequenceChunkFn(ListKind, vrw), hashValueBytes)
}
func makeListLeafChunkFn(vrw ValueReadWriter) makeChunkFn {
func makeListLeafChunkFn(vrw ValueReadWriter, f *Format) makeChunkFn {
return func(level uint64, items []sequenceItem) (Collection, orderedKey, uint64) {
d.PanicIfFalse(level == 0)
values := make([]Value, len(items))
@@ -267,12 +266,11 @@ func makeListLeafChunkFn(vrw ValueReadWriter) makeChunkFn {
values[i] = v.(Value)
}
// TODO(binformat)
list := newList(newListLeafSequence(vrw, Format_7_18, values...))
list := newList(newListLeafSequence(vrw, f, values...))
return list, orderedKeyFromInt(len(values)), uint64(len(values))
}
}
func newEmptyListSequenceChunker(ctx context.Context, vrw ValueReadWriter) *sequenceChunker {
return newEmptySequenceChunker(ctx, vrw, makeListLeafChunkFn(vrw), newIndexedMetaSequenceChunkFn(ListKind, vrw), hashValueBytes)
func newEmptyListSequenceChunker(ctx context.Context, f *Format, vrw ValueReadWriter) *sequenceChunker {
return newEmptySequenceChunker(ctx, vrw, makeListLeafChunkFn(vrw, f), newIndexedMetaSequenceChunkFn(ListKind, vrw), hashValueBytes)
}
+4 -3
View File
@@ -13,11 +13,12 @@ import (
type ListEditor struct {
l List
f *Format
edits *listEdit
}
func NewListEditor(l List) *ListEditor {
return &ListEditor{l, nil}
func NewListEditor(l List, f *Format) *ListEditor {
return &ListEditor{l, f, nil}
}
func (le *ListEditor) Kind() NomsKind {
@@ -90,7 +91,7 @@ func (le *ListEditor) List(ctx context.Context) List {
sp := <-<-spliceChan
if ch == nil {
ch = newSequenceChunker(ctx, cur, 0, vrw, makeListLeafChunkFn(vrw), newIndexedMetaSequenceChunkFn(ListKind, vrw), hashValueBytes)
ch = newSequenceChunker(ctx, cur, 0, vrw, makeListLeafChunkFn(vrw, le.f), newIndexedMetaSequenceChunkFn(ListKind, vrw), hashValueBytes)
} else {
ch.advanceTo(ctx, cur)
}
+6 -3
View File
@@ -17,11 +17,13 @@ func listOfInts(vrw ValueReadWriter, vals ...int) List {
for _, v := range vals {
vs = append(vs, Float(v))
}
return NewList(context.Background(), vrw, vs...)
// TODO(binformat)
return NewList(context.Background(), Format_7_18, vrw, vs...)
}
func testEditor(vrw ValueReadWriter, vals ...int) *ListEditor {
return NewListEditor(listOfInts(vrw, vals...))
// TODO(binformat)
return NewListEditor(listOfInts(vrw, vals...), Format_7_18)
}
func edit(le *ListEditor, idx, remove int, insert ...int) {
@@ -220,7 +222,8 @@ func TestListSpliceFuzzer(t *testing.T) {
for i := 0; i < rounds; i++ {
tl := newTestList(startCount)
le := tl.toList(vrw).Edit()
// TODO(binformat)
le := tl.toList(vrw).Edit(Format_7_18)
for j := 0; j < splices; j++ {
idx, removed, insert := nextRandomSplice(len(tl))
+2 -1
View File
@@ -16,7 +16,8 @@ func TestListIterator(t *testing.T) {
vrw := newTestValueStore()
numbers := append(generateNumbersAsValues(10), Float(20), Float(25))
l := NewList(context.Background(), vrw, numbers...)
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, vrw, numbers...)
i := l.Iterator(context.Background())
vs := iterToSlice(i)
assert.True(vs.Equals(numbers), "Expected: %v != actual: %v", numbers, vs)
+147 -95
View File
@@ -57,7 +57,8 @@ func (tl testList) Diff(last testList) []Splice {
}
func (tl testList) toList(vrw ValueReadWriter) List {
return NewList(context.Background(), vrw, tl...)
// TODO(binformat)
return NewList(context.Background(), Format_7_18, vrw, tl...)
}
func newTestList(length int) testList {
@@ -65,7 +66,8 @@ func newTestList(length int) testList {
}
func validateList(t *testing.T, vrw ValueReadWriter, l List, values ValueSlice) {
assert.True(t, l.Equals(NewList(context.Background(), vrw, values...)))
// TODO(binformat)
assert.True(t, l.Equals(NewList(context.Background(), Format_7_18, vrw, values...)))
out := ValueSlice{}
l.IterAll(context.Background(), func(v Value, idx uint64) {
out = append(out, v)
@@ -84,7 +86,8 @@ func newListTestSuite(size uint, expectChunkCount int, expectPrependChunkDiff in
length := 1 << size
elems := newTestList(length)
tr := MakeListType(FloaTType)
list := NewList(context.Background(), vrw, elems...)
// TODO(binformat)
list := NewList(context.Background(), Format_7_18, vrw, elems...)
return &listTestSuite{
collectionTestSuite: collectionTestSuite{
col: list,
@@ -105,13 +108,15 @@ func newListTestSuite(size uint, expectChunkCount int, expectPrependChunkDiff in
dup := make([]Value, length+1)
dup[0] = Float(0)
copy(dup[1:], elems)
return NewList(context.Background(), vrw, dup...)
// TODO(binformat)
return NewList(context.Background(), Format_7_18, vrw, dup...)
},
appendOne: func() Collection {
dup := make([]Value, length+1)
copy(dup, elems)
dup[len(dup)-1] = Float(0)
return NewList(context.Background(), vrw, dup...)
// TODO(binformat)
return NewList(context.Background(), Format_7_18, vrw, dup...)
},
},
elems: elems,
@@ -147,7 +152,8 @@ func (suite *listTestSuite) TestIterRange() {
batchSize := list.Len() / (2 << s)
expectIdx := uint64(0)
for i := uint64(0); i < list.Len(); i += batchSize {
list.IterRange(context.Background(), i, i+batchSize, func(v Value, idx uint64) {
// TODO(binformat)
list.IterRange(context.Background(), Format_7_18, i, i+batchSize, func(v Value, idx uint64) {
suite.Equal(expectIdx, idx)
expectIdx++
suite.Equal(suite.elems[idx], v)
@@ -176,7 +182,8 @@ func TestListInsert(t *testing.T) {
for i := 0; i < len(tl); i += 16 {
tl = tl.Insert(i, Float(i))
list = list.Edit().Insert(uint64(i), Float(i)).List(context.Background())
// TODO(binformat)
list = list.Edit(Format_7_18).Insert(uint64(i), Float(i)).List(context.Background())
}
assert.True(tl.toList(vrw).Equals(list))
@@ -195,7 +202,8 @@ func TestListRemove(t *testing.T) {
for i := len(tl) - 16; i >= 0; i -= 16 {
tl = tl.Remove(i, i+4)
list = list.Edit().Remove(uint64(i), uint64(i+4)).List(context.Background())
// TODO(binformat)
list = list.Edit(Format_7_18).Remove(uint64(i), uint64(i+4)).List(context.Background())
}
assert.True(tl.toList(vrw).Equals(list))
@@ -205,15 +213,16 @@ func TestListRemoveAt(t *testing.T) {
assert := assert.New(t)
vrw := newTestValueStore()
l0 := NewList(context.Background(), vrw)
l0 = l0.Edit().Append(Bool(false), Bool(true)).List(context.Background())
l1 := l0.Edit().RemoveAt(1).List(context.Background())
assert.True(NewList(context.Background(), vrw, Bool(false)).Equals(l1))
l1 = l1.Edit().RemoveAt(0).List(context.Background())
assert.True(NewList(context.Background(), vrw).Equals(l1))
// TODO(binformat)
l0 := NewList(context.Background(), Format_7_18, vrw)
l0 = l0.Edit(Format_7_18).Append(Bool(false), Bool(true)).List(context.Background())
l1 := l0.Edit(Format_7_18).RemoveAt(1).List(context.Background())
assert.True(NewList(context.Background(), Format_7_18, vrw, Bool(false)).Equals(l1))
l1 = l1.Edit(Format_7_18).RemoveAt(0).List(context.Background())
assert.True(NewList(context.Background(), Format_7_18, vrw).Equals(l1))
assert.Panics(func() {
l1.Edit().RemoveAt(0).List(context.Background())
l1.Edit(Format_7_18).RemoveAt(0).List(context.Background())
})
}
@@ -255,9 +264,10 @@ func TestStreamingListCreation(t *testing.T) {
vs := newTestValueStore()
simpleList := getTestList()
cl := NewList(context.Background(), vs, simpleList...)
// TODO(binformat)
cl := NewList(context.Background(), Format_7_18, vs, simpleList...)
valueChan := make(chan Value)
listChan := NewStreamingList(context.Background(), vs, valueChan)
listChan := NewStreamingList(context.Background(), Format_7_18, vs, valueChan)
for _, v := range simpleList {
valueChan <- v
}
@@ -281,8 +291,9 @@ func TestListAppend(t *testing.T) {
}
assert := assert.New(t)
// TODO(binformat)
newList := func(items testList) List {
return NewList(context.Background(), vrw, items...)
return NewList(context.Background(), Format_7_18, vrw, items...)
}
listToSimple := func(cl List) (simple testList) {
@@ -293,11 +304,12 @@ func TestListAppend(t *testing.T) {
}
cl := newList(getTestList())
cl2 := cl.Edit().Append(Float(42)).List(context.Background())
cl3 := cl2.Edit().Append(Float(43)).List(context.Background())
cl4 := cl3.Edit().Append(getTestList().AsValuables()...).List(context.Background())
cl5 := cl4.Edit().Append(Float(44), Float(45)).List(context.Background())
cl6 := cl5.Edit().Append(getTestList().AsValuables()...).List(context.Background())
// TODO(binformat)
cl2 := cl.Edit(Format_7_18).Append(Float(42)).List(context.Background())
cl3 := cl2.Edit(Format_7_18).Append(Float(43)).List(context.Background())
cl4 := cl3.Edit(Format_7_18).Append(getTestList().AsValuables()...).List(context.Background())
cl5 := cl4.Edit(Format_7_18).Append(Float(44), Float(45)).List(context.Background())
cl6 := cl5.Edit(Format_7_18).Append(getTestList().AsValuables()...).List(context.Background())
expected := getTestList()
assert.Equal(expected, listToSimple(cl))
@@ -342,9 +354,10 @@ func TestListValidateInsertAscending(t *testing.T) {
values := generateNumbersAsValues(1000)
s := NewList(context.Background(), vrw)
// TODO(binformat)
s := NewList(context.Background(), Format_7_18, vrw)
for i, v := range values {
s = s.Edit().Insert(uint64(i), v).List(context.Background())
s = s.Edit(Format_7_18).Insert(uint64(i), v).List(context.Background())
validateList(t, vrw, s, values[0:i+1])
}
}
@@ -360,12 +373,14 @@ func TestListValidateInsertAtZero(t *testing.T) {
vrw := newTestValueStore()
values := generateNumbersAsValues(1000)
s := NewList(context.Background(), vrw)
// TODO(binformat)
s := NewList(context.Background(), Format_7_18, vrw)
count := len(values)
for count > 0 {
count--
v := values[count]
s = s.Edit().Insert(uint64(0), v).List(context.Background())
// TODO(binformat)
s = s.Edit(Format_7_18).Insert(uint64(0), v).List(context.Background())
validateList(t, vrw, s, values[count:])
}
}
@@ -380,12 +395,13 @@ func TestListInsertNothing(t *testing.T) {
cl := getTestList().toList(vrw)
assert.True(cl.Equals(cl.Edit().Insert(0).List(context.Background())))
// TODO(binformat)
assert.True(cl.Equals(cl.Edit(Format_7_18).Insert(0).List(context.Background())))
for i := uint64(1); i < getTestListLen(); i *= 2 {
assert.True(cl.Equals(cl.Edit().Insert(i).List(context.Background())))
assert.True(cl.Equals(cl.Edit(Format_7_18).Insert(i).List(context.Background())))
}
assert.True(cl.Equals(cl.Edit().Insert(cl.Len() - 1).List(context.Background())))
assert.True(cl.Equals(cl.Edit().Insert(cl.Len()).List(context.Background())))
assert.True(cl.Equals(cl.Edit(Format_7_18).Insert(cl.Len() - 1).List(context.Background())))
assert.True(cl.Equals(cl.Edit(Format_7_18).Insert(cl.Len()).List(context.Background())))
}
func TestListInsertStart(t *testing.T) {
@@ -400,11 +416,12 @@ func TestListInsertStart(t *testing.T) {
vrw := newTestValueStore()
cl := getTestList().toList(vrw)
cl2 := cl.Edit().Insert(0, Float(42)).List(context.Background())
cl3 := cl2.Edit().Insert(0, Float(43)).List(context.Background())
cl4 := cl3.Edit().Insert(0, getTestList().AsValuables()...).List(context.Background())
cl5 := cl4.Edit().Insert(0, Float(44), Float(45)).List(context.Background())
cl6 := cl5.Edit().Insert(0, getTestList().AsValuables()...).List(context.Background())
// TODO(binformat)
cl2 := cl.Edit(Format_7_18).Insert(0, Float(42)).List(context.Background())
cl3 := cl2.Edit(Format_7_18).Insert(0, Float(43)).List(context.Background())
cl4 := cl3.Edit(Format_7_18).Insert(0, getTestList().AsValuables()...).List(context.Background())
cl5 := cl4.Edit(Format_7_18).Insert(0, Float(44), Float(45)).List(context.Background())
cl6 := cl5.Edit(Format_7_18).Insert(0, getTestList().AsValuables()...).List(context.Background())
expected := getTestList()
assert.Equal(expected, testListFromNomsList(cl))
@@ -449,12 +466,13 @@ func TestListInsertMiddle(t *testing.T) {
vrw := newTestValueStore()
cl := getTestList().toList(vrw)
cl2 := cl.Edit().Insert(100, Float(42)).List(context.Background())
cl3 := cl2.Edit().Insert(200, Float(43)).List(context.Background())
cl4 := cl3.Edit().Insert(300, getTestList().AsValuables()...).List(context.Background())
cl5 := cl4.Edit().Insert(400, Float(44), Float(45)).List(context.Background())
cl6 := cl5.Edit().Insert(500, getTestList().AsValuables()...).List(context.Background())
cl7 := cl6.Edit().Insert(600, Float(100)).List(context.Background())
// TODO(binformat)
cl2 := cl.Edit(Format_7_18).Insert(100, Float(42)).List(context.Background())
cl3 := cl2.Edit(Format_7_18).Insert(200, Float(43)).List(context.Background())
cl4 := cl3.Edit(Format_7_18).Insert(300, getTestList().AsValuables()...).List(context.Background())
cl5 := cl4.Edit(Format_7_18).Insert(400, Float(44), Float(45)).List(context.Background())
cl6 := cl5.Edit(Format_7_18).Insert(500, getTestList().AsValuables()...).List(context.Background())
cl7 := cl6.Edit(Format_7_18).Insert(600, Float(100)).List(context.Background())
expected := getTestList()
assert.Equal(expected, testListFromNomsList(cl))
@@ -510,7 +528,8 @@ func TestListInsertRanges(t *testing.T) {
for incr, i := 256, 0; i < len(testList)-incr; i += incr {
for window := 1; window <= incr; window *= 16 {
testListPart := testList.Remove(i, i+window)
actual := testListPart.toList(vrw).Edit().Insert(uint64(i), testList[i:i+window].AsValuables()...).List(context.Background())
// TODO(binformat)
actual := testListPart.toList(vrw).Edit(Format_7_18).Insert(uint64(i), testList[i:i+window].AsValuables()...).List(context.Background())
assert.Equal(whole.Len(), actual.Len())
assert.True(whole.Equals(actual))
}
@@ -518,7 +537,8 @@ func TestListInsertRanges(t *testing.T) {
// Compare list length, which doesn't require building a new list every iteration, so the increment can be smaller.
for incr, i := 10, 0; i < len(testList); i += incr {
assert.Equal(len(testList)+incr, int(whole.Edit().Insert(uint64(i), testList[0:incr].AsValuables()...).List(context.Background()).Len()))
// TODO(binformat)
assert.Equal(len(testList)+incr, int(whole.Edit(Format_7_18).Insert(uint64(i), testList[0:incr].AsValuables()...).List(context.Background()).Len()))
}
}
@@ -532,12 +552,13 @@ func TestListRemoveNothing(t *testing.T) {
cl := getTestList().toList(vrw)
assert.True(cl.Equals(cl.Edit().Remove(0, 0).List(context.Background())))
// TODO(binformat)
assert.True(cl.Equals(cl.Edit(Format_7_18).Remove(0, 0).List(context.Background())))
for i := uint64(1); i < getTestListLen(); i *= 2 {
assert.True(cl.Equals(cl.Edit().Remove(i, i).List(context.Background())))
assert.True(cl.Equals(cl.Edit(Format_7_18).Remove(i, i).List(context.Background())))
}
assert.True(cl.Equals(cl.Edit().Remove(cl.Len()-1, cl.Len()-1).List(context.Background())))
assert.True(cl.Equals(cl.Edit().Remove(cl.Len(), cl.Len()).List(context.Background())))
assert.True(cl.Equals(cl.Edit(Format_7_18).Remove(cl.Len()-1, cl.Len()-1).List(context.Background())))
assert.True(cl.Equals(cl.Edit(Format_7_18).Remove(cl.Len(), cl.Len()).List(context.Background())))
}
func TestListRemoveEverything(t *testing.T) {
@@ -548,9 +569,11 @@ func TestListRemoveEverything(t *testing.T) {
vrw := newTestValueStore()
cl := getTestList().toList(vrw).Edit().Remove(0, getTestListLen()).List(context.Background())
// TODO(binformat)
cl := getTestList().toList(vrw).Edit(Format_7_18).Remove(0, getTestListLen()).List(context.Background())
assert.True(NewList(context.Background(), vrw).Equals(cl))
// TODO(binformat)
assert.True(NewList(context.Background(), Format_7_18, vrw).Equals(cl))
assert.Equal(0, int(cl.Len()))
}
@@ -566,8 +589,9 @@ func TestListRemoveAtMiddle(t *testing.T) {
vrw := newTestValueStore()
cl := getTestList().toList(vrw)
cl2 := cl.Edit().RemoveAt(100).List(context.Background())
cl3 := cl2.Edit().RemoveAt(200).List(context.Background())
// TODO(binformat)
cl2 := cl.Edit(Format_7_18).RemoveAt(100).List(context.Background())
cl3 := cl2.Edit(Format_7_18).RemoveAt(200).List(context.Background())
expected := getTestList()
assert.Equal(expected, testListFromNomsList(cl))
@@ -604,7 +628,8 @@ func TestListRemoveRanges(t *testing.T) {
for window := 1; window <= incr; window *= 16 {
testListPart := testList.Remove(i, i+window)
expected := testListPart.toList(vrw)
actual := whole.Edit().Remove(uint64(i), uint64(i+window)).List(context.Background())
// TODO(binformat)
actual := whole.Edit(Format_7_18).Remove(uint64(i), uint64(i+window)).List(context.Background())
assert.Equal(expected.Len(), actual.Len())
assert.True(expected.Equals(actual))
}
@@ -612,7 +637,8 @@ func TestListRemoveRanges(t *testing.T) {
// Compare list length, which doesn't require building a new list every iteration, so the increment can be smaller.
for incr, i := 10, 0; i < len(testList)-incr; i += incr {
assert.Equal(len(testList)-incr, int(whole.Edit().Remove(uint64(i), uint64(i+incr)).List(context.Background()).Len()))
// TODO(binformat)
assert.Equal(len(testList)-incr, int(whole.Edit(Format_7_18).Remove(uint64(i), uint64(i+incr)).List(context.Background()).Len()))
}
}
@@ -631,7 +657,8 @@ func TestListRemoveAtEnd(t *testing.T) {
cl := tl.toList(vrw)
for i := len(tl) - 1; i >= 0; i-- {
cl = cl.Edit().Remove(uint64(i), uint64(i+1)).List(context.Background())
// TODO(binformat)
cl = cl.Edit(Format_7_18).Remove(uint64(i), uint64(i+1)).List(context.Background())
expect := tl[0:i].toList(vrw)
assert.True(expect.Equals(cl))
}
@@ -653,7 +680,8 @@ func TestListSet(t *testing.T) {
testIdx := func(idx int, testEquality bool) {
newVal := Float(-1) // Test values are never < 0
cl2 := cl.Edit().Set(uint64(idx), newVal).List(context.Background())
// TODO(binformat)
cl2 := cl.Edit(Format_7_18).Set(uint64(idx), newVal).List(context.Background())
assert.False(cl.Equals(cl2))
if testEquality {
assert.True(testList.Set(idx, newVal).toList(vrw).Equals(cl2))
@@ -676,7 +704,8 @@ func TestListFirstNNumbers(t *testing.T) {
vrw := newTestValueStore()
nums := generateNumbersAsValues(testListSize)
NewList(context.Background(), vrw, nums...)
// TODO(binformat)
NewList(context.Background(), Format_7_18, vrw, nums...)
}
func TestListRefOfStructFirstNNumbers(t *testing.T) {
@@ -686,7 +715,8 @@ func TestListRefOfStructFirstNNumbers(t *testing.T) {
vrw := newTestValueStore()
nums := generateNumbersAsRefOfStructs(vrw, testListSize)
NewList(context.Background(), vrw, nums...)
// TODO(binformat)
NewList(context.Background(), Format_7_18, vrw, nums...)
}
func TestListModifyAfterRead(t *testing.T) {
@@ -703,9 +733,10 @@ func TestListModifyAfterRead(t *testing.T) {
// Modify/query. Once upon a time this would crash.
llen := list.Len()
z := list.Get(context.Background(), 0)
list = list.Edit().RemoveAt(0).List(context.Background())
// TODO(binformat)
list = list.Edit(Format_7_18).RemoveAt(0).List(context.Background())
assert.Equal(llen-1, list.Len())
list = list.Edit().Append(z).List(context.Background())
list = list.Edit(Format_7_18).Append(z).List(context.Background())
assert.Equal(llen, list.Len())
}
@@ -741,8 +772,9 @@ func TestListDiffIdentical(t *testing.T) {
assert := assert.New(t)
nums := generateNumbersAsValues(5)
l1 := NewList(context.Background(), vrw, nums...)
l2 := NewList(context.Background(), vrw, nums...)
// TODO(binformat)
l1 := NewList(context.Background(), Format_7_18, vrw, nums...)
l2 := NewList(context.Background(), Format_7_18, vrw, nums...)
diff1 := accumulateDiffSplices(l1, l2)
diff2 := accumulateDiffSplices(l2, l1)
@@ -759,8 +791,9 @@ func TestListDiffVersusEmpty(t *testing.T) {
assert := assert.New(t)
nums1 := generateNumbersAsValues(5)
l1 := NewList(context.Background(), vrw, nums1...)
l2 := NewList(context.Background(), vrw)
// TODO(binformat)
l1 := NewList(context.Background(), Format_7_18, vrw, nums1...)
l2 := NewList(context.Background(), Format_7_18, vrw)
diff1 := accumulateDiffSplices(l1, l2)
diff2 := accumulateDiffSplices(l2, l1)
@@ -784,8 +817,9 @@ func TestListDiffReverse(t *testing.T) {
assert := assert.New(t)
nums1 := generateNumbersAsValues(5000)
nums2 := reverseValues(nums1)
l1 := NewList(context.Background(), vrw, nums1...)
l2 := NewList(context.Background(), vrw, nums2...)
// TODO(binformat)
l1 := NewList(context.Background(), Format_7_18, vrw, nums1...)
l2 := NewList(context.Background(), Format_7_18, vrw, nums2...)
diff1 := accumulateDiffSplices(l1, l2)
diff2 := accumulateDiffSplices(l2, l1)
@@ -811,8 +845,9 @@ func TestListDiffReverseWithLargerLimit(t *testing.T) {
nums1 := generateNumbersAsValues(5000)
nums2 := reverseValues(nums1)
l1 := NewList(context.Background(), vrw, nums1...)
l2 := NewList(context.Background(), vrw, nums2...)
// TODO(binformat)
l1 := NewList(context.Background(), Format_7_18, vrw, nums1...)
l2 := NewList(context.Background(), Format_7_18, vrw, nums2...)
diff1 := accumulateDiffSplicesWithLimit(l1, l2, 27e6)
diff2 := accumulateDiffSplicesWithLimit(l2, l1, 27e6)
@@ -842,8 +877,9 @@ func TestListDiffRemove5x100(t *testing.T) {
for count := 5; count > 0; count-- {
nums2 = spliceValues(nums2, (count-1)*1000, 100)
}
l1 := NewList(context.Background(), vrw, nums1...)
l2 := NewList(context.Background(), vrw, nums2...)
// TODO(binformat)
l1 := NewList(context.Background(), Format_7_18, vrw, nums1...)
l2 := NewList(context.Background(), Format_7_18, vrw, nums2...)
diff1 := accumulateDiffSplices(l1, l2)
diff2 := accumulateDiffSplices(l2, l1)
@@ -875,8 +911,9 @@ func TestListDiffAdd5x5(t *testing.T) {
for count := 5; count > 0; count-- {
nums2 = spliceValues(nums2, (count-1)*1000, 0, Float(0), Float(1), Float(2), Float(3), Float(4))
}
l1 := NewList(context.Background(), vrw, nums1...)
l2 := NewList(context.Background(), vrw, nums2...)
// TODO(binformat)
l1 := NewList(context.Background(), Format_7_18, vrw, nums1...)
l2 := NewList(context.Background(), Format_7_18, vrw, nums2...)
diff1 := accumulateDiffSplices(l1, l2)
diff2 := accumulateDiffSplices(l2, l1)
@@ -909,8 +946,9 @@ func TestListDiffReplaceReverse5x100(t *testing.T) {
out := reverseValues(nums2[(count-1)*1000 : (count-1)*1000+100])
nums2 = spliceValues(nums2, (count-1)*1000, 100, out...)
}
l1 := NewList(context.Background(), vrw, nums1...)
l2 := NewList(context.Background(), vrw, nums2...)
// TODO(binformat)
l1 := NewList(context.Background(), Format_7_18, vrw, nums1...)
l2 := NewList(context.Background(), Format_7_18, vrw, nums2...)
diff := accumulateDiffSplices(l2, l1)
diffExpected := []Splice{
@@ -937,8 +975,9 @@ func TestListDiffString1(t *testing.T) {
assert := assert.New(t)
nums1 := []Value{String("one"), String("two"), String("three")}
nums2 := []Value{String("one"), String("two"), String("three")}
l1 := NewList(context.Background(), vrw, nums1...)
l2 := NewList(context.Background(), vrw, nums2...)
// TODO(binformat)
l1 := NewList(context.Background(), Format_7_18, vrw, nums1...)
l2 := NewList(context.Background(), Format_7_18, vrw, nums2...)
diff := accumulateDiffSplices(l2, l1)
assert.Equal(0, len(diff))
@@ -953,8 +992,9 @@ func TestListDiffString2(t *testing.T) {
assert := assert.New(t)
nums1 := []Value{String("one"), String("two"), String("three")}
nums2 := []Value{String("one"), String("two"), String("three"), String("four")}
l1 := NewList(context.Background(), vrw, nums1...)
l2 := NewList(context.Background(), vrw, nums2...)
// TODO(binformat)
l1 := NewList(context.Background(), Format_7_18, vrw, nums1...)
l2 := NewList(context.Background(), Format_7_18, vrw, nums2...)
diff := accumulateDiffSplices(l2, l1)
diffExpected := []Splice{
@@ -972,8 +1012,9 @@ func TestListDiffString3(t *testing.T) {
assert := assert.New(t)
nums1 := []Value{String("one"), String("two"), String("three")}
nums2 := []Value{String("one"), String("two"), String("four")}
l1 := NewList(context.Background(), vrw, nums1...)
l2 := NewList(context.Background(), vrw, nums2...)
// TODO(binformat)
l1 := NewList(context.Background(), Format_7_18, vrw, nums1...)
l2 := NewList(context.Background(), Format_7_18, vrw, nums2...)
diff := accumulateDiffSplices(l2, l1)
diffExpected := []Splice{
@@ -994,7 +1035,8 @@ func TestListDiffLargeWithSameMiddle(t *testing.T) {
cs1 := storage.NewView()
vs1 := NewValueStore(cs1)
nums1 := generateNumbersAsValues(4000)
l1 := NewList(context.Background(), vs1, nums1...)
// TODO(binformat)
l1 := NewList(context.Background(), Format_7_18, vs1, nums1...)
hash1 := vs1.WriteValue(context.Background(), l1).TargetHash()
vs1.Commit(context.Background(), vs1.Root(context.Background()), vs1.Root(context.Background()))
@@ -1003,7 +1045,8 @@ func TestListDiffLargeWithSameMiddle(t *testing.T) {
cs2 := storage.NewView()
vs2 := NewValueStore(cs2)
nums2 := generateNumbersAsValuesFromToBy(5, 3550, 1)
l2 := NewList(context.Background(), vs2, nums2...)
// TODO(binformat)
l2 := NewList(context.Background(), Format_7_18, vs2, nums2...)
hash2 := vs2.WriteValue(context.Background(), l2).TargetHash()
vs2.Commit(context.Background(), vs1.Root(context.Background()), vs1.Root(context.Background()))
refList2 := vs2.ReadValue(context.Background(), hash2).(List)
@@ -1064,17 +1107,20 @@ func TestListTypeAfterMutations(t *testing.T) {
vrw := newTestValueStore()
values := generateNumbersAsValues(n)
l := NewList(context.Background(), vrw, values...)
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, vrw, values...)
assert.Equal(l.Len(), uint64(n))
assert.IsType(c, l.asSequence())
assert.True(TypeOf(l).Equals(MakeListType(FloaTType)))
l = l.Edit().Append(String("a")).List(context.Background())
// TODO(binformat)
l = l.Edit(Format_7_18).Append(String("a")).List(context.Background())
assert.Equal(l.Len(), uint64(n+1))
assert.IsType(c, l.asSequence())
assert.True(TypeOf(l).Equals(MakeListType(MakeUnionType(FloaTType, StringType))))
l = l.Edit().Splice(l.Len()-1, 1).List(context.Background())
// TODO(binformat)
l = l.Edit(Format_7_18).Splice(l.Len()-1, 1).List(context.Background())
assert.Equal(l.Len(), uint64(n))
assert.IsType(c, l.asSequence())
assert.True(TypeOf(l).Equals(MakeListType(FloaTType)))
@@ -1100,7 +1146,8 @@ func TestListRemoveLastWhenNotLoaded(t *testing.T) {
for len(tl) > 0 {
tl = tl[:len(tl)-1]
nl = reload(nl.Edit().RemoveAt(uint64(len(tl))).List(context.Background()))
// TODO(binformat)
nl = reload(nl.Edit(Format_7_18).RemoveAt(uint64(len(tl))).List(context.Background()))
assert.True(tl.toList(vs).Equals(nl))
}
}
@@ -1133,7 +1180,8 @@ func TestListConcat(t *testing.T) {
for i := from; i < to; i += by {
fst := reload(vs, listSlice[:i].toList(vs))
snd := reload(vs, listSlice[i:].toList(vs))
actual := fst.Concat(context.Background(), snd)
// TODO(binformat)
actual := fst.Concat(context.Background(), Format_7_18, snd)
assert.True(list.Equals(actual),
"fail at %d/%d (with expected length %d, actual %d)", i, size, list.Len(), actual.Len())
}
@@ -1164,15 +1212,17 @@ func TestListConcatDifferentTypes(t *testing.T) {
whole = append(whole, fst...)
whole = append(whole, snd...)
concat := NewList(context.Background(), vrw, fst...).Concat(context.Background(), NewList(context.Background(), vrw, snd...))
assert.True(NewList(context.Background(), vrw, whole...).Equals(concat))
// TODO(binformat)
concat := NewList(context.Background(), Format_7_18, vrw, fst...).Concat(context.Background(), Format_7_18, NewList(context.Background(), Format_7_18, vrw, snd...))
assert.True(NewList(context.Background(), Format_7_18, vrw, whole...).Equals(concat))
}
func TestListWithStructShouldHaveOptionalFields(t *testing.T) {
assert := assert.New(t)
vrw := newTestValueStore()
list := NewList(context.Background(), vrw,
// TODO(binformat)
list := NewList(context.Background(), Format_7_18, vrw,
NewStruct("Foo", StructData{
"a": Float(1),
}),
@@ -1193,10 +1243,11 @@ func TestListWithNil(t *testing.T) {
vrw := newTestValueStore()
assert.Panics(t, func() {
NewList(context.Background(), vrw, nil)
// TODO(binformat)
NewList(context.Background(), Format_7_18, vrw, nil)
})
assert.Panics(t, func() {
NewList(context.Background(), vrw, Float(42), nil)
NewList(context.Background(), Format_7_18, vrw, Float(42), nil)
})
}
@@ -1204,9 +1255,10 @@ func TestListOfListsDoesNotWriteRoots(t *testing.T) {
assert := assert.New(t)
vrw := newTestValueStore()
l1 := NewList(context.Background(), vrw, String("a"), String("b"))
l2 := NewList(context.Background(), vrw, String("c"), String("d"))
l3 := NewList(context.Background(), vrw, l1, l2)
// TODO(binformat)
l1 := NewList(context.Background(), Format_7_18, vrw, String("a"), String("b"))
l2 := NewList(context.Background(), Format_7_18, vrw, String("c"), String("d"))
l3 := NewList(context.Background(), Format_7_18, vrw, l1, l2)
// TODO(binformat)
assert.Nil(vrw.ReadValue(context.Background(), l1.Hash(Format_7_18)))
+4 -2
View File
@@ -123,7 +123,8 @@ func (m Map) Value(ctx context.Context) Value {
}
func (m Map) WalkValues(ctx context.Context, cb ValueCallback) {
iterAll(ctx, m, func(v Value, idx uint64) {
// TODO(binformat)
iterAll(ctx, Format_7_18, m, func(v Value, idx uint64) {
cb(v)
})
}
@@ -224,7 +225,8 @@ type mapIterAllCallback func(key, value Value)
func (m Map) IterAll(ctx context.Context, cb mapIterAllCallback) {
var k Value
iterAll(ctx, m, func(v Value, idx uint64) {
// TODO(binformat)
iterAll(ctx, Format_7_18, m, func(v Value, idx uint64) {
if k != nil {
cb(k, v)
k = nil
+9 -7
View File
@@ -1133,8 +1133,9 @@ func TestMapEquals(t *testing.T) {
diffMapTest(assert, m3, m1, 0, 0, 0)
diffMapTest(assert, m3, m2, 0, 0, 0)
m1 = NewMap(context.Background(), vrw, String("foo"), Float(0.0), String("bar"), NewList(context.Background(), vrw))
m2 = m2.Edit().Set(String("foo"), Float(0.0)).Set(String("bar"), NewList(context.Background(), vrw)).Map(context.Background())
// TODO(binformat)
m1 = NewMap(context.Background(), vrw, String("foo"), Float(0.0), String("bar"), NewList(context.Background(), Format_7_18, vrw))
m2 = m2.Edit().Set(String("foo"), Float(0.0)).Set(String("bar"), NewList(context.Background(), Format_7_18, vrw)).Map(context.Background())
assert.True(m1.Equals(m2))
assert.True(m2.Equals(m1))
assert.False(m2.Equals(m3))
@@ -1162,8 +1163,8 @@ func TestMapNotStringKeys(t *testing.T) {
Float(0), String("Float: 0"),
b1, String("blob1"),
b2, String("blob2"),
NewList(context.Background(), vrw), String("empty list"),
NewList(context.Background(), vrw, NewList(context.Background(), vrw)), String("list of list"),
NewList(context.Background(), Format_7_18, vrw), String("empty list"),
NewList(context.Background(), Format_7_18, vrw, NewList(context.Background(), Format_7_18, vrw)), String("list of list"),
NewMap(context.Background(), vrw), String("empty map"),
NewMap(context.Background(), vrw, NewMap(context.Background(), vrw), NewMap(context.Background(), vrw)), String("map of map/map"),
NewSet(context.Background(), vrw), String("empty set"),
@@ -1421,7 +1422,8 @@ func TestMapEmpty(t *testing.T) {
me = m.Edit()
assert.False(m.Empty())
me.Set(NewList(ctx, vrw), NewMap(ctx, vrw))
// TODO(binformat)
me.Set(NewList(ctx, Format_7_18, vrw), NewMap(ctx, vrw))
m = me.Map(ctx)
assert.False(m.Empty())
}
@@ -1575,7 +1577,7 @@ func TestCompoundMapWithValuesOfEveryType(t *testing.T) {
// TODO(binformat)
NewBlob(context.Background(), Format_7_18, vrw, bytes.NewBufferString("buf")), v,
NewSet(context.Background(), vrw, Bool(true)), v,
NewList(context.Background(), vrw, Bool(true)), v,
NewList(context.Background(), Format_7_18, vrw, Bool(true)), v,
NewMap(context.Background(), vrw, Bool(true), Float(0)), v,
NewStruct("", StructData{"field": Bool(true)}), v,
// Refs of values
@@ -1585,7 +1587,7 @@ func TestCompoundMapWithValuesOfEveryType(t *testing.T) {
// TODO(binformat)
NewRef(NewBlob(context.Background(), Format_7_18, vrw, bytes.NewBufferString("buf"))), v,
NewRef(NewSet(context.Background(), vrw, Bool(true))), v,
NewRef(NewList(context.Background(), vrw, Bool(true))), v,
NewRef(NewList(context.Background(), Format_7_18, vrw, Bool(true))), v,
NewRef(NewMap(context.Background(), vrw, Bool(true), Float(0))), v,
NewRef(NewStruct("", StructData{"field": Bool(true)})), v,
}
+10 -5
View File
@@ -99,7 +99,8 @@ func TestPathIndex(t *testing.T) {
assertResolvesTo(assert, expKey, v, str+"@key")
}
v = NewList(context.Background(), vs, Float(1), Float(3), String("foo"), Bool(false))
// TODO(binformat)
v = NewList(context.Background(), Format_7_18, vs, Float(1), Float(3), String("foo"), Bool(false))
resolvesTo(Float(1), Float(0), "[0]")
resolvesTo(Float(3), Float(1), "[1]")
@@ -177,7 +178,8 @@ func TestPathHashIndex(t *testing.T) {
br := NewRef(b)
i := Float(0)
str := String("foo")
l := NewList(context.Background(), vs, b, i, str)
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, vs, b, i, str)
lr := NewRef(l)
m := NewMap(context.Background(), vs,
b, br,
@@ -245,7 +247,8 @@ func TestPathMulti(t *testing.T) {
m1, String("fire"),
)
l := NewList(context.Background(), vs, m1, m2)
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, vs, m1, m2)
s := NewStruct("", StructData{
"foo": l,
@@ -487,7 +490,8 @@ func TestPathType(t *testing.T) {
String("string"), String("foo"),
String("bool"), Bool(false),
String("number"), Float(42),
String("List<number|string>"), NewList(context.Background(), vs, Float(42), String("foo")),
// TODO(binformat)
String("List<number|string>"), NewList(context.Background(), Format_7_18, vs, Float(42), String("foo")),
String("Map<Bool, Bool>"), NewMap(context.Background(), vs, Bool(true), Bool(false)))
m.IterAll(context.Background(), func(k, cv Value) {
@@ -534,7 +538,8 @@ func TestPathAtAnnotation(t *testing.T) {
assertResolvesTo(assert, expKey, v, str+"@key")
}
v = NewList(context.Background(), vs, Float(1), Float(3), String("foo"), Bool(false))
// TODO(binformat)
v = NewList(context.Background(), Format_7_18, vs, Float(1), Float(3), String("foo"), Bool(false))
resolvesTo(Float(1), nil, "@at(0)")
resolvesTo(Float(3), nil, "@at(1)")
+5 -5
View File
@@ -29,7 +29,7 @@ func (s *perfSuite) SetupSuite() {
func (s *perfSuite) Test01BuildList10mNumbers() {
assert := s.NewAssert()
in := make(chan types.Value, 16)
out := types.NewStreamingList(context.Background(), s.Database, in)
out := types.NewStreamingList(context.Background(), types.Format_7_18, s.Database, in)
for i := 0; i < 1e7; i++ {
in <- types.Float(s.r.Int63())
@@ -48,7 +48,7 @@ func (s *perfSuite) Test01BuildList10mNumbers() {
func (s *perfSuite) Test02BuildList10mStructs() {
assert := s.NewAssert()
in := make(chan types.Value, 16)
out := types.NewStreamingList(context.Background(), s.Database, in)
out := types.NewStreamingList(context.Background(), types.Format_7_18, s.Database, in)
for i := 0; i < 1e7; i++ {
in <- types.NewStruct("", types.StructData{
@@ -86,13 +86,13 @@ func (s *perfSuite) Test05Concat10mValues2kTimes() {
l1Len, l2Len := l1.Len(), l2.Len()
l1Last, l2Last := last(l1), last(l2)
l3 := types.NewList(context.Background(), s.Database)
l3 := types.NewList(context.Background(), types.Format_7_18, s.Database)
for i := uint64(0); i < 1e3; i++ { // 1k iterations * 2 concat ops = 2k times
// Include some basic sanity checks.
l3 = l3.Concat(context.Background(), l1)
l3 = l3.Concat(context.Background(), types.Format_7_18, l1)
assert.True(l1Last.Equals(last(l3)))
assert.Equal(i*(l1Len+l2Len)+l1Len, l3.Len())
l3 = l3.Concat(context.Background(), l2)
l3 = l3.Concat(context.Background(), types.Format_7_18, l2)
assert.True(l2Last.Equals(last(l3)))
assert.Equal((i+1)*(l1Len+l2Len), l3.Len())
}
+5 -3
View File
@@ -16,9 +16,10 @@ func TestRefInList(t *testing.T) {
vs := newTestValueStore()
l := NewList(context.Background(), vs)
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, vs)
r := NewRef(l)
l = l.Edit().Append(r).List(context.Background())
l = l.Edit(Format_7_18).Append(r).List(context.Background())
r2 := l.Get(context.Background(), 0)
assert.True(r.Equals(r2))
}
@@ -55,7 +56,8 @@ func TestRefChunks(t *testing.T) {
vs := newTestValueStore()
l := NewList(context.Background(), vs)
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, vs)
r := NewRef(l)
assert.Len(getChunks(r), 1)
assert.Equal(r, getChunks(r)[0])
+4 -2
View File
@@ -108,7 +108,8 @@ func (s Set) Value(ctx context.Context) Value {
}
func (s Set) WalkValues(ctx context.Context, cb ValueCallback) {
iterAll(ctx, s, func(v Value, idx uint64) {
// TODO(binformat)
iterAll(ctx, Format_7_18, s, func(v Value, idx uint64) {
cb(v)
})
}
@@ -147,7 +148,8 @@ func (s Set) Iter(ctx context.Context, cb setIterCallback) {
type setIterAllCallback func(v Value)
func (s Set) IterAll(ctx context.Context, cb setIterAllCallback) {
iterAll(ctx, s, func(v Value, idx uint64) {
// TODO(binformat)
iterAll(ctx, Format_7_18, s, func(v Value, idx uint64) {
cb(v)
})
}
+2 -2
View File
@@ -1014,7 +1014,7 @@ func TestChunkedSetWithValuesOfEveryType(t *testing.T) {
// TODO(binformat)
NewBlob(context.Background(), Format_7_18, vs, bytes.NewBufferString("buf")),
NewSet(context.Background(), vs, Bool(true)),
NewList(context.Background(), vs, Bool(true)),
NewList(context.Background(), Format_7_18, vs, Bool(true)),
NewMap(context.Background(), vs, Bool(true), Float(0)),
NewStruct("", StructData{"field": Bool(true)}),
// Refs of values
@@ -1024,7 +1024,7 @@ func TestChunkedSetWithValuesOfEveryType(t *testing.T) {
// TODO(binformat)
NewRef(NewBlob(context.Background(), Format_7_18, vs, bytes.NewBufferString("buf"))),
NewRef(NewSet(context.Background(), vs, Bool(true))),
NewRef(NewList(context.Background(), vs, Bool(true))),
NewRef(NewList(context.Background(), Format_7_18, vs, Bool(true))),
NewRef(NewMap(context.Background(), vs, Bool(true), Float(0))),
NewRef(NewStruct("", StructData{"field": Bool(true)})),
}
+22 -10
View File
@@ -80,8 +80,9 @@ func TestGenericStructSet(t *testing.T) {
).Equals(TypeOf(s5)))
// Subtype is not equal.
s6 := NewStruct("", StructData{"l": NewList(context.Background(), vs, Float(0), Float(1), Bool(false), Bool(true))})
s7 := s6.Set("l", NewList(context.Background(), vs, Float(2), Float(3)))
// TODO(binformat)
s6 := NewStruct("", StructData{"l": NewList(context.Background(), Format_7_18, vs, Float(0), Float(1), Bool(false), Bool(true))})
s7 := s6.Set("l", NewList(context.Background(), Format_7_18, vs, Float(2), Float(3)))
t7 := MakeStructTypeFromFields("", FieldMap{
"l": MakeListType(FloaTType),
})
@@ -173,34 +174,44 @@ func TestStructDiff(t *testing.T) {
s1, NewStruct("NewType", StructData{"a": Bool(true), "c": Float(4), "d": Float(5)}))
s2 := NewStruct("", StructData{
"a": NewList(context.Background(), vs, Float(0), Float(1)),
// TODO(binformat)
"a": NewList(context.Background(), Format_7_18, vs, Float(0), Float(1)),
"b": NewMap(context.Background(), vs, String("foo"), Bool(false), String("bar"), Bool(true)),
"c": NewSet(context.Background(), vs, Float(0), Float(1), String("foo")),
})
assertDiff([]ValueChanged{},
s2, NewStruct("", StructData{
"a": NewList(context.Background(), vs, Float(0), Float(1)),
// TODO(binformat)
"a": NewList(context.Background(), Format_7_18, vs, Float(0), Float(1)),
"b": NewMap(context.Background(), vs, String("foo"), Bool(false), String("bar"), Bool(true)),
"c": NewSet(context.Background(), vs, Float(0), Float(1), String("foo")),
}))
assertDiff([]ValueChanged{
vc(DiffChangeModified, "a", NewList(context.Background(), vs, Float(1), Float(1)), NewList(context.Background(), vs, Float(0), Float(1))),
vc(DiffChangeModified, "b", NewMap(context.Background(), vs, String("foo"), Bool(true), String("bar"), Bool(true)), NewMap(context.Background(), vs, String("foo"), Bool(false), String("bar"), Bool(true))),
// TODO(binformat)
vc(DiffChangeModified, "a",
NewList(context.Background(), Format_7_18, vs, Float(1), Float(1)),
NewList(context.Background(), Format_7_18, vs, Float(0), Float(1))),
vc(DiffChangeModified, "b",
NewMap(context.Background(), vs, String("foo"), Bool(true), String("bar"), Bool(true)),
NewMap(context.Background(), vs, String("foo"), Bool(false), String("bar"), Bool(true))),
},
s2, NewStruct("", StructData{
"a": NewList(context.Background(), vs, Float(1), Float(1)),
// TODO(binformat)
"a": NewList(context.Background(), Format_7_18, vs, Float(1), Float(1)),
"b": NewMap(context.Background(), vs, String("foo"), Bool(true), String("bar"), Bool(true)),
"c": NewSet(context.Background(), vs, Float(0), Float(1), String("foo")),
}))
assertDiff([]ValueChanged{
vc(DiffChangeModified, "a", NewList(context.Background(), vs, Float(0)), NewList(context.Background(), vs, Float(0), Float(1))),
// TODO(binformat)
vc(DiffChangeModified, "a", NewList(context.Background(), Format_7_18, vs, Float(0)), NewList(context.Background(), Format_7_18, vs, Float(0), Float(1))),
vc(DiffChangeModified, "c", NewSet(context.Background(), vs, Float(0), Float(2), String("foo")), NewSet(context.Background(), vs, Float(0), Float(1), String("foo"))),
},
s2, NewStruct("", StructData{
"a": NewList(context.Background(), vs, Float(0)),
// TODO(binformat)
"a": NewList(context.Background(), Format_7_18, vs, Float(0)),
"b": NewMap(context.Background(), vs, String("foo"), Bool(false), String("bar"), Bool(true)),
"c": NewSet(context.Background(), vs, Float(0), Float(2), String("foo")),
}))
@@ -210,7 +221,8 @@ func TestStructDiff(t *testing.T) {
vc(DiffChangeModified, "c", NewSet(context.Background(), vs, Float(0), Float(1), String("bar")), NewSet(context.Background(), vs, Float(0), Float(1), String("foo"))),
},
s2, NewStruct("", StructData{
"a": NewList(context.Background(), vs, Float(0), Float(1)),
// TODO(binformat)
"a": NewList(context.Background(), Format_7_18, vs, Float(0), Float(1)),
"b": NewMap(context.Background(), vs, String("boo"), Bool(false), String("bar"), Bool(true)),
"c": NewSet(context.Background(), vs, Float(0), Float(1), String("bar")),
}))
+30 -19
View File
@@ -68,7 +68,8 @@ func TestAssertTypeValue(t *testing.T) {
assertSubtype(context.Background(), ValueType, Bool(true))
assertSubtype(context.Background(), ValueType, Float(1))
assertSubtype(context.Background(), ValueType, String("abc"))
l := NewList(context.Background(), vs, Float(0), Float(1), Float(2), Float(3))
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, vs, Float(0), Float(1), Float(2), Float(3))
assertSubtype(context.Background(), ValueType, l)
}
@@ -84,7 +85,8 @@ func TestAssertTypeList(tt *testing.T) {
vs := newTestValueStore()
listOfNumberType := MakeListType(FloaTType)
l := NewList(context.Background(), vs, Float(0), Float(1), Float(2), Float(3))
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, vs, Float(0), Float(1), Float(2), Float(3))
assertSubtype(context.Background(), listOfNumberType, l)
assertAll(tt, listOfNumberType, l)
assertSubtype(context.Background(), MakeListType(ValueType), l)
@@ -137,7 +139,8 @@ func TestAssertTypeUnion(tt *testing.T) {
assertSubtype(context.Background(), MakeUnionType(FloaTType, StringType, BoolType), Bool(true))
lt := MakeListType(MakeUnionType(FloaTType, StringType))
assertSubtype(context.Background(), lt, NewList(context.Background(), vs, Float(1), String("hi"), Float(2), String("bye")))
// TODO(binformat)
assertSubtype(context.Background(), lt, NewList(context.Background(), Format_7_18, vs, Float(1), String("hi"), Float(2), String("bye")))
st := MakeSetType(StringType)
assertSubtype(context.Background(), MakeUnionType(st, FloaTType), Float(42))
@@ -183,17 +186,20 @@ func TestAssertTypeEmptyListUnion(tt *testing.T) {
vs := newTestValueStore()
lt := MakeListType(MakeUnionType())
assertSubtype(context.Background(), lt, NewList(context.Background(), vs))
// TODO(binformat)
assertSubtype(context.Background(), lt, NewList(context.Background(), Format_7_18, vs))
}
func TestAssertTypeEmptyList(tt *testing.T) {
vs := newTestValueStore()
lt := MakeListType(FloaTType)
assertSubtype(context.Background(), lt, NewList(context.Background(), vs))
// TODO(binformat)
assertSubtype(context.Background(), lt, NewList(context.Background(), Format_7_18, vs))
// List<> not a subtype of List<Float>
assertInvalid(tt, MakeListType(MakeUnionType()), NewList(context.Background(), vs, Float(1)))
// TODO(binformat)
assertInvalid(tt, MakeListType(MakeUnionType()), NewList(context.Background(), Format_7_18, vs, Float(1)))
}
func TestAssertTypeEmptySet(tt *testing.T) {
@@ -552,7 +558,8 @@ func TestIsValueSubtypeOf(tt *testing.T) {
{String("s"), StringType},
{NewEmptyBlob(vs, Format_7_18), BlobType},
{BoolType, TypeType},
{NewList(context.Background(), vs, Float(42)), MakeListType(FloaTType)},
// TODO(binformat)
{NewList(context.Background(), Format_7_18, vs, Float(42)), MakeListType(FloaTType)},
{NewSet(context.Background(), vs, Float(42)), MakeSetType(FloaTType)},
{NewRef(Float(42)), MakeRefType(FloaTType)},
{NewMap(context.Background(), vs, Float(42), String("a")), MakeMapType(FloaTType, StringType)},
@@ -579,13 +586,14 @@ func TestIsValueSubtypeOf(tt *testing.T) {
assertFalse(String("abc"), MakeUnionType(BoolType, FloaTType))
assertFalse(String("abc"), MakeUnionType())
assertTrue(NewList(context.Background(), vs), MakeListType(FloaTType))
assertTrue(NewList(context.Background(), vs, Float(0), Float(1), Float(2), Float(3)), MakeListType(FloaTType))
assertFalse(NewList(context.Background(), vs, Float(0), Float(1), Float(2), Float(3)), MakeListType(BoolType))
assertTrue(NewList(context.Background(), vs, Float(0), Float(1), Float(2), Float(3)), MakeListType(MakeUnionType(FloaTType, BoolType)))
assertTrue(NewList(context.Background(), vs, Float(0), Bool(true)), MakeListType(MakeUnionType(FloaTType, BoolType)))
assertFalse(NewList(context.Background(), vs, Float(0)), MakeListType(MakeUnionType()))
assertTrue(NewList(context.Background(), vs), MakeListType(MakeUnionType()))
// TODO(binformat)
assertTrue(NewList(context.Background(), Format_7_18, vs), MakeListType(FloaTType))
assertTrue(NewList(context.Background(), Format_7_18, vs, Float(0), Float(1), Float(2), Float(3)), MakeListType(FloaTType))
assertFalse(NewList(context.Background(), Format_7_18, vs, Float(0), Float(1), Float(2), Float(3)), MakeListType(BoolType))
assertTrue(NewList(context.Background(), Format_7_18, vs, Float(0), Float(1), Float(2), Float(3)), MakeListType(MakeUnionType(FloaTType, BoolType)))
assertTrue(NewList(context.Background(), Format_7_18, vs, Float(0), Bool(true)), MakeListType(MakeUnionType(FloaTType, BoolType)))
assertFalse(NewList(context.Background(), Format_7_18, vs, Float(0)), MakeListType(MakeUnionType()))
assertTrue(NewList(context.Background(), Format_7_18, vs), MakeListType(MakeUnionType()))
{
newChunkedList := func(vals ...Value) List {
@@ -722,10 +730,11 @@ func TestIsValueSubtypeOf(tt *testing.T) {
assertTrue(
NewStruct("Node", StructData{
"value": Float(1),
"children": NewList(context.Background(), vs,
// TODO(binformat)
"children": NewList(context.Background(), Format_7_18, vs,
NewStruct("Node", StructData{
"value": Float(2),
"children": NewList(context.Background(), vs),
"children": NewList(context.Background(), Format_7_18, vs),
}),
),
}),
@@ -738,10 +747,11 @@ func TestIsValueSubtypeOf(tt *testing.T) {
assertFalse( // inner Node has wrong type.
NewStruct("Node", StructData{
"value": Float(1),
"children": NewList(context.Background(), vs,
// TODO(binformat)
"children": NewList(context.Background(), Format_7_18, vs,
NewStruct("Node", StructData{
"value": Bool(true),
"children": NewList(context.Background(), vs),
"children": NewList(context.Background(), Format_7_18, vs),
}),
),
}),
@@ -759,7 +769,8 @@ func TestIsValueSubtypeOf(tt *testing.T) {
}
rv := NewStruct("Node", StructData{
"value": value,
"children": NewList(context.Background(), vs, childrenAsRefs...),
// TODO(binformat)
"children": NewList(context.Background(), Format_7_18, vs, childrenAsRefs...),
})
return rv
}
+18 -9
View File
@@ -150,22 +150,26 @@ func TestFlushOrder(t *testing.T) {
n := Float(42)
sr, nr := vs.WriteValue(context.Background(), s), vs.WriteValue(context.Background(), n)
ccs.expect(sr, nr)
ml := NewList(context.Background(), vs, sr, nr)
// TODO(binformat)
ml := NewList(context.Background(), Format_7_18, vs, sr, nr)
// TODO(binformat)
b := NewEmptyBlob(vs, Format_7_18)
br, mlr := vs.WriteValue(context.Background(), b), vs.WriteValue(context.Background(), ml)
ccs.expect(br, mlr)
ml1 := NewList(context.Background(), vs, br, mlr)
// TODO(binformat)
ml1 := NewList(context.Background(), Format_7_18, vs, br, mlr)
f := Bool(false)
fr := vs.WriteValue(context.Background(), f)
ccs.expect(fr)
ml2 := NewList(context.Background(), vs, fr)
// TODO(binformat)
ml2 := NewList(context.Background(), Format_7_18, vs, fr)
ml1r, ml2r := vs.WriteValue(context.Background(), ml1), vs.WriteValue(context.Background(), ml2)
ccs.expect(ml1r, ml2r)
l := NewList(context.Background(), vs, ml1r, ml2r)
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, vs, ml1r, ml2r)
r := vs.WriteValue(context.Background(), l)
ccs.expect(r)
@@ -181,7 +185,8 @@ func TestFlushOverSize(t *testing.T) {
s := String("oy")
sr := vs.WriteValue(context.Background(), s)
ccs.expect(sr)
NewList(context.Background(), vs, sr) // will write the root chunk
// TODO(binformat)
NewList(context.Background(), Format_7_18, vs, sr) // will write the root chunk
}
func TestTolerateTopDown(t *testing.T) {
@@ -199,11 +204,13 @@ func TestTolerateTopDown(t *testing.T) {
sr := vs.WriteValue(context.Background(), S)
ccs.expect(sr)
ML := NewList(context.Background(), vs, sr)
// TODO(binformat)
ML := NewList(context.Background(), Format_7_18, vs, sr)
mlr := vs.WriteValue(context.Background(), ML)
ccs.expect(mlr)
L := NewList(context.Background(), vs, mlr)
// TODO(binformat)
L := NewList(context.Background(), Format_7_18, vs, mlr)
lr := vs.WriteValue(context.Background(), L)
ccs.expect(lr)
@@ -243,7 +250,8 @@ func TestPanicIfDangling(t *testing.T) {
vs := newTestValueStore()
r := NewRef(Bool(true))
l := NewList(context.Background(), vs, r)
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, vs, r)
vs.WriteValue(context.Background(), l)
assert.Panics(func() {
@@ -256,7 +264,8 @@ func TestSkipEnforceCompleteness(t *testing.T) {
vs.SetEnforceCompleteness(false)
r := NewRef(Bool(true))
l := NewList(context.Background(), vs, r)
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, vs, r)
vs.WriteValue(context.Background(), l)
vs.Commit(context.Background(), vs.Root(context.Background()), vs.Root(context.Background()))
+5 -3
View File
@@ -68,14 +68,16 @@ func TestWalkRefs(t *testing.T) {
r := rand.New(rand.NewSource(0))
t.Run("OfRefs", func(t *testing.T) {
l := NewList(context.Background(), vrw, vrw.WriteValue(context.Background(), Float(42)), vrw.WriteValue(context.Background(), Float(0)))
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, vrw, vrw.WriteValue(context.Background(), Float(42)), vrw.WriteValue(context.Background(), Float(0)))
runTest(l, t)
})
t.Run("Chunked", func(t *testing.T) {
l := NewList(context.Background(), vrw, newValueSlice(r)...)
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, vrw, newValueSlice(r)...)
for l.sequence.isLeaf() {
l = l.Concat(context.Background(), NewList(context.Background(), vrw, newValueSlice(r)...))
l = l.Concat(context.Background(), Format_7_18, NewList(context.Background(), Format_7_18, vrw, newValueSlice(r)...))
}
runTest(l, t)
})
+9 -5
View File
@@ -92,7 +92,8 @@ func (suite *WalkAllTestSuite) TestWalkMultilevelList() {
for i := 0; i < count; i++ {
nums[i] = Float(i)
}
l := NewList(context.Background(), suite.vs, nums...)
// TODO(binformat)
l := NewList(context.Background(), Format_7_18, suite.vs, nums...)
suite.True(NewRef(l).Height() > 1)
suite.assertCallbackCount(l, count+1)
@@ -171,7 +172,8 @@ func (suite *WalkTestSuite) skipWorker(composite Value) (reached ValueSlice) {
// Skipping a sub-tree must allow other items in the list to be processed.
func (suite *WalkTestSuite) TestSkipListElement() {
wholeList := NewList(context.Background(), suite.vs, suite.mustSkip, suite.shouldSee, suite.shouldSee)
// TODO(binformat)
wholeList := NewList(context.Background(), Format_7_18, suite.vs, suite.mustSkip, suite.shouldSee, suite.shouldSee)
reached := suite.skipWorker(wholeList)
for _, v := range []Value{wholeList, suite.mustSkip, suite.shouldSee, suite.shouldSeeItem} {
suite.True(reached.Contains(v), "Doesn't contain %+v", v)
@@ -209,7 +211,8 @@ func (suite *WalkTestSuite) TestSkipMapKey() {
}
func (suite *WalkAllTestSuite) NewList(vs ...Value) Ref {
v := NewList(context.Background(), suite.vs, vs...)
// TODO(binformat)
v := NewList(context.Background(), Format_7_18, suite.vs, vs...)
return suite.vs.WriteValue(context.Background(), v)
}
@@ -257,7 +260,8 @@ func (suite *WalkTestSuite) SetupTest() {
suite.ts = storage.NewView()
suite.vs = NewValueStore(suite.ts)
suite.shouldSeeItem = String("zzz")
suite.shouldSee = NewList(context.Background(), suite.vs, suite.shouldSeeItem)
// TODO(binformat)
suite.shouldSee = NewList(context.Background(), Format_7_18, suite.vs, suite.shouldSeeItem)
suite.deadValue = Float(0xDEADBEEF)
suite.mustSkip = NewList(context.Background(), suite.vs, suite.deadValue)
suite.mustSkip = NewList(context.Background(), Format_7_18, suite.vs, suite.deadValue)
}