Skip to content

Commit e93e2bb

Browse files
committed
More tests for correct border behavior
1 parent 19163df commit e93e2bb

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

src/AngleSharp.Css.Tests/Styling/CssSheet.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,60 @@ public void CssStyleSheetShouldIgnoreHtmlCommentTokens()
925925
Assert.AreEqual("none", div.Style.GetDisplay());
926926
}
927927

928+
[Test]
929+
public void CssStyleSheetShouldExpandBorderColorCorrectly_Issue23()
930+
{
931+
var parser = new CssParser();
932+
var source = "body { border-color: red }";
933+
var sheet = parser.ParseStyleSheet(source);
934+
935+
Assert.AreEqual(1, sheet.Rules.Length);
936+
Assert.AreEqual(CssRuleType.Style, sheet.Rules[0].Type);
937+
938+
var body = sheet.Rules[0] as ICssStyleRule;
939+
Assert.AreEqual("border-color: rgba(255, 0, 0, 1)", body.Style.CssText);
940+
Assert.AreEqual("rgba(255, 0, 0, 1)", body.Style.GetBorderColor());
941+
Assert.AreEqual("rgba(255, 0, 0, 1)", body.Style.GetBorderLeftColor());
942+
Assert.AreEqual("rgba(255, 0, 0, 1)", body.Style.GetBorderRightColor());
943+
Assert.AreEqual("rgba(255, 0, 0, 1)", body.Style.GetBorderTopColor());
944+
Assert.AreEqual("rgba(255, 0, 0, 1)", body.Style.GetBorderBottomColor());
945+
}
946+
947+
[Test]
948+
public void CssStyleSheetShouldCollapseBorderColorCorrectly_Issue23()
949+
{
950+
var parser = new CssParser();
951+
var source = "body { border-color: red }";
952+
var sheet = parser.ParseStyleSheet(source);
953+
954+
var body = sheet.Rules[0] as ICssStyleRule;
955+
body.Style.SetBorderLeftColor("blue");
956+
body.Style.SetBorderRightColor("blue");
957+
Assert.AreEqual("border-color: rgba(255, 0, 0, 1) rgba(0, 0, 255, 1)", body.Style.CssText);
958+
Assert.AreEqual("rgba(255, 0, 0, 1) rgba(0, 0, 255, 1)", body.Style.GetBorderColor());
959+
Assert.AreEqual("rgba(0, 0, 255, 1)", body.Style.GetBorderLeftColor());
960+
Assert.AreEqual("rgba(0, 0, 255, 1)", body.Style.GetBorderRightColor());
961+
Assert.AreEqual("rgba(255, 0, 0, 1)", body.Style.GetBorderTopColor());
962+
Assert.AreEqual("rgba(255, 0, 0, 1)", body.Style.GetBorderBottomColor());
963+
}
964+
965+
[Test]
966+
public void CssStyleSheetShouldCollapseFullBorderCorrectly_Issue23()
967+
{
968+
var parser = new CssParser();
969+
var source = "body { border: 1px solid red }";
970+
var sheet = parser.ParseStyleSheet(source);
971+
972+
var body = sheet.Rules[0] as ICssStyleRule;
973+
Assert.AreEqual("border: 1px solid rgba(255, 0, 0, 1)", body.Style.CssText);
974+
body.Style.SetBorderLeftColor("blue");
975+
body.Style.SetBorderTopWidth("medium");
976+
Assert.AreEqual("border-top: 3px solid rgba(255, 0, 0, 1); border-right: 1px solid rgba(255, 0, 0, 1); border-bottom: 1px solid rgba(255, 0, 0, 1); border-left: 1px solid rgba(0, 0, 255, 1)", body.Style.CssText);
977+
Assert.AreEqual("rgba(255, 0, 0, 1) rgba(255, 0, 0, 1) rgba(255, 0, 0, 1) rgba(0, 0, 255, 1)", body.Style.GetBorderColor());
978+
Assert.AreEqual("3px 1px 1px", body.Style.GetBorderWidth());
979+
Assert.AreEqual("solid", body.Style.GetBorderStyle());
980+
}
981+
928982
[Test]
929983
public void CssStyleSheetInsertShouldSetParentStyleSheetCorrectly()
930984
{

src/AngleSharp.Css/BrowsingContextExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ internal static ICssProperty CreateShorthand(this IBrowsingContext context, Stri
6363
{
6464
var factory = context.GetFactory<IDeclarationFactory>();
6565
var info = factory.Create(name);
66-
var value = info.Combine(factory, longhands);
66+
var value = info.Collapse(factory, longhands);
6767

6868
if (context.AllowsDeclaration(info))
6969
{
@@ -77,7 +77,7 @@ internal static ICssProperty[] CreateLonghands(this IBrowsingContext context, IC
7777
{
7878
var factory = context.GetFactory<IDeclarationFactory>();
7979
var info = factory.Create(shorthand.Name);
80-
var values = info.Seperate(factory, shorthand.RawValue);
80+
var values = info.Expand(factory, shorthand.RawValue);
8181
return factory.CreateProperties(info.Longhands, values, shorthand.IsImportant);
8282
}
8383

src/AngleSharp.Css/Extensions/DeclarationInfoExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ static class DeclarationInfoExtensions
1111
public static IEnumerable<String> GetMappings(this DeclarationInfo info) =>
1212
info.Longhands.Length > 0 ? info.Longhands : Enumerable.Repeat(info.Name, 1);
1313

14-
public static ICssValue Combine(this DeclarationInfo info, IDeclarationFactory factory, ICssValue[] longhands)
14+
public static ICssValue Collapse(this DeclarationInfo info, IDeclarationFactory factory, ICssValue[] longhands)
1515
{
1616
var initial = true;
1717
var unset = true;
@@ -40,7 +40,7 @@ public static ICssValue Combine(this DeclarationInfo info, IDeclarationFactory f
4040
return info.Aggregator?.Merge(longhands);
4141
}
4242

43-
public static ICssValue[] Seperate(this DeclarationInfo info, IDeclarationFactory factory, ICssValue value)
43+
public static ICssValue[] Expand(this DeclarationInfo info, IDeclarationFactory factory, ICssValue value)
4444
{
4545
var longhands = info.Longhands;
4646

0 commit comments

Comments
 (0)