Browse Source
Merge branch 'master' into fixes/1558-getposition-transform
pull/2342/head
Steven Kirk
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
59 additions and
0 deletions
-
src/Markup/Avalonia.Markup/Markup/Parsers/ExpressionParser.cs
-
tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs
-
tests/Avalonia.Markup.UnitTests/Parsers/ExpressionNodeBuilderTests.cs
-
tests/Avalonia.Markup.UnitTests/Parsers/ExpressionNodeBuilderTests_Errors.cs
|
|
|
@ -106,6 +106,11 @@ namespace Avalonia.Markup.Parsers |
|
|
|
{ |
|
|
|
return State.Indexer; |
|
|
|
} |
|
|
|
else if (ParseDot(ref r)) |
|
|
|
{ |
|
|
|
nodes.Add(new EmptyExpressionNode()); |
|
|
|
return State.End; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var identifier = r.ParseIdentifier(); |
|
|
|
@ -317,6 +322,11 @@ namespace Avalonia.Markup.Parsers |
|
|
|
return !r.End && r.TakeIf('#'); |
|
|
|
} |
|
|
|
|
|
|
|
private static bool ParseDot(ref CharacterReader r) |
|
|
|
{ |
|
|
|
return !r.End && r.TakeIf('.'); |
|
|
|
} |
|
|
|
|
|
|
|
private enum State |
|
|
|
{ |
|
|
|
Start, |
|
|
|
|
|
|
|
@ -273,6 +273,39 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
|
Assert.Equal(42, target.Value); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Null_Path_Should_Bind_To_DataContext() |
|
|
|
{ |
|
|
|
var target = new TextBlock { DataContext = "foo" }; |
|
|
|
var binding = new Binding(); |
|
|
|
|
|
|
|
target.Bind(TextBlock.TextProperty, binding); |
|
|
|
|
|
|
|
Assert.Equal("foo", target.Text); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Empty_Path_Should_Bind_To_DataContext() |
|
|
|
{ |
|
|
|
var target = new TextBlock { DataContext = "foo" }; |
|
|
|
var binding = new Binding { Path = string.Empty }; |
|
|
|
|
|
|
|
target.Bind(TextBlock.TextProperty, binding); |
|
|
|
|
|
|
|
Assert.Equal("foo", target.Text); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Dot_Path_Should_Bind_To_DataContext() |
|
|
|
{ |
|
|
|
var target = new TextBlock { DataContext = "foo" }; |
|
|
|
var binding = new Binding { Path = "." }; |
|
|
|
|
|
|
|
target.Bind(TextBlock.TextProperty, binding); |
|
|
|
|
|
|
|
Assert.Equal("foo", target.Text); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Tests a problem discovered with ListBox with selection.
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
@ -36,6 +36,15 @@ namespace Avalonia.Markup.UnitTests.Parsers |
|
|
|
AssertIsProperty(result[0], "F0o"); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Build_Dot() |
|
|
|
{ |
|
|
|
var result = ToList(ExpressionObserverBuilder.Parse(".")); |
|
|
|
|
|
|
|
Assert.Equal(1, result.Count); |
|
|
|
Assert.IsType<EmptyExpressionNode>(result[0]); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Build_Property_Chain() |
|
|
|
{ |
|
|
|
|
|
|
|
@ -30,6 +30,13 @@ namespace Avalonia.Markup.UnitTests.Parsers |
|
|
|
() => ExpressionObserverBuilder.Parse("Foo.Bar.")); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Expression_Cannot_Start_With_Period_Then_Token() |
|
|
|
{ |
|
|
|
Assert.Throws<ExpressionParseException>( |
|
|
|
() => ExpressionObserverBuilder.Parse(".Bar")); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Expression_Cannot_Have_Empty_Indexer() |
|
|
|
{ |
|
|
|
|