Skip to content

Commit 6ed8c02

Browse files
author
Frank
committed
Fix csstext not outputting the liniar angle that was parsed
1 parent c99af71 commit 6ed8c02

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

src/AngleSharp.Css.Tests/Declarations/CssBackgroundProperty.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,5 +661,16 @@ public void CssBackgroundImageDataUrlLegal()
661661
Assert.IsTrue(property.HasValue);
662662
Assert.AreEqual("url(\"" + url + "\")", property.Value);
663663
}
664+
665+
[Test]
666+
public void CssBackgroundImageLinearGradientLegal()
667+
{
668+
var source = "background-image: linear-gradient(to right, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))";
669+
var property = ParseDeclaration(source);
670+
Assert.IsTrue(property.HasValue);
671+
672+
var expected = "linear-gradient(90deg, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))";
673+
Assert.AreEqual(expected, property.Value);
674+
}
664675
}
665676
}

src/AngleSharp.Css.Tests/Declarations/CssBorderImageProperty.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AngleSharp.Css.Tests.Declarations
1+
namespace AngleSharp.Css.Tests.Declarations
22
{
33
using NUnit.Framework;
44
using static CssConstructionFunctions;
@@ -39,7 +39,7 @@ public void CssBorderImageSourceLinearGradientLegal()
3939
Assert.IsFalse(property.IsImportant);
4040
Assert.IsFalse(property.IsInherited);
4141
Assert.IsTrue(property.HasValue);
42-
Assert.AreEqual("linear-gradient(rgba(255, 0, 0, 1), rgba(255, 255, 0, 1))", property.Value);
42+
Assert.AreEqual("linear-gradient(0deg, rgba(255, 0, 0, 1), rgba(255, 255, 0, 1))", property.Value);
4343
}
4444

4545
[Test]

src/AngleSharp.Css.Tests/Values/Gradient.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public void InRadialGradient()
2929
[Test]
3030
public void BackgroundImageLinearGradientWithAngle()
3131
{
32-
var source = "background-image: linear-gradient(135deg, red, blue)";
32+
var red = Color.Red;
33+
var blue = Color.Blue;
34+
var source = $"background-image: linear-gradient(135deg, {red.CssText}, {blue.CssText})";
3335
var property = ParseDeclaration(source);
3436
Assert.IsTrue(property.HasValue);
3537
Assert.IsFalse(property.IsInitial);
@@ -41,8 +43,10 @@ public void BackgroundImageLinearGradientWithAngle()
4143
Assert.IsFalse(gradient.IsRepeating);
4244
Assert.AreEqual(Angle.TripleHalfQuarter, gradient.Angle);
4345
Assert.AreEqual(2, gradient.Stops.Length);
44-
Assert.AreEqual(Color.Red, gradient.Stops.First().Color);
45-
Assert.AreEqual(Color.Blue, gradient.Stops.Last().Color);
46+
Assert.AreEqual(red, gradient.Stops.First().Color);
47+
Assert.AreEqual(blue, gradient.Stops.Last().Color);
48+
49+
Assert.AreEqual(source, property.CssText);
4650
}
4751

4852
[Test]

src/AngleSharp.Css/Values/Functions/CssLinearGradientValue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public String CssText
6969
get
7070
{
7171
var defaultAngle = _angle as Angle?;
72-
var offset = defaultAngle.HasValue ? 0 : 1;
72+
var offset = defaultAngle.HasValue ? 1 : 0;
7373
var args = new String[_stops.Length + offset];
7474

7575
if (defaultAngle.HasValue)
@@ -80,7 +80,7 @@ public String CssText
8080
{
8181
if (angle.Value == value)
8282
{
83-
args[0] = angle.Key;
83+
args[0] = angle.Value.CssText;
8484
break;
8585
}
8686
}

0 commit comments

Comments
 (0)