Skip to content

Commit

Permalink
release v1.0.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	src/AngleSharp.Diffing.Tests/Core/HtmlDifferenceEngineTest.cs
#	src/AngleSharp.Diffing/Core/AttributeComparison.cs
#	src/AngleSharp.Diffing/Core/AttributeComparisonSource.cs
#	src/AngleSharp.Diffing/Core/CompareDecision.cs
#	src/AngleSharp.Diffing/Core/CompareResult.cs
#	src/AngleSharp.Diffing/Core/Comparison.cs
#	src/AngleSharp.Diffing/Core/ComparisonSource.cs
#	src/AngleSharp.Diffing/Core/HtmlDifferenceEngine.cs
#	src/AngleSharp.Diffing/Strategies/AttributeStrategies/OrderingStyleAttributeComparer.cs
#	src/AngleSharp.Diffing/Strategies/AttributeStrategies/StyleAttributeComparer.cs
#	src/Directory.Build.props
  • Loading branch information
egil committed Oct 14, 2024
2 parents 7a0c5e1 + 1118b70 commit 5694c9b
Show file tree
Hide file tree
Showing 43 changed files with 271 additions and 169 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
3 changes: 3 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions src/AngleSharp.Diffing.Tests/AngleSharp.DiffingTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<AssemblyName>AngleSharp.Diffing.Tests</AssemblyName>
<RootNamespace>AngleSharp.Diffing</RootNamespace>
Expand All @@ -10,18 +10,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.0.1">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Shouldly" Version="4.1.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions src/AngleSharp.Diffing.Tests/Core/AttributeComparisonTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void Test005()
var test = ToAttributeComparisonSource(@"<br foo=""bar"">", "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);
Expand Down Expand Up @@ -135,7 +135,7 @@ public void Test005()
var test = ToAttributeComparisonSource(@"<br foo=""bar"">", "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);
Expand Down
4 changes: 2 additions & 2 deletions src/AngleSharp.Diffing.Tests/Core/DiffingEngineTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand All @@ -24,7 +24,7 @@ protected static HtmlDiffer CreateHtmlDiffer(
);
}

private class MockDiffingStrategy : IDiffingStrategy
private sealed class MockDiffingStrategy : IDiffingStrategy
{
private readonly Func<ComparisonSource, FilterDecision>? _nodeFilter;
private readonly Func<AttributeComparisonSource, FilterDecision>? _attrFilter;
Expand Down
8 changes: 4 additions & 4 deletions src/AngleSharp.Diffing.Tests/Core/HtmlDifferenceEngineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ private static IEnumerable<Comparison> NoneNodeMatcher(IDiffContext ctx, SourceC
private static Func<IDiffContext, SourceCollection, SourceCollection, IEnumerable<Comparison>> SpecificIndexNodeMatcher(int index)
=> (ctx, controlNodes, testNodes) =>
{
return new List<Comparison> { new Comparison(controlNodes[index], testNodes[index]) };
return new List<Comparison> { new(controlNodes[index], testNodes[index]) };
};

private static IEnumerable<Comparison> OneToOneNodeListMatcher(
Expand All @@ -477,7 +477,7 @@ private static Func<IDiffContext, SourceMap, SourceMap, IEnumerable<AttributeCom
{
return (ctx, ctrlAttrs, testAttrs) => new List<AttributeComparison>
{
new AttributeComparison(ctrlAttrs[matchAttrName], testAttrs[matchAttrName] )
new(ctrlAttrs[matchAttrName], testAttrs[matchAttrName] )
};
}

Expand Down Expand Up @@ -510,14 +510,14 @@ private static Func<AttributeComparisonSource, FilterDecision> 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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/AngleSharp.Diffing.Tests/DiffBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public void Test001()
[Fact(DisplayName = "Builder throws if null is passed to control and test")]
public void Test002()
{
Should.Throw<ArgumentNullException>(() => DiffBuilder.Compare(null!)).ParamName.ShouldBe(nameof(DiffBuilder.Control));
Should.Throw<ArgumentNullException>(() => DiffBuilder.Compare("").WithTest(null!)).ParamName.ShouldBe(nameof(DiffBuilder.Test));
Should.Throw<ArgumentNullException>(() => DiffBuilder.Compare(null!)).ParamName.ShouldBe("value");
Should.Throw<ArgumentNullException>(() => DiffBuilder.Compare("").WithTest(null!)).ParamName.ShouldBe("value");
}

[Fact(DisplayName = "Calling Build() with DefaultOptions() returns expected diffs")]
Expand Down
15 changes: 8 additions & 7 deletions src/AngleSharp.Diffing.Tests/DiffingTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ public abstract class DiffingTestBase : IClassFixture<DiffingTestFixture>
{
private readonly DiffingTestFixture _testFixture;


public static readonly TheoryData<CompareResult> 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;
}
Expand Down Expand Up @@ -68,10 +75,4 @@ protected SourceMap ToSourceMap(string html, ComparisonSourceType sourceType = C
var source = ToComparisonSource(html, sourceType);
return new SourceMap(source);
}

public static TheoryData<CompareResult> SameAndSkipCompareResult = new TheoryData<CompareResult>
{
CompareResult.Same,
CompareResult.Skip,
};
}
9 changes: 9 additions & 0 deletions src/AngleSharp.Diffing.Tests/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -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")]
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("<button diff:ignoreAttributes diff:ignoreChildren></button>", @"<button id=""buttonid"" class=""somecss"">Not Ignored</button>")]
[InlineData("<button diff:ignoreAttributes diff:ignoreChildren></button>", @"<button id=""buttonid"" class=""somecss""><span>Not Ignored</span></button>")]
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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("<button diff:ignoreAttributes diff:ignoreChildren></button>", @"<button id=""buttonid"" class=""somecss"">Not Ignored</button>")]
[InlineData("<button diff:ignoreAttributes diff:ignoreChildren></button>", @"<button id=""buttonid"" class=""somecss""><span>Not Ignored</span></button>")]
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class TextNodeTestBase : DiffingTestBase

public static readonly IEnumerable<object[]> WhitespaceCharStrings = AllWhitespaceCharacters.Select(c => new string[] { c.ToString(CultureInfo.InvariantCulture) }).ToArray();

public TextNodeTestBase(DiffingTestFixture fixture) : base(fixture)
protected TextNodeTestBase(DiffingTestFixture fixture) : base(fixture)
{
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/AngleSharp.Diffing.sln
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

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
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AngleSharp.DiffingTests", "AngleSharp.Diffing.Tests\AngleSharp.DiffingTests.csproj", "{18203D98-66B4-4736-B79A-3B7D02EFA9E8}"
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
Expand Down
68 changes: 36 additions & 32 deletions src/AngleSharp.Diffing/AngleSharp.Diffing.csproj
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup>
<Description>Provides a complete diffing model of HTML.</Description>
<Product>AngleSharp.Diffing</Product>
<Authors>AngleSharp</Authors>
<PackageId>AngleSharp.Diffing</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://anglesharp.github.io</PackageProjectUrl>
<PackageIcon>logo.png</PackageIcon>
<PackageIconUrl>https://raw.github.com/AngleSharp/AngleSharp.Diffing/master/logo.png</PackageIconUrl>
<PackageTags>html html5 css css3 dom library diffing anglesharp diff difference compare comparison testing</PackageTags>
<Copyright>Egil Hansen</Copyright>
<RepositoryUrl>https://github.com/AngleSharp/AngleSharp.Diffing</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<PropertyGroup>
<Description>Provides a complete diffing model of HTML.</Description>
<Product>AngleSharp.Diffing</Product>
<Authors>AngleSharp</Authors>
<PackageId>AngleSharp.Diffing</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://anglesharp.github.io</PackageProjectUrl>
<PackageIcon>logo.png</PackageIcon>
<PackageIconUrl>https://raw.github.com/AngleSharp/AngleSharp.Diffing/master/logo.png</PackageIconUrl>
<PackageTags>html html5 css css3 dom library diffing anglesharp diff difference compare comparison testing</PackageTags>
<Copyright>Egil Hansen</Copyright>
<RepositoryUrl>https://github.com/AngleSharp/AngleSharp.Diffing</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<NoWarn>$(NoWarn);NU5104</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160" PrivateAssets="all" />
<PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[5.0.0]" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.169">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160" PrivateAssets="all" />
<PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[5.0.0]" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\logo.png" Pack="true" PackagePath="\" />
<None Include="..\..\LICENSE" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\logo.png" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
5 changes: 4 additions & 1 deletion src/AngleSharp.Diffing/Core/AttributeComparison.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using System.Runtime.InteropServices;

namespace AngleSharp.Diffing.Core;

/// <summary>
/// A match between two attributes that should be compared.
/// </summary>
/// <param name="Control">Gets the control attribute which the <see cref="Test"/> attribute is supposed to match.</param>
/// <param name="Test">Gets the test attribute which should be compared to the <see cref="Control"/> attribute.</param>
[StructLayout(LayoutKind.Auto)]
public readonly record struct AttributeComparison(in AttributeComparisonSource Control, in AttributeComparisonSource Test)
{
/// <summary>
/// Returns the control and test elements which the control and test attributes belongs to.
/// </summary>
public (IElement ControlElement, IElement TestElement) GetAttributeElements()
public readonly (IElement ControlElement, IElement TestElement) AttributeElements
=> ((IElement)Control.ElementSource.Node, (IElement)Test.ElementSource.Node);
}
1 change: 1 addition & 0 deletions src/AngleSharp.Diffing/Core/AttributeComparisonSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace AngleSharp.Diffing.Core;
/// </summary>
/// <param name="attributeName">Name of the attribute.</param>
/// <param name="elementSource">The source of the element the attribute belongs to.</param>
[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))
Expand Down
2 changes: 1 addition & 1 deletion src/AngleSharp.Diffing/Core/CompareDecision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public enum CompareDecision
/// <summary>
/// Use when the compare result is unknown.
/// </summary>
Unknown = 0,
None = 0,
/// <summary>
/// Use when the two compared nodes or attributes are the same.
/// </summary>
Expand Down
Loading

0 comments on commit 5694c9b

Please sign in to comment.