Skip to content

Commit 78740fe

Browse files
committed
Added more tests for background-size
1 parent ad7aff4 commit 78740fe

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@ namespace AngleSharp.Css.Tests.Declarations
66
[TestFixture]
77
public class CssBackgroundPropertyTests
88
{
9+
[Test]
10+
public void CssBackgroundSizeCoverTest()
11+
{
12+
var snippet = "background-size : cover";
13+
var property = ParseDeclaration(snippet);
14+
Assert.AreEqual("background-size", property.Name);
15+
Assert.IsFalse(property.IsImportant);
16+
Assert.IsFalse(property.IsInherited);
17+
Assert.IsTrue(property.HasValue);
18+
Assert.AreEqual("cover", property.Value);
19+
}
20+
21+
[Test]
22+
public void CssBackgroundSizeContainTest()
23+
{
24+
var snippet = "background-size : contain";
25+
var property = ParseDeclaration(snippet);
26+
Assert.AreEqual("background-size", property.Name);
27+
Assert.IsFalse(property.IsImportant);
28+
Assert.IsFalse(property.IsInherited);
29+
Assert.IsTrue(property.HasValue);
30+
Assert.AreEqual("contain", property.Value);
31+
}
32+
933
[Test]
1034
public void CssBackgroundAttachmentScrollLegal()
1135
{

src/AngleSharp.Css/Parser/Micro/PointParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,15 @@ public static CssBackgroundSizeValue ParseSize(this StringSource source)
167167
{
168168
var w = source.ParseDistanceOrCalc();
169169

170-
if (w == null && !source.IsIdentifier(CssKeywords.Auto))
170+
if (w is null && !source.IsIdentifier(CssKeywords.Auto))
171171
{
172172
return null;
173173
}
174174

175175
source.SkipSpacesAndComments();
176176
var h = source.ParseDistanceOrCalc();
177177

178-
if (h == null)
178+
if (h is null)
179179
{
180180
source.IsIdentifier(CssKeywords.Auto);
181181
}

src/AngleSharp.Css/Values/Composites/CssBackgroundSizeValue.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public sealed class CssBackgroundSizeValue : IEquatable<CssBackgroundSizeValue>,
3030

3131
private CssBackgroundSizeValue(ValueMode mode)
3232
{
33-
_width = Length.Zero;
34-
_height = Length.Zero;
33+
_width = Length.Auto;
34+
_height = Length.Auto;
3535
_mode = mode;
3636
}
3737

@@ -94,18 +94,29 @@ public String CssText
9494
/// </summary>
9595
/// <param name="other">The other background size.</param>
9696
/// <returns>True if both are equivalent, otherwise false.</returns>
97-
public Boolean Equals(CssBackgroundSizeValue other) =>
98-
_mode == other._mode && _height == other._height && _width == other._width;
97+
public Boolean Equals(CssBackgroundSizeValue other) => _mode == other._mode && _height == other._height && _width == other._width;
9998

10099
#endregion
101100

102101
#region Value Mode
103102

103+
/// <summary>
104+
/// Represents the value modes for the vertical and horizontal axis.
105+
/// </summary>
104106
private enum ValueMode
105107
{
108+
/// <summary>
109+
/// The size is explicitly specified.
110+
/// </summary>
106111
Explicit,
112+
/// <summary>
113+
/// The size should cover the axis.
114+
/// </summary>
107115
Cover,
108-
Contain
116+
/// <summary>
117+
/// The size should contain the axis.
118+
/// </summary>
119+
Contain,
109120
}
110121

111122
#endregion

0 commit comments

Comments
 (0)