Skip to content

Commit 082c0d6

Browse files
committed
Create IgnoreAttributeStrategy and make IgnoreAttributeComparer obsolete
1 parent 2597558 commit 082c0d6

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

src/AngleSharp.Diffing.Tests/Strategies/AttributeStrategies/IgnoreAttributeComparerTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void Test000(CompareResult currentResult)
1717
@"<p foo=""bar""></p>", "foo"
1818
);
1919

20-
IgnoreAttributeComparer
20+
IgnoreAttributeStrategy
2121
.Compare(comparison, currentResult)
2222
.ShouldBe(currentResult);
2323
}
@@ -30,8 +30,8 @@ public void Test003()
3030
@"<p foo=""bar""></p>", "foo"
3131
);
3232

33-
IgnoreAttributeComparer.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Different);
34-
IgnoreAttributeComparer.Compare(comparison, CompareResult.Same).ShouldBe(CompareResult.Same);
33+
IgnoreAttributeStrategy.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Different);
34+
IgnoreAttributeStrategy.Compare(comparison, CompareResult.Same).ShouldBe(CompareResult.Same);
3535
}
3636

3737
[Fact(DisplayName = "When a attribute does contain have the ':ignore' postfix, Same is returned")]
@@ -42,6 +42,6 @@ public void Test004()
4242
@"<p foo=""baz""></p>", "foo"
4343
);
4444

45-
IgnoreAttributeComparer.Compare(comparison, CompareResult.Unknown).ShouldBe(CompareResult.Same);
45+
IgnoreAttributeStrategy.Compare(comparison, CompareResult.Unknown).ShouldBe(CompareResult.Same);
4646
}
4747
}

src/AngleSharp.Diffing/Strategies/AttributeStrategies/DiffingStrategyPipelineBuilderExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static IDiffingStrategyCollection IgnoreDiffAttributes(this IDiffingStrat
2323
public static IDiffingStrategyCollection AddAttributeNameMatcher(this IDiffingStrategyCollection builder)
2424
{
2525
builder.AddMatcher(AttributeNameMatcher.Match, StrategyType.Generalized);
26-
builder.AddMatcher(IgnoreAttributeMatcher.Match, StrategyType.Generalized);
26+
builder.AddMatcher(IgnoreAttributeStrategy.Match, StrategyType.Generalized);
2727
return builder;
2828
}
2929

@@ -34,7 +34,7 @@ public static IDiffingStrategyCollection AddAttributeComparer(this IDiffingStrat
3434
{
3535
builder.AddMatcher(PostfixedAttributeMatcher.Match, StrategyType.Specialized);
3636
builder.AddComparer(AttributeComparer.Compare, StrategyType.Generalized);
37-
builder.AddComparer(IgnoreAttributeComparer.Compare, StrategyType.Specialized);
37+
builder.AddComparer(IgnoreAttributeStrategy.Compare, StrategyType.Specialized);
3838
return builder;
3939
}
4040

src/AngleSharp.Diffing/Strategies/AttributeStrategies/IgnoreAttributeComparer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/// <summary>
44
/// Represents the ignore attribute comparer.
55
/// </summary>
6+
[Obsolete("Has been moved to IgnoreAttributeStrategy")]
67
public static class IgnoreAttributeComparer
78
{
89
private const string DIFF_IGNORE_POSTFIX = ":ignore";
@@ -20,8 +21,8 @@ public static CompareResult Compare(in AttributeComparison comparison, CompareRe
2021
: currentDecision;
2122
}
2223

23-
public static bool IsIgnoreAttribute(IAttr source)
24+
private static bool IsIgnoreAttribute(IAttr source)
2425
{
25-
return source.Name.EndsWith(DIFF_IGNORE_POSTFIX, StringComparison.OrdinalIgnoreCase);
26+
return source.Name.EndsWith(DIFF_IGNORE_POSTFIX, StringComparison.OrdinalIgnoreCase);
2627
}
27-
}
28+
}

src/AngleSharp.Diffing/Strategies/AttributeStrategies/IgnoreAttributeMatcher.cs renamed to src/AngleSharp.Diffing/Strategies/AttributeStrategies/IgnoreAttributeStrategy.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@
33
/// <summary>
44
/// Ignore Attribute matcher strategy.
55
/// </summary>
6-
public static class IgnoreAttributeMatcher
6+
public static class IgnoreAttributeStrategy
77
{
88
private const string DIFF_IGNORE_POSTFIX = ":ignore";
99

10+
/// <summary>
11+
/// The ignore attribute comparer.
12+
/// </summary>
13+
public static CompareResult Compare(in AttributeComparison comparison, CompareResult currentDecision)
14+
{
15+
if (currentDecision.IsSameOrSkip)
16+
return currentDecision;
17+
18+
return IsIgnoreAttribute(comparison.Control.Attribute)
19+
? CompareResult.Same
20+
: currentDecision;
21+
}
22+
1023
/// <summary>
1124
/// Attribute name matcher strategy.
1225
/// </summary>
@@ -26,4 +39,9 @@ public static IEnumerable<AttributeComparison> Match(IDiffContext context, Sourc
2639
yield return new AttributeComparison(control, control);
2740
}
2841
}
42+
43+
private static bool IsIgnoreAttribute(IAttr source)
44+
{
45+
return source.Name.EndsWith(DIFF_IGNORE_POSTFIX, StringComparison.OrdinalIgnoreCase);
46+
}
2947
}

0 commit comments

Comments
 (0)