Skip to content

Commit

Permalink
test(sticky-index): introduce tests for Decode()
Browse files Browse the repository at this point in the history
  • Loading branch information
LSViana committed Sep 13, 2023
1 parent f9b6625 commit 0378b11
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Tests/YDotNet.Tests.Unit/StickyIndexes/DecodeTests.cs
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));
}
}

0 comments on commit 0378b11

Please sign in to comment.