diff --git a/CHANGELOG.md b/CHANGELOG.md index c352737..72e8386 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.0.0 + +- Enabled using `diff:ignoreAttributes` and `diff:ignoreChildren` together on the same element. +- Corrected list of attributes that is considered as boolean attributes. Removed `hidden`, added `inert`, `playsinline`, `shadowrootclonable`, `shadowrootdelegatesfocus`, and `shadowrootserializable`. +- Upgrade to v1.x of AngleSharp. + # 0.18.2 - Changed `CompareStrategy` such that it now can control the `IDiff` type that should be returned in case a difference is found in a comparison. This allows a comparer to embed additional context in the `IDiff` object. By [@SebastianStehle](https://github.com/SebastianStehle). diff --git a/src/.editorconfig b/src/.editorconfig index 8dea088..daaaa18 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -225,3 +225,6 @@ dotnet_naming_style.fields_begin_with__.required_prefix = _ dotnet_naming_style.fields_begin_with__.required_suffix = dotnet_naming_style.fields_begin_with__.word_separator = dotnet_naming_style.fields_begin_with__.capitalization = camel_case + +# MA0012: Do not raise reserved exception type +dotnet_diagnostic.MA0012.severity = none \ No newline at end of file diff --git a/src/AngleSharp.Diffing.Tests/AngleSharp.DiffingTests.csproj b/src/AngleSharp.Diffing.Tests/AngleSharp.DiffingTests.csproj index c3605ce..ec15b72 100644 --- a/src/AngleSharp.Diffing.Tests/AngleSharp.DiffingTests.csproj +++ b/src/AngleSharp.Diffing.Tests/AngleSharp.DiffingTests.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 false AngleSharp.Diffing.Tests AngleSharp.Diffing @@ -10,18 +10,18 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/AngleSharp.Diffing.Tests/Core/AttributeComparisonTest.cs b/src/AngleSharp.Diffing.Tests/Core/AttributeComparisonTest.cs index d7ec516..d8cc0ba 100644 --- a/src/AngleSharp.Diffing.Tests/Core/AttributeComparisonTest.cs +++ b/src/AngleSharp.Diffing.Tests/Core/AttributeComparisonTest.cs @@ -65,7 +65,7 @@ public void Test005() var test = ToAttributeComparisonSource(@"
", "foo"); var comparison = new AttributeComparison(control, test); - var (actualCtrlElm, actualTestElm) = comparison.GetAttributeElements(); + var (actualCtrlElm, actualTestElm) = comparison.AttributeElements; actualCtrlElm.ShouldBe(control.ElementSource.Node); actualTestElm.ShouldBe(test.ElementSource.Node); @@ -135,7 +135,7 @@ public void Test005() var test = ToAttributeComparisonSource(@"
", "foo"); var comparison = new AttributeComparison(control, test); - var (actualCtrlElm, actualTestElm) = comparison.GetAttributeElements(); + var (actualCtrlElm, actualTestElm) = comparison.AttributeElements; actualCtrlElm.ShouldBe(control.ElementSource.Node); actualTestElm.ShouldBe(test.ElementSource.Node); diff --git a/src/AngleSharp.Diffing.Tests/Core/DiffingEngineTestBase.cs b/src/AngleSharp.Diffing.Tests/Core/DiffingEngineTestBase.cs index 901b004..e5609b8 100644 --- a/src/AngleSharp.Diffing.Tests/Core/DiffingEngineTestBase.cs +++ b/src/AngleSharp.Diffing.Tests/Core/DiffingEngineTestBase.cs @@ -2,7 +2,7 @@ namespace AngleSharp.Diffing.Core; public abstract class DiffingEngineTestBase : DiffingTestBase { - public DiffingEngineTestBase(DiffingTestFixture fixture) : base(fixture) + protected DiffingEngineTestBase(DiffingTestFixture fixture) : base(fixture) { } @@ -24,7 +24,7 @@ protected static HtmlDiffer CreateHtmlDiffer( ); } - private class MockDiffingStrategy : IDiffingStrategy + private sealed class MockDiffingStrategy : IDiffingStrategy { private readonly Func? _nodeFilter; private readonly Func? _attrFilter; diff --git a/src/AngleSharp.Diffing.Tests/Core/HtmlDifferenceEngineTest.cs b/src/AngleSharp.Diffing.Tests/Core/HtmlDifferenceEngineTest.cs index 7f8ae45..1383304 100644 --- a/src/AngleSharp.Diffing.Tests/Core/HtmlDifferenceEngineTest.cs +++ b/src/AngleSharp.Diffing.Tests/Core/HtmlDifferenceEngineTest.cs @@ -451,7 +451,7 @@ private static IEnumerable NoneNodeMatcher(IDiffContext ctx, SourceC private static Func> SpecificIndexNodeMatcher(int index) => (ctx, controlNodes, testNodes) => { - return new List { new Comparison(controlNodes[index], testNodes[index]) }; + return new List { new(controlNodes[index], testNodes[index]) }; }; private static IEnumerable OneToOneNodeListMatcher( @@ -477,7 +477,7 @@ private static Func new List { - new AttributeComparison(ctrlAttrs[matchAttrName], testAttrs[matchAttrName] ) + new(ctrlAttrs[matchAttrName], testAttrs[matchAttrName] ) }; } @@ -510,14 +510,14 @@ private static Func SpecificAttrFilte #endregion #region CustomDiff - public record CustomNodeDiff : NodeDiff + public sealed record CustomNodeDiff : NodeDiff { public CustomNodeDiff(in Comparison comparison) : base(comparison) { } } - public record CustomAttrDiff : AttrDiff + public sealed record CustomAttrDiff : AttrDiff { public CustomAttrDiff(in AttributeComparison comparison) : base(comparison, AttrDiffKind.Unspecified) { diff --git a/src/AngleSharp.Diffing.Tests/DiffBuilderTest.cs b/src/AngleSharp.Diffing.Tests/DiffBuilderTest.cs index 9287f03..9769990 100644 --- a/src/AngleSharp.Diffing.Tests/DiffBuilderTest.cs +++ b/src/AngleSharp.Diffing.Tests/DiffBuilderTest.cs @@ -20,8 +20,8 @@ public void Test001() [Fact(DisplayName = "Builder throws if null is passed to control and test")] public void Test002() { - Should.Throw(() => DiffBuilder.Compare(null!)).ParamName.ShouldBe(nameof(DiffBuilder.Control)); - Should.Throw(() => DiffBuilder.Compare("").WithTest(null!)).ParamName.ShouldBe(nameof(DiffBuilder.Test)); + Should.Throw(() => DiffBuilder.Compare(null!)).ParamName.ShouldBe("value"); + Should.Throw(() => DiffBuilder.Compare("").WithTest(null!)).ParamName.ShouldBe("value"); } [Fact(DisplayName = "Calling Build() with DefaultOptions() returns expected diffs")] diff --git a/src/AngleSharp.Diffing.Tests/DiffingTestBase.cs b/src/AngleSharp.Diffing.Tests/DiffingTestBase.cs index af96fe0..41d41ce 100644 --- a/src/AngleSharp.Diffing.Tests/DiffingTestBase.cs +++ b/src/AngleSharp.Diffing.Tests/DiffingTestBase.cs @@ -4,11 +4,18 @@ public abstract class DiffingTestBase : IClassFixture { private readonly DiffingTestFixture _testFixture; + + public static readonly TheoryData SameAndSkipCompareResult = new() + { + CompareResult.Same, + CompareResult.Skip, + }; + protected IDiffContext DummyContext { get; } = new DiffContext(default(IElement), default(IElement)); protected INodeList EmptyNodeList => ToNodeList(""); - public DiffingTestBase(DiffingTestFixture fixture) + protected DiffingTestBase(DiffingTestFixture fixture) { _testFixture = fixture; } @@ -68,10 +75,4 @@ protected SourceMap ToSourceMap(string html, ComparisonSourceType sourceType = C var source = ToComparisonSource(html, sourceType); return new SourceMap(source); } - - public static TheoryData SameAndSkipCompareResult = new TheoryData - { - CompareResult.Same, - CompareResult.Skip, - }; } \ No newline at end of file diff --git a/src/AngleSharp.Diffing.Tests/GlobalSuppressions.cs b/src/AngleSharp.Diffing.Tests/GlobalSuppressions.cs new file mode 100644 index 0000000..0501c6d --- /dev/null +++ b/src/AngleSharp.Diffing.Tests/GlobalSuppressions.cs @@ -0,0 +1,9 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("Usage", "CA2201:Do not raise reserved exception types", Justification = "Not relevant in tests.")] +[assembly: SuppressMessage("Design", "CA1034:Nested types should not be visible", Justification = "Not relevant in tests")] diff --git a/src/AngleSharp.Diffing.Tests/Strategies/DiffingStrategyPipelineTest.cs b/src/AngleSharp.Diffing.Tests/Strategies/DiffingStrategyPipelineTest.cs index c071b28..9f985a7 100644 --- a/src/AngleSharp.Diffing.Tests/Strategies/DiffingStrategyPipelineTest.cs +++ b/src/AngleSharp.Diffing.Tests/Strategies/DiffingStrategyPipelineTest.cs @@ -6,7 +6,7 @@ public DiffingStrategyPipelineTest(DiffingTestFixture fixture) : base(fixture) { } - private FilterDecision NegateDecision(FilterDecision decision) => decision switch + private static FilterDecision NegateDecision(FilterDecision decision) => decision switch { FilterDecision.Keep => FilterDecision.Exclude, FilterDecision.Exclude => FilterDecision.Keep, diff --git a/src/AngleSharp.Diffing.Tests/Strategies/ElementStrategies/IgnoreAttributesElementComparerTest.cs b/src/AngleSharp.Diffing.Tests/Strategies/ElementStrategies/IgnoreAttributesElementComparerTest.cs index 67bcd96..261a655 100644 --- a/src/AngleSharp.Diffing.Tests/Strategies/ElementStrategies/IgnoreAttributesElementComparerTest.cs +++ b/src/AngleSharp.Diffing.Tests/Strategies/ElementStrategies/IgnoreAttributesElementComparerTest.cs @@ -32,4 +32,19 @@ public void Test002(string controlHtml) IgnoreAttributesElementComparer.Compare(comparison, CompareResult.Unknown).ShouldBe(CompareResult.SkipAttributes); IgnoreAttributesElementComparer.Compare(comparison, CompareResult.Unknown).ShouldBe(CompareResult.SkipAttributes); } + + [Theory(DisplayName = "When a control element has both 'diff:ignoreChildren' and a 'diff:ignoreAttributes'")] + [InlineData("", @"")] + [InlineData("", @"")] + public void Test003(string controlHtml, string testHtml) + { + var comparison = ToComparison(controlHtml, testHtml); + + IgnoreAttributesElementComparer.Compare(comparison, CompareResult.Same).ShouldBe(CompareResult.SkipAttributes); + IgnoreAttributesElementComparer.Compare(comparison, CompareResult.Unknown).ShouldBe(CompareResult.SkipAttributes); + IgnoreAttributesElementComparer.Compare(comparison, CompareResult.Skip).ShouldBe(CompareResult.Skip); + IgnoreAttributesElementComparer.Compare(comparison, CompareResult.SkipChildrenAndAttributes).ShouldBe(CompareResult.SkipChildrenAndAttributes); + IgnoreAttributesElementComparer.Compare(comparison, CompareResult.SkipChildren).ShouldBe(CompareResult.SkipChildrenAndAttributes); + IgnoreAttributesElementComparer.Compare(comparison, CompareResult.SkipAttributes).ShouldBe(CompareResult.SkipAttributes); + } } diff --git a/src/AngleSharp.Diffing.Tests/Strategies/ElementStrategies/IgnoreChildrenElementComparerTest.cs b/src/AngleSharp.Diffing.Tests/Strategies/ElementStrategies/IgnoreChildrenElementComparerTest.cs index 0fa89b9..96b064a 100644 --- a/src/AngleSharp.Diffing.Tests/Strategies/ElementStrategies/IgnoreChildrenElementComparerTest.cs +++ b/src/AngleSharp.Diffing.Tests/Strategies/ElementStrategies/IgnoreChildrenElementComparerTest.cs @@ -32,4 +32,19 @@ public void Test002(string controlHtml) IgnoreChildrenElementComparer.Compare(comparison, CompareResult.Unknown).ShouldBe(CompareResult.SkipChildren); IgnoreChildrenElementComparer.Compare(comparison, CompareResult.Unknown).ShouldBe(CompareResult.SkipChildren); } + + [Theory(DisplayName = "When a control element has both 'diff:ignoreChildren' and a 'diff:ignoreAttributes'")] + [InlineData("", @"")] + [InlineData("", @"")] + public void Test003(string controlHtml, string testHtml) + { + var comparison = ToComparison(controlHtml, testHtml); + + IgnoreChildrenElementComparer.Compare(comparison, CompareResult.Same).ShouldBe(CompareResult.SkipChildren); + IgnoreChildrenElementComparer.Compare(comparison, CompareResult.Unknown).ShouldBe(CompareResult.SkipChildren); + IgnoreChildrenElementComparer.Compare(comparison, CompareResult.Skip).ShouldBe(CompareResult.Skip); + IgnoreChildrenElementComparer.Compare(comparison, CompareResult.SkipChildrenAndAttributes).ShouldBe(CompareResult.SkipChildrenAndAttributes); + IgnoreChildrenElementComparer.Compare(comparison, CompareResult.SkipAttributes).ShouldBe(CompareResult.SkipChildrenAndAttributes); + IgnoreChildrenElementComparer.Compare(comparison, CompareResult.SkipChildren).ShouldBe(CompareResult.SkipChildren); + } } diff --git a/src/AngleSharp.Diffing.Tests/Strategies/TextNodeStrategies/TextNodeTestBase.cs b/src/AngleSharp.Diffing.Tests/Strategies/TextNodeStrategies/TextNodeTestBase.cs index 1b8fc0a..3df2e00 100644 --- a/src/AngleSharp.Diffing.Tests/Strategies/TextNodeStrategies/TextNodeTestBase.cs +++ b/src/AngleSharp.Diffing.Tests/Strategies/TextNodeStrategies/TextNodeTestBase.cs @@ -18,7 +18,7 @@ public abstract class TextNodeTestBase : DiffingTestBase public static readonly IEnumerable WhitespaceCharStrings = AllWhitespaceCharacters.Select(c => new string[] { c.ToString(CultureInfo.InvariantCulture) }).ToArray(); - public TextNodeTestBase(DiffingTestFixture fixture) : base(fixture) + protected TextNodeTestBase(DiffingTestFixture fixture) : base(fixture) { } } diff --git a/src/AngleSharp.Diffing.sln b/src/AngleSharp.Diffing.sln index c93f6cd..83fb1ab 100644 --- a/src/AngleSharp.Diffing.sln +++ b/src/AngleSharp.Diffing.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29230.61 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35312.102 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AngleSharp.Diffing", "AngleSharp.Diffing\AngleSharp.Diffing.csproj", "{2BFFA992-22C2-4A65-94D8-CA06E81D2364}" EndProject @@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AngleSharp.DiffingTests", " EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E8E3C8B4-92C3-4DB7-B920-D28651E24A57}" ProjectSection(SolutionItems) = preProject - ..\.editorconfig = ..\.editorconfig + .editorconfig = .editorconfig ..\tools\anglesharp.cake = ..\tools\anglesharp.cake ..\build.cake = ..\build.cake ..\build.ps1 = ..\build.ps1 diff --git a/src/AngleSharp.Diffing/AngleSharp.Diffing.csproj b/src/AngleSharp.Diffing/AngleSharp.Diffing.csproj index d115210..1c574ff 100644 --- a/src/AngleSharp.Diffing/AngleSharp.Diffing.csproj +++ b/src/AngleSharp.Diffing/AngleSharp.Diffing.csproj @@ -1,40 +1,44 @@ - - netstandard2.0 - true - + + netstandard2.0 + true + - - Provides a complete diffing model of HTML. - AngleSharp.Diffing - AngleSharp - AngleSharp.Diffing - MIT - https://anglesharp.github.io - logo.png - https://raw.github.com/AngleSharp/AngleSharp.Diffing/master/logo.png - html html5 css css3 dom library diffing anglesharp diff difference compare comparison testing - Egil Hansen - https://github.com/AngleSharp/AngleSharp.Diffing - git - true - true - snupkg - + + Provides a complete diffing model of HTML. + AngleSharp.Diffing + AngleSharp + AngleSharp.Diffing + MIT + https://anglesharp.github.io + logo.png + https://raw.github.com/AngleSharp/AngleSharp.Diffing/master/logo.png + html html5 css css3 dom library diffing anglesharp diff difference compare comparison testing + Egil Hansen + https://github.com/AngleSharp/AngleSharp.Diffing + git + true + true + snupkg + $(NoWarn);NU5104 + - - - + + + - - - - + + + all + runtime; build; native; contentfiles; analyzers + + + + - - - - + + + \ No newline at end of file diff --git a/src/AngleSharp.Diffing/Core/AttributeComparison.cs b/src/AngleSharp.Diffing/Core/AttributeComparison.cs index 18a0da7..5f69f71 100644 --- a/src/AngleSharp.Diffing/Core/AttributeComparison.cs +++ b/src/AngleSharp.Diffing/Core/AttributeComparison.cs @@ -1,3 +1,5 @@ +using System.Runtime.InteropServices; + namespace AngleSharp.Diffing.Core; /// @@ -5,11 +7,12 @@ namespace AngleSharp.Diffing.Core; /// /// Gets the control attribute which the attribute is supposed to match. /// Gets the test attribute which should be compared to the attribute. +[StructLayout(LayoutKind.Auto)] public readonly record struct AttributeComparison(in AttributeComparisonSource Control, in AttributeComparisonSource Test) { /// /// Returns the control and test elements which the control and test attributes belongs to. /// - public (IElement ControlElement, IElement TestElement) GetAttributeElements() + public readonly (IElement ControlElement, IElement TestElement) AttributeElements => ((IElement)Control.ElementSource.Node, (IElement)Test.ElementSource.Node); } diff --git a/src/AngleSharp.Diffing/Core/AttributeComparisonSource.cs b/src/AngleSharp.Diffing/Core/AttributeComparisonSource.cs index 4f9939f..a5a1e68 100644 --- a/src/AngleSharp.Diffing/Core/AttributeComparisonSource.cs +++ b/src/AngleSharp.Diffing/Core/AttributeComparisonSource.cs @@ -30,6 +30,7 @@ namespace AngleSharp.Diffing.Core; /// /// Name of the attribute. /// The source of the element the attribute belongs to. + [SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "Attribute names should be safe to lowercase.")] public AttributeComparisonSource(string attributeName, in ComparisonSource elementSource) { if (string.IsNullOrEmpty(attributeName)) diff --git a/src/AngleSharp.Diffing/Core/CompareDecision.cs b/src/AngleSharp.Diffing/Core/CompareDecision.cs index cc0942e..73d626d 100644 --- a/src/AngleSharp.Diffing/Core/CompareDecision.cs +++ b/src/AngleSharp.Diffing/Core/CompareDecision.cs @@ -9,7 +9,7 @@ public enum CompareDecision /// /// Use when the compare result is unknown. /// - Unknown = 0, + None = 0, /// /// Use when the two compared nodes or attributes are the same. /// diff --git a/src/AngleSharp.Diffing/Core/CompareResult.cs b/src/AngleSharp.Diffing/Core/CompareResult.cs index 0d4ea28..cd3de65 100644 --- a/src/AngleSharp.Diffing/Core/CompareResult.cs +++ b/src/AngleSharp.Diffing/Core/CompareResult.cs @@ -10,39 +10,44 @@ public readonly record struct CompareResult(CompareDecision Decision, IDiff? Dif /// /// Use when the compare result is unknown. /// - public static readonly CompareResult Unknown = default; + public static readonly CompareResult Unknown; /// /// Use when the two compared nodes or attributes are the same. /// - public static readonly CompareResult Same = new CompareResult(CompareDecision.Same); + public static readonly CompareResult Same = new(CompareDecision.Same); /// /// Use when the comparison should be skipped and any child-nodes or attributes skipped as well. /// - public static readonly CompareResult Skip = new CompareResult(CompareDecision.Skip); + public static readonly CompareResult Skip = new(CompareDecision.Skip); /// /// Use when the comparison should skip any child-nodes. /// - public static readonly CompareResult SkipChildren = new CompareResult(CompareDecision.SkipChildren); + public static readonly CompareResult SkipChildren = new(CompareDecision.SkipChildren); /// /// Use when the comparison should skip any attributes. /// - public static readonly CompareResult SkipAttributes = new CompareResult(CompareDecision.SkipAttributes); + public static readonly CompareResult SkipAttributes = new(CompareDecision.SkipAttributes); + + /// + /// Use when the comparison should skip any attributes. + /// + public static readonly CompareResult SkipChildrenAndAttributes = new(CompareDecision.SkipChildren | CompareDecision.SkipAttributes); /// /// Use when the two compared nodes or attributes are the different. /// - public static CompareResult Different => new CompareResult(CompareDecision.Different); + public static CompareResult Different => new(CompareDecision.Different); /// /// Use when the two compared nodes or attributes are the different. /// /// The associated describing the difference. /// Returns a with set to . - public static CompareResult FromDiff(IDiff diff) => new CompareResult(CompareDecision.Different, diff); + public static CompareResult FromDiff(IDiff diff) => new(CompareDecision.Different, diff); /// /// Checks if a is either a or . diff --git a/src/AngleSharp.Diffing/Core/Comparison.cs b/src/AngleSharp.Diffing/Core/Comparison.cs index cdab391..41742e8 100644 --- a/src/AngleSharp.Diffing/Core/Comparison.cs +++ b/src/AngleSharp.Diffing/Core/Comparison.cs @@ -1,3 +1,5 @@ +using System.Runtime.InteropServices; + namespace AngleSharp.Diffing.Core; /// @@ -5,6 +7,7 @@ namespace AngleSharp.Diffing.Core; /// /// Gets the control source in the comparison. /// Gets the test source in the comparison. +[StructLayout(LayoutKind.Auto)] public readonly record struct Comparison(in ComparisonSource Control, in ComparisonSource Test) { /// diff --git a/src/AngleSharp.Diffing/Core/ComparisonSource.cs b/src/AngleSharp.Diffing/Core/ComparisonSource.cs index 13025e2..f900d64 100644 --- a/src/AngleSharp.Diffing/Core/ComparisonSource.cs +++ b/src/AngleSharp.Diffing/Core/ComparisonSource.cs @@ -64,6 +64,7 @@ public ComparisonSource(INode node, int index, string parentsPath, ComparisonSou /// /// /// + [SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "Nodenames are safe to lower case.")] public static string GetNodePathSegment(INode node) { var index = GetPathIndex(node); diff --git a/src/AngleSharp.Diffing/Core/SourceType.cs b/src/AngleSharp.Diffing/Core/ComparisonSourceType.cs similarity index 100% rename from src/AngleSharp.Diffing/Core/SourceType.cs rename to src/AngleSharp.Diffing/Core/ComparisonSourceType.cs diff --git a/src/AngleSharp.Diffing/Core/DiffTarget.cs b/src/AngleSharp.Diffing/Core/DiffTarget.cs index af6579b..a4f400b 100644 --- a/src/AngleSharp.Diffing/Core/DiffTarget.cs +++ b/src/AngleSharp.Diffing/Core/DiffTarget.cs @@ -30,24 +30,3 @@ public enum DiffTarget /// Text } - -/// -/// Helper methods for working with . -/// -public static class NodeTypeExtensions -{ - /// - /// Gets the diff target based on the node type. - /// - /// Mode type to get the diff target off. - public static DiffTarget ToDiffTarget(this NodeType nodeType) - { - return nodeType switch - { - NodeType.Element => DiffTarget.Element, - NodeType.Comment => DiffTarget.Comment, - NodeType.Text => DiffTarget.Text, - _ => DiffTarget.Node - }; - } -} diff --git a/src/AngleSharp.Diffing/Core/FilterDecision.cs b/src/AngleSharp.Diffing/Core/FilterDecision.cs index 1274efb..ad80d89 100644 --- a/src/AngleSharp.Diffing/Core/FilterDecision.cs +++ b/src/AngleSharp.Diffing/Core/FilterDecision.cs @@ -14,19 +14,3 @@ public enum FilterDecision /// Exclude } - -/// -/// Helper methods for . -/// -public static class FilterDecisionExtensions -{ - /// - /// Gets whether the is . - /// - public static bool IsExclude(this FilterDecision decision) => decision == FilterDecision.Exclude; - - /// - /// Gets whether the is . - /// - public static bool IsKeep(this FilterDecision decision) => decision == FilterDecision.Keep; -} diff --git a/src/AngleSharp.Diffing/Core/FilterDecisionExtensions.cs b/src/AngleSharp.Diffing/Core/FilterDecisionExtensions.cs new file mode 100644 index 0000000..ba7d609 --- /dev/null +++ b/src/AngleSharp.Diffing/Core/FilterDecisionExtensions.cs @@ -0,0 +1,17 @@ +namespace AngleSharp.Diffing.Core; + +/// +/// Helper methods for . +/// +public static class FilterDecisionExtensions +{ + /// + /// Gets whether the is . + /// + public static bool IsExclude(this FilterDecision decision) => decision == FilterDecision.Exclude; + + /// + /// Gets whether the is . + /// + public static bool IsKeep(this FilterDecision decision) => decision == FilterDecision.Keep; +} diff --git a/src/AngleSharp.Diffing/Core/HtmlDifferenceEngine.cs b/src/AngleSharp.Diffing/Core/HtmlDifferenceEngine.cs index 8065dac..575ca96 100644 --- a/src/AngleSharp.Diffing/Core/HtmlDifferenceEngine.cs +++ b/src/AngleSharp.Diffing/Core/HtmlDifferenceEngine.cs @@ -90,13 +90,13 @@ private IEnumerable CompareNode(in Comparison comparison) if (compareRes.Decision.HasFlag(CompareDecision.Different)) { IDiff diff = compareRes.Diff ?? new NodeDiff(comparison); - return new[] { diff }; + return [diff]; } return Array.Empty(); } - private IEnumerable CompareElement(in Comparison comparison) + private List CompareElement(in Comparison comparison) { var result = new List(); diff --git a/src/AngleSharp.Diffing/Core/NodeTypeExtensions.cs b/src/AngleSharp.Diffing/Core/NodeTypeExtensions.cs new file mode 100644 index 0000000..4467e48 --- /dev/null +++ b/src/AngleSharp.Diffing/Core/NodeTypeExtensions.cs @@ -0,0 +1,22 @@ +namespace AngleSharp.Diffing.Core; + +/// +/// Helper methods for working with . +/// +public static class NodeTypeExtensions +{ + /// + /// Gets the diff target based on the node type. + /// + /// Mode type to get the diff target off. + public static DiffTarget ToDiffTarget(this NodeType nodeType) + { + return nodeType switch + { + NodeType.Element => DiffTarget.Element, + NodeType.Comment => DiffTarget.Comment, + NodeType.Text => DiffTarget.Text, + _ => DiffTarget.Node + }; + } +} diff --git a/src/AngleSharp.Diffing/Core/SourceMap.cs b/src/AngleSharp.Diffing/Core/SourceMap.cs index 47e504d..4f99c8d 100644 --- a/src/AngleSharp.Diffing/Core/SourceMap.cs +++ b/src/AngleSharp.Diffing/Core/SourceMap.cs @@ -6,8 +6,8 @@ namespace AngleSharp.Diffing.Core; [SuppressMessage("Naming", "CA1710:Identifiers should have correct suffix")] public class SourceMap : IEnumerable { - private readonly HashSet _matched = new HashSet(); - private readonly Dictionary _sources = new Dictionary(); + private readonly HashSet _matched = new(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary _sources = new(StringComparer.OrdinalIgnoreCase); /// /// Gets the type of the sources in the collection. diff --git a/src/AngleSharp.Diffing/DiffBuilder.cs b/src/AngleSharp.Diffing/DiffBuilder.cs index ee40b9e..bf94b6c 100644 --- a/src/AngleSharp.Diffing/DiffBuilder.cs +++ b/src/AngleSharp.Diffing/DiffBuilder.cs @@ -17,12 +17,12 @@ public class DiffBuilder /// /// Gets or sets the control markup string. /// - public string Control { get => _control; set => _control = value ?? throw new ArgumentNullException(nameof(Control)); } + public string Control { get => _control; set => _control = value ?? throw new ArgumentNullException(nameof(value)); } /// /// Gets or sets the test markup string. /// - public string Test { get => _test; set => _test = value ?? throw new ArgumentNullException(nameof(Test)); } + public string Test { get => _test; set => _test = value ?? throw new ArgumentNullException(nameof(value)); } private DiffBuilder(string control) { diff --git a/src/AngleSharp.Diffing/Extensions/NodeListExtensions.cs b/src/AngleSharp.Diffing/Extensions/AngleSharpDomExtensions.cs similarity index 95% rename from src/AngleSharp.Diffing/Extensions/NodeListExtensions.cs rename to src/AngleSharp.Diffing/Extensions/AngleSharpDomExtensions.cs index 14ca9d5..2049656 100644 --- a/src/AngleSharp.Diffing/Extensions/NodeListExtensions.cs +++ b/src/AngleSharp.Diffing/Extensions/AngleSharpDomExtensions.cs @@ -34,5 +34,5 @@ public static IEnumerable ToComparisonSourceList(this IEnumera /// Creates a comparison source from a node. /// public static ComparisonSource ToComparisonSource(this INode node, int index, ComparisonSourceType sourceType, string path = "") - => new ComparisonSource(node, index, path, sourceType); + => new(node, index, path, sourceType); } diff --git a/src/AngleSharp.Diffing/Extensions/EmptyHtmlCollection.cs b/src/AngleSharp.Diffing/Extensions/EmptyHtmlCollection.cs index be9c1ac..2cb0435 100644 --- a/src/AngleSharp.Diffing/Extensions/EmptyHtmlCollection.cs +++ b/src/AngleSharp.Diffing/Extensions/EmptyHtmlCollection.cs @@ -8,10 +8,12 @@ public class EmptyHtmlCollection : IHtmlCollection where T : IElement { /// [SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations")] + [SuppressMessage("Usage", "CA2201:Do not raise reserved exception types")] public T this[int index] => throw new IndexOutOfRangeException(); /// [SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations")] + [SuppressMessage("Usage", "CA2201:Do not raise reserved exception types")] public T this[string id] => throw new IndexOutOfRangeException(); /// diff --git a/src/AngleSharp.Diffing/Extensions/UnexpectedDOMTreeStructureException.cs b/src/AngleSharp.Diffing/Extensions/UnexpectedDOMTreeStructureException.cs index cd77df0..74e27d7 100644 --- a/src/AngleSharp.Diffing/Extensions/UnexpectedDOMTreeStructureException.cs +++ b/src/AngleSharp.Diffing/Extensions/UnexpectedDOMTreeStructureException.cs @@ -13,6 +13,17 @@ public sealed class UnexpectedDOMTreeStructureException : Exception public UnexpectedDOMTreeStructureException() : base("The DOM tree structure was not as expected by AngleSharp.Diffing.") { } - private UnexpectedDOMTreeStructureException(SerializationInfo info, StreamingContext context) - : base(info, context) { } + /// + /// Creates an instance of the . + /// + public UnexpectedDOMTreeStructureException(string message) : base(message) + { + } + + /// + /// Creates an instance of the . + /// + public UnexpectedDOMTreeStructureException(string message, Exception innerException) : base(message, innerException) + { + } } diff --git a/src/AngleSharp.Diffing/Strategies/AttributeStrategies/BooleanAttributeComparer.cs b/src/AngleSharp.Diffing/Strategies/AttributeStrategies/BooleanAttributeComparer.cs index 889badc..feb77b2 100644 --- a/src/AngleSharp.Diffing/Strategies/AttributeStrategies/BooleanAttributeComparer.cs +++ b/src/AngleSharp.Diffing/Strategies/AttributeStrategies/BooleanAttributeComparer.cs @@ -5,7 +5,7 @@ /// public class BooleanAttributeComparer { - private static readonly HashSet BooleanAttributesSet = new HashSet() + private static readonly HashSet BooleanAttributesSet = new(StringComparer.OrdinalIgnoreCase) { "allowfullscreen", "allowpaymentrequest", @@ -18,7 +18,7 @@ public class BooleanAttributeComparer "defer", "disabled", "formnovalidate", - "hidden", + "inert", "ismap", "itemscope", "loop", @@ -27,10 +27,14 @@ public class BooleanAttributeComparer "nomodule", "novalidate", "open", + "playsinline", "readonly", "required", "reversed", "selected", + "shadowrootclonable", + "shadowrootdelegatesfocus", + "shadowrootserializable", "typemustmatch" }; diff --git a/src/AngleSharp.Diffing/Strategies/AttributeStrategies/ClassAttributeComparer.cs b/src/AngleSharp.Diffing/Strategies/AttributeStrategies/ClassAttributeComparer.cs index cfe136b..5cd59c5 100644 --- a/src/AngleSharp.Diffing/Strategies/AttributeStrategies/ClassAttributeComparer.cs +++ b/src/AngleSharp.Diffing/Strategies/AttributeStrategies/ClassAttributeComparer.cs @@ -18,11 +18,11 @@ public static CompareResult Compare(in AttributeComparison comparison, CompareRe if (!IsBothClassAttributes(comparison)) return CompareResult.FromDiff(new AttrDiff(comparison, AttrDiffKind.Name)); - var (ctrlElm, testElm) = comparison.GetAttributeElements(); + var (ctrlElm, testElm) = comparison.AttributeElements; if (ctrlElm.ClassList.Length != testElm.ClassList.Length) return CompareResult.FromDiff(new AttrDiff(comparison, AttrDiffKind.Value)); - return ctrlElm.ClassList.All(x => testElm.ClassList.Contains(x)) + return ctrlElm.ClassList.All(x => testElm.ClassList.Contains(x, StringComparer.Ordinal)) ? CompareResult.Same : CompareResult.FromDiff(new AttrDiff(comparison, AttrDiffKind.Value)); } diff --git a/src/AngleSharp.Diffing/Strategies/AttributeStrategies/OrderingStyleAttributeComparer.cs b/src/AngleSharp.Diffing/Strategies/AttributeStrategies/OrderingStyleAttributeComparer.cs index 4e3d830..19fcb5e 100644 --- a/src/AngleSharp.Diffing/Strategies/AttributeStrategies/OrderingStyleAttributeComparer.cs +++ b/src/AngleSharp.Diffing/Strategies/AttributeStrategies/OrderingStyleAttributeComparer.cs @@ -26,7 +26,7 @@ private static bool IsStyleAttributeComparison(in AttributeComparison comparison private static CompareResult CompareElementStyle(in AttributeComparison comparison) { - var (ctrlElm, testElm) = comparison.GetAttributeElements(); + var (ctrlElm, testElm) = comparison.AttributeElements; var ctrlStyle = ctrlElm.GetStyle(); var testStyle = testElm.GetStyle(); return CompareCssStyleDeclarations(ctrlStyle, testStyle) @@ -39,8 +39,8 @@ private static bool CompareCssStyleDeclarations(ICssStyleDeclaration control, IC if (control.Length != test.Length) return false; - var orderedControl = control.CssText.Split(';').Select(x => x.Trim()).OrderBy(x => x); - var orderedTest = test.CssText.Split(';').Select(x => x.Trim()).OrderBy(x => x); + var orderedControl = control.CssText.Split(';').Select(x => x.Trim()).OrderBy(x => x, StringComparer.Ordinal); + var orderedTest = test.CssText.Split(';').Select(x => x.Trim()).OrderBy(x => x, StringComparer.Ordinal); return orderedControl.SequenceEqual(orderedTest, StringComparer.Ordinal); } diff --git a/src/AngleSharp.Diffing/Strategies/AttributeStrategies/StyleAttributeComparer.cs b/src/AngleSharp.Diffing/Strategies/AttributeStrategies/StyleAttributeComparer.cs index 00dfaee..8b41cdf 100644 --- a/src/AngleSharp.Diffing/Strategies/AttributeStrategies/StyleAttributeComparer.cs +++ b/src/AngleSharp.Diffing/Strategies/AttributeStrategies/StyleAttributeComparer.cs @@ -26,7 +26,7 @@ private static bool IsStyleAttributeComparison(in AttributeComparison comparison private static CompareResult CompareElementStyle(in AttributeComparison comparison) { - var (ctrlElm, testElm) = comparison.GetAttributeElements(); + var (ctrlElm, testElm) = comparison.AttributeElements; var ctrlStyle = ctrlElm.GetStyle(); var testStyle = testElm.GetStyle(); return CompareCssStyleDeclarations(ctrlStyle, testStyle) diff --git a/src/AngleSharp.Diffing/Strategies/DiffingStrategyPipeline.cs b/src/AngleSharp.Diffing/Strategies/DiffingStrategyPipeline.cs index 4856f0f..b4348c0 100644 --- a/src/AngleSharp.Diffing/Strategies/DiffingStrategyPipeline.cs +++ b/src/AngleSharp.Diffing/Strategies/DiffingStrategyPipeline.cs @@ -6,12 +6,12 @@ namespace AngleSharp.Diffing.Strategies; /// public class DiffingStrategyPipeline : IDiffingStrategy, IDiffingStrategyCollection { - private readonly List> _nodeFilters = new List>(); - private readonly List> _attrsFilters = new List>(); - private readonly List> _nodeMatchers = new List>(); - private readonly List> _attrsMatchers = new List>(); - private readonly List> _nodeComparers = new List>(); - private readonly List> _attrComparers = new List>(); + private readonly List> _nodeFilters = new(); + private readonly List> _attrsFilters = new(); + private readonly List> _nodeMatchers = new(); + private readonly List> _attrsMatchers = new(); + private readonly List> _nodeComparers = new(); + private readonly List> _attrComparers = new(); /// /// Gets whether the pipeline have any matchers registered. @@ -64,7 +64,7 @@ public IEnumerable Match(IDiffContext context, SourceMap co public CompareResult Compare(in AttributeComparison comparison) => Compare(comparison, _attrComparers, CompareResult.Different); /// - public IDiffingStrategyCollection AddFilter(FilterStrategy filterStrategy, StrategyType strategyType) + public IDiffingStrategyCollection AddFilter(FilterStrategy filterStrategy, StrategyType strategyType = StrategyType.Specialized) { if (strategyType == StrategyType.Specialized) _nodeFilters.Add(filterStrategy); @@ -74,7 +74,7 @@ public IDiffingStrategyCollection AddFilter(FilterStrategy fil } /// - public IDiffingStrategyCollection AddFilter(FilterStrategy filterStrategy, StrategyType strategyType) + public IDiffingStrategyCollection AddFilter(FilterStrategy filterStrategy, StrategyType strategyType = StrategyType.Specialized) { if (strategyType == StrategyType.Specialized) _attrsFilters.Add(filterStrategy); @@ -84,7 +84,7 @@ public IDiffingStrategyCollection AddFilter(FilterStrategy - public IDiffingStrategyCollection AddMatcher(MatchStrategy matchStrategy, StrategyType strategyType) + public IDiffingStrategyCollection AddMatcher(MatchStrategy matchStrategy, StrategyType strategyType = StrategyType.Specialized) { if (strategyType == StrategyType.Specialized) _nodeMatchers.Insert(0, matchStrategy); @@ -94,7 +94,7 @@ public IDiffingStrategyCollection AddMatcher(MatchStrategy - public IDiffingStrategyCollection AddMatcher(MatchStrategy matchStrategy, StrategyType strategyType) + public IDiffingStrategyCollection AddMatcher(MatchStrategy matchStrategy, StrategyType strategyType = StrategyType.Specialized) { if (strategyType == StrategyType.Specialized) _attrsMatchers.Insert(0, matchStrategy); @@ -104,7 +104,7 @@ public IDiffingStrategyCollection AddMatcher(MatchStrategy - public IDiffingStrategyCollection AddComparer(CompareStrategy compareStrategy, StrategyType strategyType) + public IDiffingStrategyCollection AddComparer(CompareStrategy compareStrategy, StrategyType strategyType = StrategyType.Specialized) { if (strategyType == StrategyType.Specialized) _nodeComparers.Add(compareStrategy); @@ -114,7 +114,7 @@ public IDiffingStrategyCollection AddComparer(CompareStrategy compar } /// - public IDiffingStrategyCollection AddComparer(CompareStrategy compareStrategy, StrategyType strategyType) + public IDiffingStrategyCollection AddComparer(CompareStrategy compareStrategy, StrategyType strategyType = StrategyType.Specialized) { if (strategyType == StrategyType.Specialized) _attrComparers.Add(compareStrategy); @@ -123,7 +123,7 @@ public IDiffingStrategyCollection AddComparer(CompareStrategy(in T source, List> filterStrategies) + private static FilterDecision Filter(in T source, List> filterStrategies) { var result = FilterDecision.Keep; for (int i = 0; i < filterStrategies.Count; i++) @@ -133,7 +133,7 @@ private FilterDecision Filter(in T source, List> filterStra return result; } - private CompareResult Compare(in TComparison comparison, List> compareStrategies, CompareResult initialResult) + private static CompareResult Compare(in TComparison comparison, List> compareStrategies, CompareResult initialResult) { var result = initialResult; foreach (var comparer in compareStrategies) diff --git a/src/AngleSharp.Diffing/Strategies/ElementStrategies/DiffMatchSelectorReturnedTooManyResultsException.cs b/src/AngleSharp.Diffing/Strategies/ElementStrategies/DiffMatchSelectorReturnedTooManyResultsException.cs index aaac7a6..390ccbc 100644 --- a/src/AngleSharp.Diffing/Strategies/ElementStrategies/DiffMatchSelectorReturnedTooManyResultsException.cs +++ b/src/AngleSharp.Diffing/Strategies/ElementStrategies/DiffMatchSelectorReturnedTooManyResultsException.cs @@ -27,11 +27,4 @@ public DiffMatchSelectorReturnedTooManyResultsException(string message) : base(m public DiffMatchSelectorReturnedTooManyResultsException(string message, Exception innerException) : base(message, innerException) { } - - /// - /// Creates a . - /// - protected DiffMatchSelectorReturnedTooManyResultsException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } } \ No newline at end of file diff --git a/src/AngleSharp.Diffing/Strategies/ElementStrategies/IgnoreAttributesElementComparer.cs b/src/AngleSharp.Diffing/Strategies/ElementStrategies/IgnoreAttributesElementComparer.cs index 7bc25dd..a5cd052 100644 --- a/src/AngleSharp.Diffing/Strategies/ElementStrategies/IgnoreAttributesElementComparer.cs +++ b/src/AngleSharp.Diffing/Strategies/ElementStrategies/IgnoreAttributesElementComparer.cs @@ -12,12 +12,20 @@ public static class IgnoreAttributesElementComparer /// public static CompareResult Compare(in Comparison comparison, CompareResult currentDecision) { - if (currentDecision == CompareResult.Skip) + if (currentDecision == CompareResult.Skip || currentDecision == CompareResult.SkipAttributes || currentDecision == CompareResult.SkipChildrenAndAttributes) return currentDecision; - return ControlHasTruthyIgnoreAttributesAttribute(comparison) - ? CompareResult.SkipAttributes - : currentDecision; + if (!ControlHasTruthyIgnoreAttributesAttribute(comparison)) + return currentDecision; + + return currentDecision.Decision switch + { + CompareDecision.None => CompareResult.SkipAttributes, + CompareDecision.Same => CompareResult.SkipAttributes, + CompareDecision.Different => CompareResult.SkipAttributes, + CompareDecision.SkipChildren => CompareResult.SkipChildrenAndAttributes, + _ => currentDecision, + }; } private static bool ControlHasTruthyIgnoreAttributesAttribute(in Comparison comparison) diff --git a/src/AngleSharp.Diffing/Strategies/ElementStrategies/IgnoreChildrenElementComparer.cs b/src/AngleSharp.Diffing/Strategies/ElementStrategies/IgnoreChildrenElementComparer.cs index cc19f1f..966fe7b 100644 --- a/src/AngleSharp.Diffing/Strategies/ElementStrategies/IgnoreChildrenElementComparer.cs +++ b/src/AngleSharp.Diffing/Strategies/ElementStrategies/IgnoreChildrenElementComparer.cs @@ -12,12 +12,20 @@ public static class IgnoreChildrenElementComparer /// public static CompareResult Compare(in Comparison comparison, CompareResult currentDecision) { - if (currentDecision == CompareResult.Skip) + if (currentDecision == CompareResult.Skip || currentDecision == CompareResult.SkipChildren || currentDecision == CompareResult.SkipChildrenAndAttributes) return currentDecision; - return ControlHasTruthyIgnoreChildrenAttribute(comparison) - ? CompareResult.SkipChildren - : currentDecision; + if (!ControlHasTruthyIgnoreChildrenAttribute(comparison)) + return currentDecision; + + return currentDecision.Decision switch + { + CompareDecision.None => CompareResult.SkipChildren, + CompareDecision.Same => CompareResult.SkipChildren, + CompareDecision.Different => CompareResult.SkipChildren, + CompareDecision.SkipAttributes => CompareResult.SkipChildrenAndAttributes, + _ => currentDecision, + }; } private static bool ControlHasTruthyIgnoreChildrenAttribute(in Comparison comparison) diff --git a/src/AngleSharp.Diffing/Strategies/IDiffingStrategyCollection.cs b/src/AngleSharp.Diffing/Strategies/IDiffingStrategyCollection.cs index 6a6768f..6da2532 100644 --- a/src/AngleSharp.Diffing/Strategies/IDiffingStrategyCollection.cs +++ b/src/AngleSharp.Diffing/Strategies/IDiffingStrategyCollection.cs @@ -3,6 +3,7 @@ namespace AngleSharp.Diffing.Strategies; /// /// Represents a collection of diffing strategies. /// +[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "Ignored.")] public interface IDiffingStrategyCollection { /// diff --git a/src/AngleSharp.Diffing/Strategies/TextNodeStrategies/TextNodeComparer.cs b/src/AngleSharp.Diffing/Strategies/TextNodeStrategies/TextNodeComparer.cs index bfe64f0..9f6f5fe 100644 --- a/src/AngleSharp.Diffing/Strategies/TextNodeStrategies/TextNodeComparer.cs +++ b/src/AngleSharp.Diffing/Strategies/TextNodeStrategies/TextNodeComparer.cs @@ -11,7 +11,7 @@ public class TextNodeComparer private const string WHITESPACE_ATTR_NAME = "diff:whitespace"; private const string IGNORECASE_ATTR_NAME = "diff:ignorecase"; private const string REGEX_ATTR_NAME = "diff:regex"; - private static readonly Regex WhitespaceReplace = new Regex(@"\s+", RegexOptions.Compiled | RegexOptions.CultureInvariant, TimeSpan.FromSeconds(5)); + private static readonly Regex WhitespaceReplace = new(@"\s+", RegexOptions.Compiled | RegexOptions.CultureInvariant, TimeSpan.FromSeconds(5)); /// /// Gets the whitespace option of the comparer instance. diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 3a59f95..bbbcb7b 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,19 +1,26 @@ - - 0.18.2 - + + 1.0.0 + - - enable - 11.0 - enable - CS8600;CS8602;CS8603;CS8625 - true - ../Key.snk - + + enable + latest + enable + CS8600;CS8602;CS8603;CS8625 + true + ../Key.snk + - - - - + + AllEnabledByDefault + true + latest + true + + + + + + \ No newline at end of file