Skip to content

Commit f856f81

Browse files
committed
Enable better cross-tree tracking of unmatched nodes and attributes
1 parent 0854b6f commit f856f81

28 files changed

+296
-173
lines changed

src/Core/AttributeComparisonSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
2-
using AngleSharp.Dom;
32
using System.Diagnostics.CodeAnalysis;
3+
using AngleSharp.Dom;
44

55
namespace Egil.AngleSharp.Diffing.Core
66
{

src/Core/Comparison.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using AngleSharp.Dom;
32

43
namespace Egil.AngleSharp.Diffing.Core
54
{

src/Core/ComparisonSource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
2-
using AngleSharp.Dom;
3-
using System.Diagnostics.CodeAnalysis;
42
using System.Diagnostics;
3+
using System.Diagnostics.CodeAnalysis;
4+
using AngleSharp.Dom;
55

66
namespace Egil.AngleSharp.Diffing.Core
77
{

src/Core/DiffContext.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ public class DiffContext
1313

1414
internal HashSet<ComparisonSource> UnexpectedSources { get; }
1515

16+
internal HashSet<AttributeComparisonSource> MissingAttributeSources { get; }
17+
18+
internal HashSet<AttributeComparisonSource> UnexpectedAttributeSources { get; }
19+
1620
public DiffContext(IElement? controlRoot, IElement? testRoot)
1721
{
1822
_controlRoot = controlRoot;
1923
_testRoot = testRoot;
2024
MissingSources = new HashSet<ComparisonSource>();
2125
UnexpectedSources = new HashSet<ComparisonSource>();
26+
MissingAttributeSources = new HashSet<AttributeComparisonSource>();
27+
UnexpectedAttributeSources = new HashSet<AttributeComparisonSource>();
2228
}
2329

2430
public IHtmlCollection<IElement> QueryControlRoot(string selector)
@@ -32,5 +38,13 @@ public IHtmlCollection<IElement> QueryTestRoot(string selector)
3238
if (_testRoot is null) return EmptyHtmlCollection<IElement>.Empty;
3339
return _testRoot.QuerySelectorAll(selector);
3440
}
41+
42+
internal IEnumerable<IDiff> GetDiffsFromUnmatched()
43+
{
44+
foreach (var source in MissingSources) yield return new MissingNodeDiff(source);
45+
foreach (var source in UnexpectedSources) yield return new UnexpectedNodeDiff(source);
46+
foreach (var source in MissingAttributeSources) yield return new MissingAttrDiff(source);
47+
foreach (var source in UnexpectedAttributeSources) yield return new UnexpectedAttrDiff(source);
48+
}
3549
}
3650
}

src/Core/Diffs/AttrDiff.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Diagnostics;
3-
4-
namespace Egil.AngleSharp.Diffing.Core
1+
namespace Egil.AngleSharp.Diffing.Core
52
{
63
public class AttrDiff : DiffBase<AttributeComparisonSource>
74
{

src/Core/Diffs/Diff.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace Egil.AngleSharp.Diffing.Core
22
{
33
public class Diff : DiffBase<ComparisonSource>
4-
{
4+
{
55
public Diff(in Comparison comparison) : base(comparison.Control, comparison.Test, comparison.Control.Node.NodeType.ToDiffTarget())
66
{
77
}

src/Core/Diffs/MissingAttrDiff.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Egil.AngleSharp.Diffing.Core
44
{
55
[DebuggerDisplay("Diff={Target} {Result}]")]
66
public class MissingAttrDiff : MissingDiffBase<AttributeComparisonSource>
7-
{
7+
{
88
internal MissingAttrDiff(in AttributeComparisonSource control) : base(control, DiffTarget.Attribute)
99
{
1010
}

src/Core/Diffs/MissingNodeDiff.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Diagnostics;
3-
using AngleSharp.Dom;
1+
using System.Diagnostics;
42

53
namespace Egil.AngleSharp.Diffing.Core
64
{

src/Core/Diffs/UnexpectedAttrDiff.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Diagnostics;
1+
using System.Diagnostics;
32

43
namespace Egil.AngleSharp.Diffing.Core
54
{

src/Core/Diffs/UnexpectedNodeDiff.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Diagnostics;
3-
using AngleSharp.Dom;
1+
using System.Diagnostics;
42

53
namespace Egil.AngleSharp.Diffing.Core
64
{

0 commit comments

Comments
 (0)