From 0e63e8c4f5ede986093ba9cbf5b4990a169f24ee Mon Sep 17 00:00:00 2001 From: H1Gdev Date: Fri, 24 Dec 2021 13:59:44 +0900 Subject: [PATCH 1/2] Add Original property in IProperty. --- src/ExCSS/StyleProperties/IProperty.cs | 1 + src/ExCSS/StyleProperties/Property.cs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/ExCSS/StyleProperties/IProperty.cs b/src/ExCSS/StyleProperties/IProperty.cs index 83b28146..e543341b 100644 --- a/src/ExCSS/StyleProperties/IProperty.cs +++ b/src/ExCSS/StyleProperties/IProperty.cs @@ -4,6 +4,7 @@ public interface IProperty : IStylesheetNode { string Name { get; } string Value { get; } + string Original { get; } bool IsImportant { get; } } } \ No newline at end of file diff --git a/src/ExCSS/StyleProperties/Property.cs b/src/ExCSS/StyleProperties/Property.cs index a4038589..f216d448 100644 --- a/src/ExCSS/StyleProperties/Property.cs +++ b/src/ExCSS/StyleProperties/Property.cs @@ -31,6 +31,8 @@ internal bool TrySetValue(TokenValue newTokenValue) public string Value => DeclaredValue != null ? DeclaredValue.CssText : Keywords.Initial; + public string Original => DeclaredValue != null ? DeclaredValue.Original.Text : Keywords.Initial; + public bool IsInherited => (_flags & PropertyFlags.Inherited) == PropertyFlags.Inherited && IsInitial || DeclaredValue != null && DeclaredValue.CssText.Is(Keywords.Inherit); From e6e4c97bceff405e32ff3e9109db90326f15d1a3 Mon Sep 17 00:00:00 2001 From: H1Gdev Date: Fri, 24 Dec 2021 14:27:13 +0900 Subject: [PATCH 2/2] Add tests. --- src/ExCSS.Tests/Property.cs | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/ExCSS.Tests/Property.cs b/src/ExCSS.Tests/Property.cs index e78f7f2e..a3c0f4b7 100644 --- a/src/ExCSS.Tests/Property.cs +++ b/src/ExCSS.Tests/Property.cs @@ -17,6 +17,7 @@ public void CssBreakAfterLegalAvoid() var concrete = (BreakAfterProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("avoid", concrete.Value); + Assert.Equal("avoid", concrete.Original); } [Fact] @@ -31,6 +32,7 @@ public void CssPageBreakAfterLegalAvoid() var concrete = (PageBreakAfterProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("avoid", concrete.Value); + Assert.Equal("avoid", concrete.Original); } [Fact] @@ -45,6 +47,7 @@ public void CssBreakAfterLegalPageCapital() var concrete = (BreakAfterProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("page", concrete.Value); + Assert.Equal("Page", concrete.Original); } [Fact] @@ -72,6 +75,7 @@ public void CssBreakAfterLegalAvoidColumn() var concrete = (BreakAfterProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("avoid-column", concrete.Value); + Assert.Equal("avoid-column", concrete.Original); } [Fact] @@ -86,6 +90,7 @@ public void CssBreakBeforeLegalAvoidColumn() var concrete = (BreakBeforeProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("auto", concrete.Value); + Assert.Equal("AUTO", concrete.Original); } [Fact] @@ -100,6 +105,7 @@ public void CssPageBreakBeforeLegalAvoid() var concrete = (PageBreakBeforeProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("auto", concrete.Value); + Assert.Equal("AUTO", concrete.Original); } [Fact] @@ -114,6 +120,7 @@ public void CssPageBreakBeforeLegalLeft() var concrete = (PageBreakBeforeProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("left", concrete.Value); + Assert.Equal("left", concrete.Original); } [Fact] @@ -154,6 +161,7 @@ public void CssBreakInsideLegalAvoidRegionUppercase() var concrete = (BreakInsideProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("avoid-region", concrete.Value); + Assert.Equal("avoid-REGION", concrete.Original); } [Fact] @@ -168,6 +176,7 @@ public void CssPageBreakInsideLegalAvoid() var concrete = (PageBreakInsideProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("avoid", concrete.Value); + Assert.Equal("avoid", concrete.Original); } [Fact] @@ -182,6 +191,7 @@ public void CssPageBreakInsideLegalAutoUppercase() var concrete = (PageBreakInsideProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("auto", concrete.Value); + Assert.Equal("AUTO", concrete.Original); } [Fact] @@ -196,6 +206,7 @@ public void CssClearLegalLeft() var concrete = (ClearProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("left", concrete.Value); + Assert.Equal("left", concrete.Original); } [Fact] @@ -210,6 +221,7 @@ public void CssClearLegalBoth() var concrete = (ClearProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("both", concrete.Value); + Assert.Equal("both", concrete.Original); } [Fact] @@ -251,6 +263,7 @@ public void CssPositionLegalAbsolute() var concrete = (PositionProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("absolute", concrete.Value); + Assert.Equal("absolute", concrete.Original); } [Fact] @@ -265,6 +278,7 @@ public void CssDisplayLegalBlock() var concrete = (DisplayProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("block", concrete.Value); + Assert.Equal("block", concrete.Original); } [Fact] @@ -279,6 +293,7 @@ public void CssVisibilityLegalCollapse() var concrete = (VisibilityProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("collapse", concrete.Value); + Assert.Equal("collapse", concrete.Original); } [Fact] @@ -293,6 +308,7 @@ public void CssVisibilityLegalHiddenCompleteUppercase() var concrete = (VisibilityProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("hidden", concrete.Value); + Assert.Equal("HIDDEN", concrete.Original); } [Fact] @@ -307,6 +323,7 @@ public void CssOverflowLegalAuto() var concrete = (OverflowProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("auto", concrete.Value); + Assert.Equal("auto", concrete.Original); } [Fact] @@ -321,6 +338,7 @@ public void CssTableLayoutLegalFixedCapitalX() var concrete = (TableLayoutProperty)property; Assert.False(concrete.IsInherited); Assert.Equal("fixed", concrete.Value); + Assert.Equal("fiXed", concrete.Original); } [Fact] @@ -335,6 +353,7 @@ public void CssBoxShadowOffsetLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("5px 4px", concrete.Value); + Assert.Equal("5px 4px", concrete.Original); } [Fact] @@ -349,6 +368,7 @@ public void CssBoxShadowInsetOffsetLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("inset 5px 4px", concrete.Value); + Assert.Equal("inset 5px 4px", concrete.Original); } [Fact] @@ -363,6 +383,7 @@ public void CssBoxShadowNoneUppercaseLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("none", concrete.Value); + Assert.Equal("NONE", concrete.Original); } [Fact] @@ -377,6 +398,7 @@ public void CssBoxShadowNormalTealLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("60px -16px rgb(0, 128, 128)", concrete.Value); + Assert.Equal("60px -16px teal", concrete.Original); } [Fact] @@ -391,6 +413,7 @@ public void CssBoxShadowNormalSpreadBlackLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("10px 5px 5px rgb(0, 0, 0)", concrete.Value); + Assert.Equal("10px 5px 5px black", concrete.Original); } [Fact] @@ -405,6 +428,7 @@ public void CssBoxShadowOliveAndRedLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("3px 3px rgb(255, 0, 0), -1em 0 0.4em rgb(128, 128, 0)", concrete.Value); + Assert.Equal("3px 3px red, -1em 0 0.4em olive", concrete.Original); } [Fact] @@ -419,6 +443,7 @@ public void CssBoxShadowInsetGoldLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("inset 5em 1em rgb(255, 215, 0)", concrete.Value); + Assert.Equal("inset 5em 1em gold", concrete.Original); } [Fact] @@ -433,6 +458,7 @@ public void CssBoxShadowZeroGoldLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("0 0 1em rgb(255, 215, 0)", concrete.Value); + Assert.Equal("0 0 1em gold", concrete.Original); } [Fact] @@ -447,6 +473,7 @@ public void CssBoxShadowInsetZeroGoldLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("inset 0 0 1em rgb(255, 215, 0)", concrete.Value); + Assert.Equal("inset 0 0 1em gold", concrete.Original); } [Fact] @@ -461,6 +488,7 @@ public void CssBoxShadowInsetZeroGoldAndNormalRedLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("inset 0 0 1em rgb(255, 215, 0), 0 0 1em rgb(255, 0, 0)", concrete.Value); + Assert.Equal("inset 0 0 1em gold, 0 0 1em red", concrete.Original); } [Fact] @@ -475,6 +503,7 @@ public void CssBoxShadowOffsetColorLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("5px 4px rgb(0, 0, 0)", concrete.Value); + Assert.Equal("5px 4px #000", concrete.Original); } [Fact] @@ -489,6 +518,7 @@ public void CssBoxShadowOffsetBlurColorLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("5px 4px 2px rgb(0, 0, 0)", concrete.Value); + Assert.Equal("5px 4px 2px #000", concrete.Original); } [Fact] @@ -503,6 +533,7 @@ public void CssBoxShadowInitialUppercaseLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("initial", concrete.Value); + Assert.Equal("INITIAL", concrete.Original); } [Fact] @@ -530,6 +561,7 @@ public void CssClipShapeLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("rect(2px, 3em, 1in, 0)", concrete.Value); + Assert.Equal("rect( 2px, 3em, 1in, 0cm )", concrete.Original); } [Fact] @@ -544,6 +576,7 @@ public void CssClipShapeBackwards() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("rect(2px 3em 1in 0)", concrete.Value); + Assert.Equal("rect( 2px 3em 1in 0cm )", concrete.Original); } [Fact] @@ -558,6 +591,7 @@ public void CssClipShapeZerosLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("rect(0, 0, 0, 0)", concrete.Value); + Assert.Equal("rect(0, 0, 0, 0)", concrete.Original); } [Fact] @@ -611,6 +645,7 @@ public void CssCursorDefaultUppercaseLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("default", concrete.Value); + Assert.Equal("DEFAULT", concrete.Original); } [Fact] @@ -625,6 +660,7 @@ public void CssCursorAutoLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("auto", concrete.Value); + Assert.Equal("auto", concrete.Original); } [Fact] @@ -639,6 +675,7 @@ public void CssCursorZoomOutLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("zoom-out", concrete.Value); + Assert.Equal("zoom-out", concrete.Original); } [Fact] @@ -666,6 +703,7 @@ public void CssCursorUrlLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("url(\"foo.png\"), default", concrete.Value); + Assert.Equal("url(\"foo.png\"), default", concrete.Original); } [Fact] @@ -680,6 +718,7 @@ public void CssCursorUrlShiftedLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("url(\"foo.png\") 0 5, auto", concrete.Value); + Assert.Equal("url(\"foo.png\") 0 5, auto", concrete.Original); } [Fact] @@ -707,6 +746,7 @@ public void CssCursorUrlsLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("url(\"foo.png\"), url(\"master.png\"), url(\"more.png\"), wait", concrete.Value); + Assert.Equal("url(\"foo.png\"), url(\"master.png\"), url(\"more.png\"), wait", concrete.Original); } [Fact] @@ -721,6 +761,7 @@ public void CssColorHexLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("rgb(18, 52, 86)", concrete.Value); + Assert.Equal("#123456", concrete.Original); } [Fact] @@ -735,6 +776,7 @@ public void CssColorRgbLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("rgb(121, 181, 201)", concrete.Value); + Assert.Equal("rgb(121, 181, 201)", concrete.Original); } [Fact] @@ -749,6 +791,7 @@ public void CssColorRgbaLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("rgba(255, 255, 201, 0.7)", concrete.Value); + Assert.Equal("rgba(255, 255, 201, 0.7)", concrete.Original); } [Fact] @@ -763,6 +806,7 @@ public void CssColorNameLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("rgb(255, 0, 0)", concrete.Value); + Assert.Equal("red", concrete.Original); } [Fact] @@ -777,6 +821,7 @@ public void CssColorNameUppercaseLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("rgb(0, 0, 255)", concrete.Value); + Assert.Equal("BLUE", concrete.Original); } [Fact] @@ -804,6 +849,7 @@ public void CssOrphansZeroLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("0", concrete.Value); + Assert.Equal("0", concrete.Original); } [Fact] @@ -818,6 +864,7 @@ public void CssOrphansTwoLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("2", concrete.Value); + Assert.Equal("2", concrete.Original); } [Fact] @@ -871,6 +918,7 @@ public void CssBoxDecorationBreakSliceLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("slice", concrete.Value); + Assert.Equal("slice", concrete.Original); } [Fact] @@ -885,6 +933,7 @@ public void CssBoxDecorationBreakClonePascalLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("clone", concrete.Value); + Assert.Equal("Clone", concrete.Original); } [Fact] @@ -899,6 +948,7 @@ public void CssBoxDecorationBreakInheritLegal() Assert.True(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("inherit", concrete.Value); + Assert.Equal("inherit", concrete.Original); } [Fact] @@ -913,6 +963,7 @@ public void CssContentNormalLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("normal", concrete.Value); + Assert.Equal("normal", concrete.Original); } [Fact] @@ -927,6 +978,7 @@ public void CssContentNoneLegalUppercaseN() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("none", concrete.Value); + Assert.Equal("noNe", concrete.Original); } [Fact] @@ -941,6 +993,7 @@ public void CssContentStringLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("\"hi\"", concrete.Value); + Assert.Equal("\"hi\"", concrete.Original); } [Fact] @@ -955,6 +1008,7 @@ public void CssContentNoOpenQuoteNoCloseQuoteLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("no-open-quote no-close-quote", concrete.Value); + Assert.Equal("no-open-quote no-close-quote", concrete.Original); } [Fact] @@ -969,6 +1023,7 @@ public void CssContentUrlLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("url(\"test.html\")", concrete.Value); + Assert.Equal("url(\"test.html\")", concrete.Original); } [Fact] @@ -983,6 +1038,7 @@ public void CssContentStringsLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("\"how\" \"are\" \"you\"", concrete.Value); + Assert.Equal("\"how\" \"are\" \"you\"", concrete.Original); } [Fact] @@ -1010,6 +1066,7 @@ public void CssQuoteStringsLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("\"\\\"\" \"\\\"\"", concrete.Value); + Assert.Equal("\"\\\"\" \"\\\"\"", concrete.Original); } [Fact] @@ -1037,6 +1094,7 @@ public void CssQuoteStringsMultipleLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("\"\\\"\" \"\\\"\" \"`\" \"´\"", concrete.Value); + Assert.Equal("\"\\\"\" \"\\\"\" \"`\" \"´\"", concrete.Original); } [Fact] @@ -1064,6 +1122,7 @@ public void CssQuoteNoneLegal() Assert.False(concrete.IsInherited); Assert.True(concrete.HasValue); Assert.Equal("none", concrete.Value); + Assert.Equal("none", concrete.Original); } [Fact] @@ -1105,6 +1164,7 @@ public void CssWidowsZeroLegal() Assert.True(concrete.HasValue); //Assert.Equal(0, concrete.Count); Assert.Equal("0", concrete.Value); + Assert.Equal("0", concrete.Original); } [Fact] @@ -1120,6 +1180,7 @@ public void CssWidowsThreeLegal() Assert.True(concrete.HasValue); //Assert.Equal(3, concrete.Count); Assert.Equal("3", concrete.Value); + Assert.Equal("3", concrete.Original); } [Fact] @@ -1149,6 +1210,7 @@ public void CssUnicodeBidiEmbedLegal() Assert.True(concrete.HasValue); //Assert.Equal(UnicodeMode.Embed, concrete.State); Assert.Equal("embed", concrete.Value); + Assert.Equal("Embed", concrete.Original); } [Fact] @@ -1164,6 +1226,7 @@ public void CssUnicodeBidiIsolateLegal() Assert.True(concrete.HasValue); //Assert.Equal(UnicodeMode.Isolate, concrete.State); Assert.Equal("isolate", concrete.Value); + Assert.Equal("isolate", concrete.Original); } [Fact] @@ -1179,6 +1242,7 @@ public void CssUnicodeBidiBidiOverrideLegal() Assert.True(concrete.HasValue); //Assert.Equal(UnicodeMode.BidiOverride, concrete.State); Assert.Equal("bidi-override", concrete.Value); + Assert.Equal("Bidi-Override", concrete.Original); } [Fact] @@ -1194,6 +1258,7 @@ public void CssUnicodeBidiPlaintextLegal() Assert.True(concrete.HasValue); //Assert.Equal(UnicodeMode.Plaintext, concrete.State); Assert.Equal("plaintext", concrete.Value); + Assert.Equal("PLAINTEXT", concrete.Original); } [Fact]