-
-
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.
Merge pull request #16 from AngleSharp/devel
0.7.0 release
- Loading branch information
Showing
11 changed files
with
284 additions
and
11 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
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
44 changes: 44 additions & 0 deletions
44
...leSharp.Diffing.Tests/Strategies/ElementStrategies/IgnoreAttributesElementComparerTest.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,44 @@ | ||
using System.Linq; | ||
|
||
using AngleSharp.Diffing.Core; | ||
|
||
using Shouldly; | ||
|
||
using Xunit; | ||
|
||
namespace AngleSharp.Diffing.Strategies.ElementStrategies | ||
{ | ||
public class IgnoreAttributesElementComparerTest : DiffingTestBase | ||
{ | ||
public IgnoreAttributesElementComparerTest(DiffingTestFixture fixture) : base(fixture) | ||
{ | ||
} | ||
|
||
[Theory(DisplayName = "When a control element does not contain the 'diff:ignoreAttributes' attribute or it is 'diff:ignoreAttributes=false', the current decision is returned")] | ||
[InlineData(@"<p></p>")] | ||
[InlineData(@"<p diff:ignoreAttributes=""false""></p>")] | ||
[InlineData(@"<p diff:ignoreAttributes=""FALSE""></p>")] | ||
[InlineData(@"<p diff:ignoreAttributes=""faLsE""></p>")] | ||
public void Test001(string controlHtml) | ||
{ | ||
var comparison = ToComparison(controlHtml, "<p></p>"); | ||
|
||
IgnoreAttributesElementComparer.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Different); | ||
IgnoreAttributesElementComparer.Compare(comparison, CompareResult.Same).ShouldBe(CompareResult.Same); | ||
IgnoreAttributesElementComparer.Compare(comparison, CompareResult.Skip).ShouldBe(CompareResult.Skip); | ||
} | ||
|
||
[Theory(DisplayName = "When a control element has 'diff:ignoreAttributes' attribute, CompareResult.SkipAttributes flag is returned")] | ||
[InlineData(@"<p diff:ignoreAttributes></p>")] | ||
[InlineData(@"<p diff:ignoreAttributes=""true""></p>")] | ||
[InlineData(@"<p diff:ignoreAttributes=""TRUE""></p>")] | ||
[InlineData(@"<p diff:ignoreAttributes=""TrUe""></p>")] | ||
public void Test002(string controlHtml) | ||
{ | ||
var comparison = ToComparison(controlHtml, "<p></p>"); | ||
|
||
IgnoreAttributesElementComparer.Compare(comparison, CompareResult.Same).ShouldBe(CompareResult.Same | CompareResult.SkipAttributes); | ||
IgnoreAttributesElementComparer.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Different | CompareResult.SkipAttributes); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ngleSharp.Diffing.Tests/Strategies/ElementStrategies/IgnoreChildrenElementComparerTest.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,44 @@ | ||
using System.Linq; | ||
|
||
using AngleSharp.Diffing.Core; | ||
|
||
using Shouldly; | ||
|
||
using Xunit; | ||
|
||
namespace AngleSharp.Diffing.Strategies.ElementStrategies | ||
{ | ||
public class IgnoreChildrenElementComparerTest : DiffingTestBase | ||
{ | ||
public IgnoreChildrenElementComparerTest(DiffingTestFixture fixture) : base(fixture) | ||
{ | ||
} | ||
|
||
[Theory(DisplayName = "When a control element does not contain the 'diff:ignoreChildren' attribute or it is 'diff:ignoreChildren=false', the current decision is returned")] | ||
[InlineData(@"<p></p>")] | ||
[InlineData(@"<p diff:ignoreChildren=""false""></p>")] | ||
[InlineData(@"<p diff:ignoreChildren=""FALSE""></p>")] | ||
[InlineData(@"<p diff:ignoreChildren=""faLsE""></p>")] | ||
public void Test001(string controlHtml) | ||
{ | ||
var comparison = ToComparison(controlHtml, "<p></p>"); | ||
|
||
IgnoreChildrenElementComparer.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Different); | ||
IgnoreChildrenElementComparer.Compare(comparison, CompareResult.Same).ShouldBe(CompareResult.Same); | ||
IgnoreChildrenElementComparer.Compare(comparison, CompareResult.Skip).ShouldBe(CompareResult.Skip); | ||
} | ||
|
||
[Theory(DisplayName = "When a control element has 'diff:ignoreChildren' attribute, CompareResult.SkipChildren flag is returned")] | ||
[InlineData(@"<p diff:ignoreChildren></p>")] | ||
[InlineData(@"<p diff:ignoreChildren=""true""></p>")] | ||
[InlineData(@"<p diff:ignoreChildren=""TRUE""></p>")] | ||
[InlineData(@"<p diff:ignoreChildren=""TrUe""></p>")] | ||
public void Test002(string controlHtml) | ||
{ | ||
var comparison = ToComparison(controlHtml, "<p></p>"); | ||
|
||
IgnoreChildrenElementComparer.Compare(comparison, CompareResult.Same).ShouldBe(CompareResult.Same | CompareResult.SkipChildren); | ||
IgnoreChildrenElementComparer.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Different | CompareResult.SkipChildren); | ||
} | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
src/AngleSharp.Diffing/Strategies/ElementStrategies/IgnoreAttributesElementComparer.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,34 @@ | ||
using AngleSharp.Diffing.Core; | ||
using AngleSharp.Diffing.Extensions; | ||
using AngleSharp.Dom; | ||
|
||
namespace AngleSharp.Diffing.Strategies.ElementStrategies | ||
{ | ||
/// <summary> | ||
/// Represents the ignore attributes element comparer. | ||
/// </summary> | ||
public static class IgnoreAttributesElementComparer | ||
{ | ||
private const string DIFF_IGNORE_ATTRIBUTES_ATTRIBUTE = "diff:ignoreattributes"; | ||
|
||
/// <summary> | ||
/// The ignore attributes element comparer. | ||
/// </summary> | ||
public static CompareResult Compare(in Comparison comparison, CompareResult currentDecision) | ||
{ | ||
if (currentDecision == CompareResult.Skip) | ||
return currentDecision; | ||
|
||
return ControlHasTruthyIgnoreAttributesAttribute(comparison) | ||
? currentDecision | CompareResult.SkipAttributes | ||
: currentDecision; | ||
} | ||
|
||
private static bool ControlHasTruthyIgnoreAttributesAttribute(in Comparison comparison) | ||
{ | ||
return comparison.Control.Node is IElement element && | ||
element.TryGetAttrValue(DIFF_IGNORE_ATTRIBUTES_ATTRIBUTE, out bool shouldIgnore) && | ||
shouldIgnore; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/AngleSharp.Diffing/Strategies/ElementStrategies/IgnoreChildrenElementComparer.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,34 @@ | ||
using AngleSharp.Diffing.Core; | ||
using AngleSharp.Diffing.Extensions; | ||
using AngleSharp.Dom; | ||
|
||
namespace AngleSharp.Diffing.Strategies.ElementStrategies | ||
{ | ||
/// <summary> | ||
/// Represents the ignore children element comparer. | ||
/// </summary> | ||
public static class IgnoreChildrenElementComparer | ||
{ | ||
private const string DIFF_IGNORE_CHILDREN_ATTRIBUTE = "diff:ignorechildren"; | ||
|
||
/// <summary> | ||
/// The ignore children element comparer. | ||
/// </summary> | ||
public static CompareResult Compare(in Comparison comparison, CompareResult currentDecision) | ||
{ | ||
if (currentDecision == CompareResult.Skip) | ||
return currentDecision; | ||
|
||
return ControlHasTruthyIgnoreChildrenAttribute(comparison) | ||
? currentDecision | CompareResult.SkipChildren | ||
: currentDecision; | ||
} | ||
|
||
private static bool ControlHasTruthyIgnoreChildrenAttribute(in Comparison comparison) | ||
{ | ||
return comparison.Control.Node is IElement element && | ||
element.TryGetAttrValue(DIFF_IGNORE_CHILDREN_ATTRIBUTE, out bool shouldIgnore) && | ||
shouldIgnore; | ||
} | ||
} | ||
} |