Skip to content

Commit

Permalink
Percentage value fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerBrinks committed Oct 11, 2024
1 parent 7fd3419 commit d0a5763
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
29 changes: 25 additions & 4 deletions src/ExCSS.Tests/PropertyTests/OpacityPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,30 @@ public void OpacityPercentLegal()
Assert.Equal("opacity", property.Name);
Assert.False(property.IsImportant);
Assert.IsType<OpacityProperty>(property);
var concrete = (OpacityProperty)property;
Assert.False(concrete.IsInherited);
Assert.True(concrete.HasValue);
Assert.Equal("50%", concrete.Value);
var result = (OpacityProperty)property;
Assert.False(result.IsInherited);
Assert.True(result.HasValue);
Assert.Equal("50%", result.Value);
}


[Fact]
public void OpacityVarianceTests()
{
var property = ParseDeclaration("opacity: 50%");
var result = (OpacityProperty)property;
Assert.Equal("50%", result.Value);

property = ParseDeclaration("opacity: .50");
result = (OpacityProperty)property;
Assert.Equal("50%", result.Value);

property = ParseDeclaration("opacity: 1");
result = (OpacityProperty)property;
Assert.Equal("100%", result.Value);

property = ParseDeclaration("opacity: 0");
result = (OpacityProperty)property;
Assert.Equal("0%", result.Value);
}
}
2 changes: 1 addition & 1 deletion src/ExCSS/Extensions/ValueExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static Length ToLength(this FontSize fontSize)
try
{
var number = token.Value;
var percentage = number / 100;
var percentage = number * 100;
return new Percent(percentage);
}
catch
Expand Down

0 comments on commit d0a5763

Please sign in to comment.