From d0a576339f95de607d8eb2b0a5347243f70541d8 Mon Sep 17 00:00:00 2001 From: Tyler Brinks Date: Fri, 11 Oct 2024 07:44:35 -0600 Subject: [PATCH] Percentage value fix --- .../PropertyTests/OpacityPropertyTests.cs | 29 ++++++++++++++++--- src/ExCSS/Extensions/ValueExtensions.cs | 2 +- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/ExCSS.Tests/PropertyTests/OpacityPropertyTests.cs b/src/ExCSS.Tests/PropertyTests/OpacityPropertyTests.cs index 5b1c475..9adc445 100644 --- a/src/ExCSS.Tests/PropertyTests/OpacityPropertyTests.cs +++ b/src/ExCSS.Tests/PropertyTests/OpacityPropertyTests.cs @@ -11,9 +11,30 @@ public void OpacityPercentLegal() Assert.Equal("opacity", property.Name); Assert.False(property.IsImportant); Assert.IsType(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); } } diff --git a/src/ExCSS/Extensions/ValueExtensions.cs b/src/ExCSS/Extensions/ValueExtensions.cs index 6f20555..43cdddb 100644 --- a/src/ExCSS/Extensions/ValueExtensions.cs +++ b/src/ExCSS/Extensions/ValueExtensions.cs @@ -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