func (suite *DatabaseSuite) TestReadWriteCache() { var v types.Value = types.Bool(true) suite.NotEqual(hash.Hash{}, suite.ds.WriteValue(v)) r := suite.ds.WriteValue(v).TargetHash() commit := NewCommit(v, types.NewSet(), types.EmptyStruct) newDs, err := suite.ds.Commit("foo", commit) suite.NoError(err) suite.Equal(1, suite.cs.Writes-writesOnCommit) v = newDs.ReadValue(r) suite.True(v.Equals(types.Bool(true))) }
func diffSummary(ch chan diffSummaryProgress, v1, v2 types.Value) { if !v1.Equals(v2) { if shouldDescend(v1, v2) { switch v1.Type().Kind() { case types.ListKind: diffSummaryList(ch, v1.(types.List), v2.(types.List)) case types.MapKind: diffSummaryMap(ch, v1.(types.Map), v2.(types.Map)) case types.SetKind: diffSummarySet(ch, v1.(types.Set), v2.(types.Set)) case types.StructKind: diffSummaryStructs(ch, v1.(types.Struct), v2.(types.Struct)) default: panic("Unrecognized type in diff function: " + v1.Type().Describe() + " and " + v2.Type().Describe()) } } else { ch <- diffSummaryProgress{Adds: 1, Removes: 1, NewSize: 1, OldSize: 1} } } }
func diff(w io.Writer, p types.Path, key, v1, v2 types.Value) { if !v1.Equals(v2) { if shouldDescend(v1, v2) { switch v1.Type().Kind() { case types.ListKind: diffLists(w, p, v1.(types.List), v2.(types.List)) case types.MapKind: diffMaps(w, p, v1.(types.Map), v2.(types.Map)) case types.SetKind: diffSets(w, p, v1.(types.Set), v2.(types.Set)) case types.StructKind: diffStructs(w, p, v1.(types.Struct), v2.(types.Struct)) default: panic("Unrecognized type in diff function") } } else { line(w, DEL, key, v1) line(w, ADD, key, v2) } } }
func Diff(w io.Writer, v1, v2 types.Value) (err error) { dq := NewDiffQueue() di := diffInfo{path: types.NewPath().AddField("/"), v1: v1, v2: v2} dq.PushBack(di) err = d.Try(func() { for di, ok := dq.PopFront(); ok; di, ok = dq.PopFront() { p, key, v1, v2 := di.path, di.key, di.v1, di.v2 v1.Type().Kind() if v1 == nil && v2 != nil { line(w, addPrefix, key, v2) } if v1 != nil && v2 == nil { line(w, subPrefix, key, v1) } if !v1.Equals(v2) { if !canCompare(v1, v2) { line(w, subPrefix, key, v1) line(w, addPrefix, key, v2) } else { switch v1.Type().Kind() { case types.ListKind: diffLists(dq, w, p, v1.(types.List), v2.(types.List)) case types.MapKind: diffMaps(dq, w, p, v1.(types.Map), v2.(types.Map)) case types.SetKind: diffSets(dq, w, p, v1.(types.Set), v2.(types.Set)) case types.StructKind: diffStructs(dq, w, p, v1.(types.Struct), v2.(types.Struct)) default: panic("Unrecognized type in diff function") } } } } }) return }