|
|
@@ -9,7 +9,7 @@ namespace Avalonia.Base.UnitTests.Styling
|
|
|
public class SelectorTests_Nesting
|
|
|
{
|
|
|
[Fact]
|
|
|
- public void Parent_Selector_Doesnt_Match_OfType()
|
|
|
+ public void Nesting_Class_Doesnt_Match_Parent_Selector()
|
|
|
{
|
|
|
var control = new Control2();
|
|
|
Style nested;
|
|
|
@@ -26,43 +26,50 @@ namespace Avalonia.Base.UnitTests.Styling
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
- public void Nested_Class_Selector()
|
|
|
+ public void Or_Nesting_Class_Doesnt_Match_Parent_Selector()
|
|
|
{
|
|
|
- var control = new Control1 { Classes = { "foo" } };
|
|
|
+ var control = new Control2();
|
|
|
Style nested;
|
|
|
var parent = new Style(x => x.OfType<Control1>())
|
|
|
{
|
|
|
Children =
|
|
|
{
|
|
|
- (nested = new Style(x => x.Nesting().Class("foo"))),
|
|
|
+ (nested = new Style(x => Selectors.Or(
|
|
|
+ x.Nesting().Class("foo"),
|
|
|
+ x.Nesting().Class("bar")))),
|
|
|
}
|
|
|
};
|
|
|
|
|
|
var match = nested.Selector.Match(control, parent);
|
|
|
- Assert.Equal(SelectorMatchResult.Sometimes, match.Result);
|
|
|
-
|
|
|
- var sink = new ActivatorSink(match.Activator);
|
|
|
-
|
|
|
- Assert.True(sink.Active);
|
|
|
- control.Classes.Clear();
|
|
|
- Assert.False(sink.Active);
|
|
|
+ Assert.Equal(SelectorMatchResult.NeverThisType, match.Result);
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
- public void Nesting_With_No_Parent_Style_Fails()
|
|
|
+ public void Or_Nesting_Child_OfType_Does_Not_Match_Parent_Selector()
|
|
|
{
|
|
|
var control = new Control1();
|
|
|
- var style = new Style(x => x.Nesting().OfType<Control1>());
|
|
|
+ var panel = new DockPanel { Children = { control } };
|
|
|
+ Style nested;
|
|
|
+ var parent = new Style(x => x.OfType<Panel>())
|
|
|
+ {
|
|
|
+ Children =
|
|
|
+ {
|
|
|
+ (nested = new Style(x => Selectors.Or(
|
|
|
+ x.Nesting().Child().OfType<Control1>(),
|
|
|
+ x.Nesting().Child().OfType<Control1>()))),
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
- Assert.Throws<InvalidOperationException>(() => style.Selector.Match(control, null));
|
|
|
+ var match = nested.Selector.Match(control, parent);
|
|
|
+ Assert.Equal(SelectorMatchResult.NeverThisInstance, match.Result);
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
- public void Nesting_With_No_Parent_Selector_Fails()
|
|
|
+ public void Nesting_Class_Matches()
|
|
|
{
|
|
|
- var control = new Control1();
|
|
|
+ var control = new Control1 { Classes = { "foo" } };
|
|
|
Style nested;
|
|
|
- var parent = new Style
|
|
|
+ var parent = new Style(x => x.OfType<Control1>())
|
|
|
{
|
|
|
Children =
|
|
|
{
|
|
|
@@ -70,44 +77,80 @@ namespace Avalonia.Base.UnitTests.Styling
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- Assert.Throws<InvalidOperationException>(() => nested.Selector.Match(control, parent));
|
|
|
+ var match = nested.Selector.Match(control, parent);
|
|
|
+ Assert.Equal(SelectorMatchResult.Sometimes, match.Result);
|
|
|
+
|
|
|
+ var sink = new ActivatorSink(match.Activator);
|
|
|
+
|
|
|
+ Assert.True(sink.Active);
|
|
|
+ control.Classes.Clear();
|
|
|
+ Assert.False(sink.Active);
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
- public void Nesting_Must_Appear_At_Start_Of_Selector()
|
|
|
+ public void Or_Nesting_Class_Matches()
|
|
|
{
|
|
|
- var control = new Control1();
|
|
|
- Assert.Throws<InvalidOperationException>(() => new Style(x => x.OfType<Control1>().Nesting()));
|
|
|
+ var control = new Control1 { Classes = { "foo" } };
|
|
|
+ Style nested;
|
|
|
+ var parent = new Style(x => x.OfType<Control1>())
|
|
|
+ {
|
|
|
+ Children =
|
|
|
+ {
|
|
|
+ (nested = new Style(x => Selectors.Or(
|
|
|
+ x.Nesting().Class("foo"),
|
|
|
+ x.Nesting().Class("bar")))),
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ var match = nested.Selector.Match(control, parent);
|
|
|
+ Assert.Equal(SelectorMatchResult.Sometimes, match.Result);
|
|
|
+
|
|
|
+ var sink = new ActivatorSink(match.Activator);
|
|
|
+
|
|
|
+ Assert.True(sink.Active);
|
|
|
+ control.Classes.Clear();
|
|
|
+ Assert.False(sink.Active);
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
- public void Nesting_Must_Appear()
|
|
|
+ public void Or_Nesting_Child_OfType_Matches()
|
|
|
{
|
|
|
- var control = new Control1();
|
|
|
+ var control = new Control1 { Classes = { "foo" } };
|
|
|
+ var panel = new Panel { Children = { control } };
|
|
|
Style nested;
|
|
|
- var parent = new Style
|
|
|
+ var parent = new Style(x => x.OfType<Panel>())
|
|
|
{
|
|
|
Children =
|
|
|
{
|
|
|
- (nested = new Style(x => x.OfType<Control1>().Class("foo"))),
|
|
|
+ (nested = new Style(x => Selectors.Or(
|
|
|
+ x.Nesting().Child().OfType<Control1>(),
|
|
|
+ x.Nesting().Child().OfType<Control1>()))),
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- Assert.Throws<InvalidOperationException>(() => nested.Selector.Match(control, parent));
|
|
|
+ var match = nested.Selector.Match(control, parent);
|
|
|
+ Assert.Equal(SelectorMatchResult.AlwaysThisInstance, match.Result);
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
- public void Nesting_Must_Appear_In_All_Or_Arguments()
|
|
|
+ public void Nesting_With_No_Parent_Style_Fails()
|
|
|
+ {
|
|
|
+ var control = new Control1();
|
|
|
+ var style = new Style(x => x.Nesting().OfType<Control1>());
|
|
|
+
|
|
|
+ Assert.Throws<InvalidOperationException>(() => style.Selector.Match(control, null));
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Nesting_With_No_Parent_Selector_Fails()
|
|
|
{
|
|
|
var control = new Control1();
|
|
|
Style nested;
|
|
|
- var parent = new Style(x => x.OfType<Control1>())
|
|
|
+ var parent = new Style
|
|
|
{
|
|
|
Children =
|
|
|
{
|
|
|
- (nested = new Style(x => Selectors.Or(
|
|
|
- x.Nesting().Class("foo"),
|
|
|
- x.Class("bar"))))
|
|
|
+ (nested = new Style(x => x.Nesting().Class("foo"))),
|
|
|
}
|
|
|
};
|
|
|
|