-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove panic from crdt.RGATreeList (#596)
- Loading branch information
Showing
13 changed files
with
166 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package crdt_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/yorkie-team/yorkie/pkg/document/crdt" | ||
"github.com/yorkie-team/yorkie/test/helper" | ||
) | ||
|
||
func TestRGATreeList(t *testing.T) { | ||
t.Run("rga_tree_list operations test", func(t *testing.T) { | ||
root := helper.TestRoot() | ||
ctx := helper.TextChangeContext(root) | ||
|
||
elements := crdt.NewRGATreeList() | ||
|
||
var err error | ||
for _, v := range []string{"1", "2", "3"} { | ||
err = elements.Add(crdt.NewPrimitive(v, ctx.IssueTimeTicket())) | ||
assert.NoError(t, err) | ||
} | ||
assert.Equal(t, `["1","2","3"]`, elements.Marshal()) | ||
|
||
nodes := elements.Nodes() | ||
assert.Equal(t, len(nodes), 3) | ||
|
||
targetElement, err := elements.Get(1) | ||
assert.NoError(t, err) | ||
assert.Equal(t, `"2"`, targetElement.Element().Marshal()) | ||
|
||
prevCreatedAt, err := elements.FindPrevCreatedAt(targetElement.CreatedAt()) | ||
assert.NoError(t, err) | ||
assert.Equal(t, prevCreatedAt.Compare(targetElement.CreatedAt()), -1) | ||
|
||
err = elements.MoveAfter(targetElement.CreatedAt(), prevCreatedAt, ctx.IssueTimeTicket()) | ||
assert.NoError(t, err) | ||
assert.Equal(t, `["2","1","3"]`, elements.Marshal()) | ||
|
||
_, err = elements.DeleteByCreatedAt(targetElement.CreatedAt(), ctx.IssueTimeTicket()) | ||
assert.NoError(t, err) | ||
assert.Equal(t, `["1","3"]`, elements.Marshal()) | ||
|
||
_, err = elements.Delete(1, ctx.IssueTimeTicket()) | ||
assert.NoError(t, err) | ||
assert.Equal(t, `["1"]`, elements.Marshal()) | ||
|
||
}) | ||
|
||
t.Run("invalid createdAt test", func(t *testing.T) { | ||
root := helper.TestRoot() | ||
ctx := helper.TextChangeContext(root) | ||
|
||
validCreatedAt, invalidCreatedAt := ctx.IssueTimeTicket(), ctx.IssueTimeTicket() | ||
elements := crdt.NewRGATreeList() | ||
err := elements.Add(crdt.NewPrimitive("1", validCreatedAt)) | ||
assert.NoError(t, err) | ||
|
||
_, err = elements.DeleteByCreatedAt(invalidCreatedAt, ctx.IssueTimeTicket()) | ||
assert.ErrorIs(t, err, crdt.ErrChildNotFound) | ||
|
||
err = elements.MoveAfter(validCreatedAt, invalidCreatedAt, ctx.IssueTimeTicket()) | ||
assert.ErrorIs(t, err, crdt.ErrChildNotFound) | ||
|
||
err = elements.MoveAfter(invalidCreatedAt, validCreatedAt, ctx.IssueTimeTicket()) | ||
assert.ErrorIs(t, err, crdt.ErrChildNotFound) | ||
|
||
_, err = elements.FindPrevCreatedAt(invalidCreatedAt) | ||
assert.ErrorIs(t, err, crdt.ErrChildNotFound) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.