Skip to content

Commit 2880820

Browse files
authored
fix(breaking): Change Core.ComparisonSource.GetPathIndex() to return the Index inside ChildNodes instead of Children
Closes #20
1 parent 498445d commit 2880820

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Released on Tuesday, February 15, 2022.
44

55
- Added a new style comparer which orders the styles before comparing them. By [@grishat](https://github.com/SebastianStehle).
6+
- Change Core.ComparisonSource.GetPathIndex() to return the index inside ChildNodes instead of Children. By [@edxlhornung](https://github.com/edxlhornung).
67

78
# 0.17.0
89

src/AngleSharp.Diffing.Tests/Core/ComparisonSourceTest.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ public void Test002()
6868
}
6969

7070
[Theory(DisplayName = "The index in the source's path is based on its position in it's parents" +
71-
"child node list, i.e. excluding other node types that does not contain children")]
71+
"child node list")]
7272
[InlineData("<p>", 0, "p(0)")]
73-
[InlineData("text<p>", 1, "p(0)")]
74-
[InlineData("<!--x--><p>", 1, "p(0)")]
75-
[InlineData("<i></i>text<p>", 2, "p(1)")]
76-
[InlineData("<i></i><!--x--><p>", 2, "p(1)")]
73+
[InlineData("text<p>", 1, "p(1)")]
74+
[InlineData("<!--x--><p>", 1, "p(1)")]
75+
[InlineData("<i></i>text<p>", 2, "p(2)")]
76+
[InlineData("<i></i><!--x--><p>", 2, "p(2)")]
77+
[InlineData("<i></i>text<!--x--><p>text", 2, "#comment(2)")]
7778
public void Test005(string sourceMarkup, int nodeIndex, string expectedPath)
7879
{
7980
var node = ToNodeList(sourceMarkup)[nodeIndex];
@@ -91,7 +92,7 @@ public void Test006()
9192

9293
var sut = new ComparisonSource(textNode, ComparisonSourceType.Control);
9394

94-
sut.Path.ShouldBe("p(0) > i(1) > #text(0)");
95+
sut.Path.ShouldBe("p(0) > i(2) > #text(0)");
9596
}
9697

9798
[Fact(DisplayName = "Source uses parent path if provided to construct own path")]

src/AngleSharp.Diffing/Core/ComparisonSource.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,14 @@ private static string CalculateParentPath(INode node)
118118

119119
private static int GetPathIndex(INode node)
120120
{
121-
var result = 0;
122121
var parent = node.Parent;
123122
if (parent is not null)
124123
{
125124
var childNodes = parent.ChildNodes;
126125
for (int index = 0; index < childNodes.Length; index++)
127126
{
128127
if (ReferenceEquals(childNodes[index], node))
129-
return result;
130-
if (childNodes[index] is IParentNode)
131-
result += 1;
128+
return index;
132129
}
133130
}
134131
throw new InvalidOperationException("Unexpected node tree state. The node was not found in its parents child nodes collection.");

0 commit comments

Comments
 (0)