-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(sticky-index): introduce tests for Decode()
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using NUnit.Framework; | ||
using YDotNet.Document; | ||
using YDotNet.Document.Options; | ||
using YDotNet.Document.StickyIndexes; | ||
|
||
namespace YDotNet.Tests.Unit.StickyIndexes; | ||
|
||
public class DecodeTests | ||
{ | ||
[Test] | ||
public void DecodesFromEmptyValue() | ||
{ | ||
// Arrange | ||
var doc = new Doc( | ||
new DocOptions | ||
{ | ||
Id = 91 | ||
}); | ||
var text = doc.Text("text"); | ||
|
||
var transaction = doc.WriteTransaction(); | ||
var stickyIndex = text.StickyIndex(transaction, index: 0, StickyAssociationType.Before); | ||
transaction.Commit(); | ||
|
||
// Act | ||
transaction = doc.WriteTransaction(); | ||
var decodedStickyIndex = StickyIndex.Decode(stickyIndex.Encode()); | ||
var index = decodedStickyIndex?.Read(transaction); | ||
transaction.Commit(); | ||
|
||
// Assert | ||
Assert.That(decodedStickyIndex, Is.Not.Null); | ||
Assert.That(index, Is.EqualTo(expected: 0)); | ||
} | ||
|
||
[Test] | ||
public void DecodesOnFilledValue() | ||
{ | ||
// Arrange | ||
var doc = new Doc( | ||
new DocOptions | ||
{ | ||
Id = 73 | ||
}); | ||
var text = doc.Text("text"); | ||
|
||
var transaction = doc.WriteTransaction(); | ||
text.Insert(transaction, index: 0, "Lucas"); | ||
var stickyIndex = text.StickyIndex(transaction, index: 3, StickyAssociationType.Before); | ||
transaction.Commit(); | ||
|
||
// Act | ||
transaction = doc.WriteTransaction(); | ||
var decodedStickyIndex = StickyIndex.Decode(stickyIndex.Encode()); | ||
var index = decodedStickyIndex?.Read(transaction); | ||
transaction.Commit(); | ||
|
||
// Assert | ||
Assert.That(decodedStickyIndex, Is.Not.Null); | ||
Assert.That(index, Is.EqualTo(expected: 3)); | ||
} | ||
} |