X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/baf7a940be8927278e3b4b87e7366cebfc16532f..b473b56ebf00e6b4d6cf16664f93e1958fbe2080:/view_test.go diff --git a/view_test.go b/view_test.go index 39c8e11..46f76da 100644 --- a/view_test.go +++ b/view_test.go @@ -10,8 +10,11 @@ import ( func TestViewMergesInTheOrderOfTheRollbackPush(t *testing.T) { tree := ViewBuiltTree{} + view := newView(0, 0) + var states *ViewPushEntry + for tick := range 20001 { states = viewPush(tick, states) starts := states.starts() @@ -31,11 +34,13 @@ func TestViewMergesInTheOrderOfTheRollbackPush(t *testing.T) { func TestViewMergesInOneBatchFromHighToLow(t *testing.T) { tree := ViewBuiltTree{} + view := newView(10, 5) sizes := make([]int, 0, 20) for range 20 { _, err := view.Append(tree) require.NoError(t, err) + sizes = append(sizes, view.Size()) } @@ -144,7 +149,7 @@ func TestRestoreViewRejectsAGap(t *testing.T) { // ViewBuiltTree is a tree with each node built, with 1 byte of text. type ViewBuiltTree struct{} -func (ViewBuiltTree) Built(level, index int) (bool, error) { +func (v ViewBuiltTree) Built(_, _ int) (bool, error) { return true, nil } @@ -164,6 +169,7 @@ type ViewPushEntry struct { // starts returns the states of the list, oldest first. func (e *ViewPushEntry) starts() []int { var starts []int + for entry := e; entry != nil; entry = entry.older { starts = append(starts, entry.state) } @@ -197,7 +203,11 @@ func (p ViewPartTree) Node(level, index int) (Node, bool, error) { return treeTestNode(level, index, text), true, nil } -// viewPush is the push of rollback_state_list.js. +// viewPush adds state to the newest end of states and returns the new list. An +// empty list gets one entry. When the newest entry is not kept, it becomes kept +// with its own state, and state is dropped. When it is kept, state becomes a +// new newest entry, and the state of the old newest entry goes to the older +// entries by the same push. func viewPush(state int, states *ViewPushEntry) *ViewPushEntry { if states == nil { return &ViewPushEntry{