|
|
@ -1,3 +1,4 @@ |
|
|
|
|
|
using System.Collections.Generic; |
|
|
using Avalonia.Media; |
|
|
using Avalonia.Media; |
|
|
using Xunit; |
|
|
using Xunit; |
|
|
|
|
|
|
|
|
@ -5,49 +6,111 @@ namespace Avalonia.Base.UnitTests.Media |
|
|
{ |
|
|
{ |
|
|
public class BoxShadowTests |
|
|
public class BoxShadowTests |
|
|
{ |
|
|
{ |
|
|
[Fact] |
|
|
[Theory] |
|
|
public void BoxShadow_Should_Parse() |
|
|
[MemberData(nameof(ParseGetData))] |
|
|
|
|
|
public void BoxShadow_Should_Parse(BoxShadow expected, string source) |
|
|
|
|
|
{ |
|
|
|
|
|
var parsered = BoxShadow.Parse(source); |
|
|
|
|
|
Assert.Equal(expected.IsInset, parsered.IsInset); |
|
|
|
|
|
Assert.Equal(expected.OffsetX, parsered.OffsetX); |
|
|
|
|
|
Assert.Equal(expected.OffsetY, parsered.OffsetY); |
|
|
|
|
|
Assert.Equal(expected.Blur, parsered.Blur); |
|
|
|
|
|
Assert.Equal(expected.Spread, parsered.Spread); |
|
|
|
|
|
Assert.Equal(expected.Color, parsered.Color); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Theory] |
|
|
|
|
|
[MemberData(nameof(ToStringGetData))] |
|
|
|
|
|
public void BoxShadows_Should_ToString(BoxShadows source, string expected) => |
|
|
|
|
|
Assert.Equal(expected, source.ToString(), true); |
|
|
|
|
|
|
|
|
|
|
|
public static IEnumerable<object[]> ParseGetData() |
|
|
{ |
|
|
{ |
|
|
foreach (var extraSpaces in new[] { false, true }) |
|
|
foreach (var extraSpaces in new[] { false, true }) |
|
|
foreach (var inset in new[] { false, true }) |
|
|
foreach (var inset in new[] { false, true }) |
|
|
for (var componentCount = 2; componentCount < 5; componentCount++) |
|
|
foreach (var color in new[] { "red", "#FF122403" }) |
|
|
{ |
|
|
for (var componentCount = 2; componentCount < 5; componentCount++) |
|
|
var s = (inset ? "inset " : "") + "10 20"; |
|
|
{ |
|
|
double blur = 0; |
|
|
var s = (inset ? "inset " : "") + "10 20"; |
|
|
double spread = 0; |
|
|
if (componentCount > 2) |
|
|
if (componentCount > 2) |
|
|
{ |
|
|
{ |
|
|
s += " 30"; |
|
|
s += " 30"; |
|
|
} |
|
|
blur = 30; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (componentCount > 3) |
|
|
if (componentCount > 3) |
|
|
{ |
|
|
{ |
|
|
s += " 40"; |
|
|
s += " 40"; |
|
|
spread = 40; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
s += " " + color; |
|
|
s += " red"; |
|
|
|
|
|
|
|
|
if (extraSpaces) |
|
|
if (extraSpaces) |
|
|
s = " " + s.Replace(" ", " ") + " "; |
|
|
s = " " + s.Replace(" ", " ") + " "; |
|
|
|
|
|
|
|
|
var parsed = BoxShadow.Parse(s); |
|
|
var parsed = BoxShadow.Parse(s); |
|
|
yield return new object[] { parsed, s }; |
|
|
Assert.Equal(inset, parsed.IsInset); |
|
|
} |
|
|
Assert.Equal(10, parsed.OffsetX); |
|
|
|
|
|
Assert.Equal(20, parsed.OffsetY); |
|
|
|
|
|
Assert.Equal(blur, parsed.Blur); |
|
|
|
|
|
Assert.Equal(spread, parsed.Spread); |
|
|
|
|
|
Assert.Equal(Colors.Red, parsed.Color); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
public static IEnumerable<object[]> ToStringGetData() |
|
|
public void BoxShadows_Should_ToString() |
|
|
|
|
|
{ |
|
|
{ |
|
|
const string source = "-20 -20 60 #CCFFFFFF, 20 20 60 #33000000"; |
|
|
yield return new object[] |
|
|
var parsed = BoxShadows.Parse(source); |
|
|
{ |
|
|
Assert.Equal(source, parsed.ToString(), true); |
|
|
new BoxShadows( |
|
|
|
|
|
new BoxShadow() |
|
|
|
|
|
{ |
|
|
|
|
|
OffsetX = -15, |
|
|
|
|
|
OffsetY = 20, |
|
|
|
|
|
Spread = 5, |
|
|
|
|
|
Color = Colors.Red, |
|
|
|
|
|
}), |
|
|
|
|
|
"-15 20 0 5 red" |
|
|
|
|
|
}; |
|
|
|
|
|
yield return new object[] |
|
|
|
|
|
{ |
|
|
|
|
|
new BoxShadows( |
|
|
|
|
|
new BoxShadow() |
|
|
|
|
|
{ |
|
|
|
|
|
IsInset = true, |
|
|
|
|
|
OffsetX = -15, |
|
|
|
|
|
OffsetY = 20, |
|
|
|
|
|
Spread = 5, |
|
|
|
|
|
Color = Colors.Red, |
|
|
|
|
|
}), |
|
|
|
|
|
"inset -15 20 0 5 red" |
|
|
|
|
|
}; |
|
|
|
|
|
yield return new object[] |
|
|
|
|
|
{ |
|
|
|
|
|
new BoxShadows( |
|
|
|
|
|
new BoxShadow() |
|
|
|
|
|
{ |
|
|
|
|
|
OffsetX = -15, |
|
|
|
|
|
OffsetY = 20, |
|
|
|
|
|
Blur = 5, |
|
|
|
|
|
Color = Colors.Red, |
|
|
|
|
|
}), |
|
|
|
|
|
"-15 20 5 red" |
|
|
|
|
|
}; |
|
|
|
|
|
yield return new object[] |
|
|
|
|
|
{ |
|
|
|
|
|
new BoxShadows( |
|
|
|
|
|
new BoxShadow() |
|
|
|
|
|
{ |
|
|
|
|
|
OffsetX = -20, |
|
|
|
|
|
OffsetY = -20, |
|
|
|
|
|
Blur = 60, |
|
|
|
|
|
Color = Color.Parse("#CCFFFFFF") |
|
|
|
|
|
}, |
|
|
|
|
|
new BoxShadow[] { new() |
|
|
|
|
|
{ |
|
|
|
|
|
OffsetX = 20, |
|
|
|
|
|
OffsetY = 20, |
|
|
|
|
|
Blur = 60, |
|
|
|
|
|
Color = Color.Parse("#33000000") |
|
|
|
|
|
} }), |
|
|
|
|
|
"-20 -20 60 #CCFFFFFF, 20 20 60 #33000000" |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|