-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v.0.18.0 release
- Loading branch information
Showing
8 changed files
with
115 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/AngleSharp.Diffing.Tests/Strategies/ElementStrategies/ElementClosingComparerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Linq; | ||
|
||
using AngleSharp.Diffing.Core; | ||
|
||
using Shouldly; | ||
|
||
using Xunit; | ||
|
||
namespace AngleSharp.Diffing.Strategies.ElementStrategies | ||
{ | ||
public class ElementClosingComparerTest : DiffingTestBase | ||
{ | ||
public ElementClosingComparerTest(DiffingTestFixture fixture) : base(fixture) | ||
{ | ||
} | ||
|
||
[Fact(DisplayName = "When control and test nodes have are both self closed, the result is Same")] | ||
public void Test001() | ||
{ | ||
var comparison = ToComparison("<v:image />", "<v:image />"); | ||
|
||
ElementClosingComparer.Compare(comparison, CompareResult.Unknown).ShouldBe(CompareResult.Same); | ||
} | ||
|
||
[Fact(DisplayName = "When control and test nodes have are both not self closed, the result is Same")] | ||
public void Test002() | ||
{ | ||
var comparison = ToComparison("<v:image />", "<v:image />"); | ||
|
||
ElementClosingComparer.Compare(comparison, CompareResult.Unknown).ShouldBe(CompareResult.Same); | ||
} | ||
|
||
[Fact(DisplayName = "When either control or test node is self closed, the result is Same")] | ||
public void Test003() | ||
{ | ||
var comparison = ToComparison("<v:image />", "<v:image>"); | ||
|
||
ElementClosingComparer.Compare(comparison, CompareResult.Unknown).ShouldBe(CompareResult.Different); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/AngleSharp.Diffing/Strategies/ElementStrategies/ElementClosingComparer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using AngleSharp.Diffing.Core; | ||
using AngleSharp.Dom; | ||
using AngleSharp.Html.Parser.Tokens; | ||
|
||
namespace AngleSharp.Diffing.Strategies.ElementStrategies | ||
{ | ||
/// <summary> | ||
/// Represents the element closing comparer strategy. | ||
/// </summary> | ||
public static class ElementClosingComparer | ||
{ | ||
/// <summary> | ||
/// The element comparer closing strategy. | ||
/// </summary> | ||
public static CompareResult Compare(in Comparison comparison, CompareResult currentDecision) | ||
{ | ||
if (currentDecision == CompareResult.Skip) | ||
return currentDecision; | ||
|
||
if (comparison.Test.Node is not IElement testElement || testElement.SourceReference is not HtmlTagToken testTag) | ||
return currentDecision; | ||
|
||
if (comparison.Control.Node is not IElement controlElement || controlElement.SourceReference is not HtmlTagToken controlTag) | ||
return currentDecision; | ||
|
||
return testTag.IsSelfClosing == controlTag.IsSelfClosing ? CompareResult.Same : CompareResult.Different; | ||
} | ||
} | ||
} |