Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update core bindings to Yrs v0.18 #94

Merged
merged 75 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
e3ed5e9
feat: introduce `SubscriptionChannel` to bind `yunobserve()`
LSViana Mar 15, 2024
117872e
feat: update `EventSubscriber` to match `SubscriptionChannel.Unobserv…
LSViana Mar 15, 2024
c375712
feat: update `Array` to use `SubscriptionChannel.Unobserve`
LSViana Mar 15, 2024
aa521ee
feat: update `Branch` to use `SubscriptionChannel.Unobserve`
LSViana Mar 15, 2024
1ff4382
feat: update `Map` to use `SubscriptionChannel.Unobserve`
LSViana Mar 15, 2024
f67d5ca
feat: update `Text` to use `SubscriptionChannel.Unobserve`
LSViana Mar 15, 2024
1f70710
feat: update `XmlElement` to use `SubscriptionChannel.Unobserve`
LSViana Mar 15, 2024
81baa39
feat: update `XmlText` to use `SubscriptionChannel.Unobserve`
LSViana Mar 15, 2024
8efa594
feat: update `UndoManager` to use `SubscriptionChannel.Unobserve`
LSViana Mar 15, 2024
9efa7a6
feat: update `Doc` to use `SubscriptionChannel.Unobserve`
LSViana Mar 15, 2024
1f9415d
test: dispose subscription on tests for `Text.ObserveDeep()`
LSViana Mar 15, 2024
e99603c
style: fix access modifier order in `Branch`
LSViana Mar 15, 2024
fbc9c06
fix: remove unnecessary null conditional operator from `XmlText.Forma…
LSViana Mar 15, 2024
5567037
feat: add the `OutputTag.XmlFragment` constant
LSViana Mar 17, 2024
27e516c
feat: update `EventBranchTag` to include `XmlFragment` and synchroniz…
LSViana Mar 17, 2024
55c6481
feat: synchronize `BranchKind` with `OutputTag`
LSViana Mar 17, 2024
83aae2d
feat: introduce `XmlFragment` and `XmlFragmentEvent`
LSViana Mar 17, 2024
84a04fb
feat: update `XmlElement` and `XmlElementEvent` to inherit from their…
LSViana Mar 17, 2024
90a9a2e
feat: update `Doc` and `DocChannel` to only allow getting root-level …
LSViana Mar 17, 2024
1be876a
feat: update `Transaction` to only allow getting root-level `XmlFragm…
LSViana Mar 17, 2024
7ef9c0d
feat: update `EventBranch` to expose `XmlFragmentEvent`
LSViana Mar 17, 2024
fa0c563
test: update existing unit tests to use root-level `XmlFragment` when…
LSViana Mar 17, 2024
fee50a1
test: introduce unit tests for `XmlFragment`
LSViana Mar 17, 2024
0c4fee3
test: introduce unit tests for `ObserveDeep()` in `XmlFragment`
LSViana Mar 17, 2024
b3ebc36
feat: use exact type comparison to prevent inheritance from allowing …
LSViana Mar 20, 2024
77173f7
feat: drop `BranchChannel.WriteTransaction()`
LSViana Mar 21, 2024
88c8a9e
feat: update `Branch.WriteTransaction()` to use `Doc.WriteTransaction()`
LSViana Mar 21, 2024
a7a70fd
chore: fix typos in `Branch` and `Doc`
LSViana Mar 21, 2024
8d4299f
feat: drop `BranchChannel.ReadTransaction()`
LSViana Mar 21, 2024
98ac727
feat: update `Branch.ReadTransaction()` to use `Doc.ReadTransaction()`
LSViana Mar 21, 2024
b82e13b
feat: update `XmlElement.Parent()` to only return a value if the pare…
LSViana Mar 21, 2024
08b7c5a
test: fix unit tests of `XmlFragment.ObserveDeep()`
LSViana Mar 21, 2024
4cb5cdc
feat: introduce `BranchIdNative*` structs
LSViana Mar 23, 2024
a4bd1ab
feat: introduce `BranchChannel.Id()`
LSViana Mar 23, 2024
85a8c02
feat: introduce `BranchId` class
LSViana Mar 23, 2024
4fa7656
feat: introduce `Branch.Id()` method
LSViana Mar 23, 2024
8e27e88
test: introduce tests for `Branch.Id()`
LSViana Mar 23, 2024
67d0409
feat: drop `BranchId.Length` and rename `HasLengthAndName` to `HasName`
LSViana Mar 23, 2024
80bcf59
docs: add documentation for `BranchId` class and properties
LSViana Mar 23, 2024
aeb97d3
docs: add documentation for `Branch.Id()`
LSViana Mar 23, 2024
30e19c0
test: update unit tests of `Branch.Id()` after API changes on `BranchId`
LSViana Mar 23, 2024
241b8d4
feat: adjust `BranchId` to store a reference to the related `Doc`
LSViana Mar 23, 2024
ffff081
feat: introduce `BranchId.Get()` and `Get()` and `Alive()` in `Branch…
LSViana Mar 23, 2024
97d5cf9
test: introduce tests for `BranchId.Get()`
LSViana Mar 23, 2024
42a989f
feat: introduce `Branch.Alive()`
LSViana Mar 23, 2024
a78770b
test: introduce tests for `Branch.Alive()`
LSViana Mar 23, 2024
94dc35c
revert: use constant numbers in `BranchKind`
LSViana Mar 26, 2024
76cfddc
style: format `Transaction`
LSViana Mar 26, 2024
bdc8975
Test change.
SebastianStehle Apr 14, 2024
a8e313f
feat: remove unused tests and classes
LSViana Apr 24, 2024
4f37b4a
feat: update `Branch` to hold a `BranchIdNative` and expose the `GetH…
LSViana Apr 24, 2024
bc8846d
test: update unit tests to adapt to the new API of `Array.Length()`
LSViana Apr 24, 2024
7a7c2bc
style: inline usages of `GetHandle()` in `Array`
LSViana May 1, 2024
c025081
style: update accessors and code style in `UnmanagedResource`
LSViana May 1, 2024
e3002cb
feat: replace `this.Handle` with `this.GetHandle()` in `Map`
LSViana May 1, 2024
0c810bc
chore: update the demo code to match the new API of `Array`
LSViana May 1, 2024
5a6c00d
feat: replace `this.Handle` with `this.GetHandle()` in `Text`
LSViana May 1, 2024
ebcefa7
fix: use correct handle when reading `XmlTextEvent.Target`
LSViana May 1, 2024
5c8a156
feat: replace `this.Handle` with `this.GetHandle()` in `XmlElement`
LSViana May 1, 2024
4e40f96
feat: replace `this.Handle` with `this.GetHandle()` in `XmlFragment`
LSViana May 1, 2024
02a3120
feat: replace `this.Handle` with `this.GetHandle()` in `XmlText`
LSViana May 1, 2024
f4cb4d3
style: format `Branch` and `UnmanagedResource`
LSViana May 1, 2024
d2499f5
test: update unit tests after migrating `Branch` types to `GetHandle()`
LSViana May 1, 2024
fdef318
test: fix tests for `Doc.ReadTransaction()`
LSViana May 1, 2024
dadf019
feat: drop `Insertions` and `Deletions` from `UndoEvent` and `UndoEve…
LSViana May 1, 2024
0658f50
test: fix tests for `ObserveAdded()` and `ObservePopped()` of `UndoMa…
LSViana May 1, 2024
4792552
ci: fix build patch
LSViana May 1, 2024
33a37b5
ci: fix matrix definition for macOS x86
LSViana May 1, 2024
3deb5d5
feat: replace `EventSubscriber` with `EventSubscriberFromId` in `Map`…
LSViana May 13, 2024
9d88a19
style: use `default` instead of `null` when fetching the `BranchId`
LSViana May 13, 2024
9298507
feat: make `Branch.BranchId` a `private` property
LSViana May 13, 2024
d3e35ce
feat: apply `using` to make the scope of `handle` clearer in `Branch.…
LSViana May 13, 2024
93ff21b
chore: fix warnings throughout the project
LSViana Jun 6, 2024
fb8af80
test: fix unit tests that used `Transaction` incorrectly
LSViana Jun 7, 2024
ba69d10
chore: fix typo in comments of `Transaction.Commit()`
LSViana Jun 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Tests/YDotNet.Tests.Unit/Branches/AliveTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using NUnit.Framework;
using YDotNet.Document;

namespace YDotNet.Tests.Unit.Branches;

public class AliveTests
{
[Test]
public void ReturnsTrueWhenAlive()
{
// Arrange
var doc = new Doc();
var text = doc.Text("text");

// Act
var alive = text.Alive();

// Assert
Assert.That(alive, Is.True);
}

[Test]
[Ignore("TODO: Check how to mark a Branch as deleted.")]
public void ReturnsFalseWhenNotAlive()
{
}
}
33 changes: 33 additions & 0 deletions Tests/YDotNet.Tests.Unit/Branches/BranchId/GetTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using NUnit.Framework;
using YDotNet.Document;
using YDotNet.Document.Types.Texts;

namespace YDotNet.Tests.Unit.Branches.BranchId;

public class GetTests
{
[Test]
public void ReturnsTheCorrectBranchWhenAlive()
{
// Arrange
var doc = new Doc();
var branch = doc.Text("text");
var branchId = branch.Id();

// Act
var transaction = doc.ReadTransaction();
var newBranch = branchId.Get(transaction);
transaction.Commit();

// Assert
Assert.That(newBranch, Is.Not.Null);
Assert.That(newBranch, Is.TypeOf<Text>());
Assert.That(newBranch, Is.EqualTo(branch));
}

[Test]
[Ignore("TODO: Check how to mark a Branch as deleted.")]
public void ReturnsTheCorrectBranchWhenNotAlive()
{
}
}
74 changes: 74 additions & 0 deletions Tests/YDotNet.Tests.Unit/Branches/IdTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using NUnit.Framework;
using YDotNet.Document;
using YDotNet.Document.Cells;
using YDotNet.Document.Options;
using YDotNet.Document.Types.Branches;

namespace YDotNet.Tests.Unit.Branches;

public class IdTests
{
[Test]
public void ReturnsIdForRootLevelType()
{
// Arrange
var doc = new Doc();
var branch = doc.Text("text");

// Act
var id = branch.Id();

// Assert
Assert.That(id, Is.Not.Null);
Assert.That(id.HasName, Is.True);
Assert.That(id.HasClientIdAndClock, Is.False);
Assert.That(id.Name, Is.EqualTo("text"));
Assert.That(id.ClientId, Is.EqualTo(expected: null));
Assert.That(id.Clock, Is.EqualTo(expected: null));
}

[Test]
public void ReturnsIdForNestedType()
{
// Arrange
var doc = new Doc(
new DocOptions
{
Id = 37
});
var map = doc.Map("map");

var transaction = map.WriteTransaction();
map.Insert(transaction, "text", Input.Text(""));
Branch branch = map.Get(transaction, "text")!.Text;
transaction.Commit();

// Act
var id = branch.Id();

// Assert
Assert.That(id, Is.Not.Null);
Assert.That(id.HasName, Is.False);
Assert.That(id.HasClientIdAndClock, Is.True);
Assert.That(id.Name, Is.Null);
Assert.That(id.ClientId, Is.EqualTo(expected: 37));
Assert.That(id.Clock, Is.EqualTo(expected: 0));

// Arrange
transaction = map.WriteTransaction();
map.Insert(transaction, "array", Input.Array(Array.Empty<Input>()));
branch = map.Get(transaction, "array")!.Array;
transaction.Commit();

// Act
id = branch.Id();

// Assert
Assert.That(id, Is.Not.Null);
Assert.That(id.HasName, Is.False);
Assert.That(id.HasClientIdAndClock, Is.True);
Assert.That(id.Name, Is.Null);
Assert.That(id.ClientId, Is.EqualTo(expected: 37));
Assert.That(id.Clock, Is.EqualTo(expected: 1));
}
}
22 changes: 4 additions & 18 deletions Tests/YDotNet.Tests.Unit/Branches/ReadTransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void StartReadTransactionWhileWriteTransactionIsOpen()
{
// Arrange
var doc = new Doc();
Branch branch = doc.XmlElement("branch");
Branch branch = doc.XmlFragment("branch");

// Act
var writeTransaction = branch.WriteTransaction();
Expand All @@ -72,7 +72,7 @@ public void StartReadTransactionWhileDocumentWriteTransactionIsOpen()
{
// Arrange
var doc = new Doc();
Branch branch = doc.XmlText("branch");
Branch branch = doc.XmlFragment("branch");

// Act
var documentTransaction = doc.WriteTransaction();
Expand Down Expand Up @@ -125,7 +125,7 @@ public void GetRootTextWithOpenTransactionNotAllowed()
}

[Test]
public void GetRootXmlTextWithOpenTransactionNotAllowed()
public void GetRootXmlFragmentWithOpenTransactionNotAllowed()
{
// Arrange
var doc = new Doc();
Expand All @@ -135,20 +135,6 @@ public void GetRootXmlTextWithOpenTransactionNotAllowed()
map.Length(map.ReadTransaction());

// Assert
Assert.Throws<YDotNetException>(() => doc.XmlText("XmlText"));
}

[Test]
public void GetRootXmlElementWithOpenTransactionNotAllowed()
{
// Arrange
var doc = new Doc();
var map = doc.Map("Map");

// Keep the transaction open.
map.Length(map.ReadTransaction());

// Assert
Assert.Throws<YDotNetException>(() => doc.XmlElement("XmlElement"));
Assert.Throws<YDotNetException>(() => doc.XmlFragment("xml-fragment"));
}
}
3 changes: 3 additions & 0 deletions Tests/YDotNet.Tests.Unit/Branches/TextObserveDeepTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,8 @@ public void ObserveDeepHasPathWhenAdded()

// Assert
Assert.That(pathSegments.Count(), Is.EqualTo(expected: 1));

// Act
subscription.Dispose();
}
}
18 changes: 2 additions & 16 deletions Tests/YDotNet.Tests.Unit/Branches/WriteTransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void GetRootTextWithOpenTransactionNotAllowed()
}

[Test]
public void GetRootXmlTextWithOpenTransactionNotAllowed()
public void GetRootXmlFragmentWithOpenTransactionNotAllowed()
{
// Arrange
var doc = new Doc();
Expand All @@ -133,20 +133,6 @@ public void GetRootXmlTextWithOpenTransactionNotAllowed()
map.Length(map.WriteTransaction());

// Assert
Assert.Throws<YDotNetException>(() => doc.XmlText("XmlText"));
}

[Test]
public void GetRootXmlElementWithOpenTransactionNotAllowed()
{
// Arrange
var doc = new Doc();
var map = doc.Map("Map");

// Keep the transaction open.
map.Length(map.WriteTransaction());

// Assert
Assert.Throws<YDotNetException>(() => doc.XmlElement("XmlElement"));
Assert.Throws<YDotNetException>(() => doc.XmlFragment("xml-fragment"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,13 @@ public void ObserveDeepHasPathWhenRemovedAttributes()
private (Doc, XmlElement, XmlElement, XmlElement) ArrangeDoc()
{
var doc = new Doc();
var xmlElement1 = doc.XmlElement("xml-element-1");
var xmlFragment = doc.XmlFragment("xml-fragment");

var transaction = doc.WriteTransaction();
var xmlElement1 = xmlFragment.InsertElement(transaction, index: 0, "xml-element-1");
transaction.Commit();

transaction = doc.WriteTransaction();
xmlElement1.InsertText(transaction, index: 0);
xmlElement1.InsertText(transaction, index: 1);
var xmlElement2 = xmlElement1.InsertElement(transaction, index: 2, "xml-element-2");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using NUnit.Framework;
using YDotNet.Document;
using YDotNet.Document.Cells;

namespace YDotNet.Tests.Unit.Branches;

Expand All @@ -10,12 +11,18 @@ public void TriggersWhenMapChangedUntilUnobserved()
{
// Arrange
var doc = new Doc();
var xmlElement = doc.XmlElement("xml-element");
var map = doc.Map("map");

var transaction = doc.WriteTransaction();
map.Insert(transaction, "xml-element", Input.XmlElement("xml-element"));
var xmlElement = map.Get(transaction, "xml-element").XmlElement;
transaction.Commit();

var called = 0;
var subscription = xmlElement.ObserveDeep(_ => called++);

// Act
var transaction = doc.WriteTransaction();
transaction = doc.WriteTransaction();
xmlElement.InsertText(transaction, index: 0);
transaction.Commit();

Expand Down
Loading