Skip to content

Commit

Permalink
test: Test new BindingPath algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Feb 16, 2021
1 parent f331879 commit e3256b1
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 2 deletions.
104 changes: 104 additions & 0 deletions src/Uno.UI.Tests/BinderTests/Given_BindingPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Uno.UI.DataBinding;

Expand Down Expand Up @@ -156,6 +157,109 @@ public void When_Initially_Incorrect_DataContext()
Assert.AreEqual("Initial2", vm.Value);
}

[TestMethod]
public void When_Parse_SimpleProperty()
{
var sut = new BindingPath("hello_world", null);

var result = sut.GetPathItems().ToArray();

result.Length.Should().Be(1);
result[0].PropertyName.Should().Be("hello_world");
}

[TestMethod]
public void When_Parse_SimpleProperties()
{
var sut = new BindingPath("hello.world.bonjour.le.monde", null);

var result = sut.GetPathItems().ToArray();

result.Length.Should().Be(5);
result[0].PropertyName.Should().Be("hello");
result[1].PropertyName.Should().Be("world");
result[2].PropertyName.Should().Be("bonjour");
result[3].PropertyName.Should().Be("le");
result[4].PropertyName.Should().Be("monde");
}

[TestMethod]
public void When_Parse_AttachedProperty()
{
var sut = new BindingPath("(Grid.Column)", null);

var result = sut.GetPathItems().ToArray();

result.Length.Should().Be(1);
result[0].PropertyName.Should().Be("Grid.Column");
}

[TestMethod]
public void When_Parse_AttachedProperties()
{
var sut = new BindingPath("(hello.world).(bonjour:le.monde)", null);

var result = sut.GetPathItems().ToArray();

result.Length.Should().Be(2);
result[0].PropertyName.Should().Be("hello.world");
result[1].PropertyName.Should().Be("bonjour:le.monde");
}

[TestMethod]
public void When_Parse_Indexer()
{
var sut = new BindingPath("[hello_world]", null);

var result = sut.GetPathItems().ToArray();

result.Length.Should().Be(1);
result[0].PropertyName.Should().Be("[hello_world]");
}

[TestMethod]
public void When_Parse_Indexers()
{
var sut = new BindingPath("[hello][world][bonjour][le][monde]", null);

var result = sut.GetPathItems().ToArray();

result.Length.Should().Be(5);
result[0].PropertyName.Should().Be("[hello]");
result[1].PropertyName.Should().Be("[world]");
result[2].PropertyName.Should().Be("[bonjour]");
result[3].PropertyName.Should().Be("[le]");
result[4].PropertyName.Should().Be("[monde]");
}

[TestMethod]
public void When_Parse_ComplexPath()
{
var sut = new BindingPath("hello[world](bonjour:le.monde).value", null);

var result = sut.GetPathItems().ToArray();

result.Length.Should().Be(4);
result[0].PropertyName.Should().Be("hello");
result[1].PropertyName.Should().Be("[world]");
result[2].PropertyName.Should().Be("bonjour:le.monde");
result[3].PropertyName.Should().Be("value");
}

[TestMethod]
public void When_Parse_TrimItemPath()
{
var sut = new BindingPath(" hello [world ]( bonjour:le.monde ).value ", null);

var result = sut.GetPathItems().ToArray();

result.Length.Should().Be(4);
result[0].PropertyName.Should().Be("hello");
result[1].PropertyName.Should().Be("[world ]");
result[2].PropertyName.Should().Be("bonjour:le.monde");
result[3].PropertyName.Should().Be("value");
}

private static (MyTarget target, BindingPath binding) Arrange(DependencyPropertyValuePrecedences? precedence = null)
{
var target = new MyTarget();
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.UI/DataBinding/BindingPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ private static void Parse(
break;

case '[' when isInItemIndex:
// Note: We use 'start = i' here for 'TryPrependItem' as we include the brackets for itemIndex properties
TryPrependItem(path, i, propertyLength, fallbackValue, precedence, allowPrivateMembers, ref head, ref tail);
// Note: We use 'start = i' and '++propertyLength' here for 'TryPrependItem' as we include the brackets for itemIndex properties
TryPrependItem(path, i, ++propertyLength, fallbackValue, precedence, allowPrivateMembers, ref head, ref tail);
isInItemIndex = false;
propertyLength = 0;
break;
Expand Down

0 comments on commit e3256b1

Please sign in to comment.