Skip to content

Commit

Permalink
Added more tests for background-size
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Jun 14, 2023
1 parent ad7aff4 commit 78740fe
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
24 changes: 24 additions & 0 deletions src/AngleSharp.Css.Tests/Declarations/CssBackgroundProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@ namespace AngleSharp.Css.Tests.Declarations
[TestFixture]
public class CssBackgroundPropertyTests
{
[Test]
public void CssBackgroundSizeCoverTest()
{
var snippet = "background-size : cover";
var property = ParseDeclaration(snippet);
Assert.AreEqual("background-size", property.Name);
Assert.IsFalse(property.IsImportant);
Assert.IsFalse(property.IsInherited);
Assert.IsTrue(property.HasValue);
Assert.AreEqual("cover", property.Value);
}

[Test]
public void CssBackgroundSizeContainTest()
{
var snippet = "background-size : contain";
var property = ParseDeclaration(snippet);
Assert.AreEqual("background-size", property.Name);
Assert.IsFalse(property.IsImportant);
Assert.IsFalse(property.IsInherited);
Assert.IsTrue(property.HasValue);
Assert.AreEqual("contain", property.Value);
}

[Test]
public void CssBackgroundAttachmentScrollLegal()
{
Expand Down
4 changes: 2 additions & 2 deletions src/AngleSharp.Css/Parser/Micro/PointParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ public static CssBackgroundSizeValue ParseSize(this StringSource source)
{
var w = source.ParseDistanceOrCalc();

if (w == null && !source.IsIdentifier(CssKeywords.Auto))
if (w is null && !source.IsIdentifier(CssKeywords.Auto))
{
return null;
}

source.SkipSpacesAndComments();
var h = source.ParseDistanceOrCalc();

if (h == null)
if (h is null)
{
source.IsIdentifier(CssKeywords.Auto);
}
Expand Down
21 changes: 16 additions & 5 deletions src/AngleSharp.Css/Values/Composites/CssBackgroundSizeValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public sealed class CssBackgroundSizeValue : IEquatable<CssBackgroundSizeValue>,

private CssBackgroundSizeValue(ValueMode mode)
{
_width = Length.Zero;
_height = Length.Zero;
_width = Length.Auto;
_height = Length.Auto;
_mode = mode;
}

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

#endregion

#region Value Mode

/// <summary>
/// Represents the value modes for the vertical and horizontal axis.
/// </summary>
private enum ValueMode
{
/// <summary>
/// The size is explicitly specified.
/// </summary>
Explicit,
/// <summary>
/// The size should cover the axis.
/// </summary>
Cover,
Contain
/// <summary>
/// The size should contain the axis.
/// </summary>
Contain,
}

#endregion
Expand Down

0 comments on commit 78740fe

Please sign in to comment.