-
-
Notifications
You must be signed in to change notification settings - Fork 8
Ignore unmatched :ignore
attributes
#49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f3fd82c
8048379
5f19c08
e254b0c
2597558
082c0d6
afee48a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
namespace AngleSharp.Diffing.TestData; | ||
|
||
internal static class IgnoreAttributeTestData | ||
{ | ||
public static TheoryData<string, string> ControlAndHtmlData() | ||
{ | ||
var theoryData = new TheoryData<string, string>(); | ||
foreach (var (controlHtml, expectedHtml, _) in TestCases) | ||
{ | ||
theoryData.Add(controlHtml, expectedHtml); | ||
} | ||
|
||
return theoryData; | ||
} | ||
|
||
public static TheoryData<string, string, DiffResult> ControlHtmlAndDiffData() | ||
{ | ||
var theoryData = new TheoryData<string, string, DiffResult>(); | ||
foreach (var (controlHtml, expectedHtml, expectedDiffResult) in TestCases) | ||
{ | ||
theoryData.Add(controlHtml, expectedHtml, expectedDiffResult); | ||
} | ||
|
||
return theoryData; | ||
} | ||
|
||
private static readonly IEnumerable<(string controlHtml, string expectedHtml, DiffResult expectedDiffResult)> | ||
TestCases = | ||
[ | ||
("<div class:ignore></div>", "<div class=\"ian-fleming\"></div>", DiffResult.Different), | ||
("<div class:ignore></div>", "<div class=\"\"></div>", DiffResult.Different), | ||
("<div class:ignore></div>", "<div class></div>", DiffResult.Different), | ||
("<div class:ignore></div>", "<div></div>", DiffResult.Missing), | ||
("<input required:ignore/>", "<input required=\"required\"/>", DiffResult.Different), | ||
("<input required:ignore/>", "<input required=\"\"/>", DiffResult.Different), | ||
("<input required:ignore/>", "<input required/>", DiffResult.Different), | ||
("<input required:ignore/>", "<input/>", DiffResult.Missing), | ||
("<button onclick:ignore/></button>", "<button onclick=\"alert(1)\"></button>", DiffResult.Different), | ||
("<button onclick:ignore/></button>", "<button/></button>", DiffResult.Missing), | ||
("<a aria-disabled:ignore/></a>", "<a aria-disabled=\"true\"/></a>", DiffResult.Different), | ||
("<a aria-disabled:ignore/></a>", "<a/></a>", DiffResult.Missing), | ||
("<span style:ignore/></span>", "<span style=\"color:red;\"/></span>", DiffResult.Different), | ||
("<span style:ignore/></span>", "<span/></span>", DiffResult.Missing), | ||
]; | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe revert this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe merge the two files into one static file, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to keep |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
namespace AngleSharp.Diffing.Strategies.AttributeStrategies; | ||
|
||
/// <summary> | ||
/// Ignore Attribute matcher strategy. | ||
/// </summary> | ||
public static class IgnoreAttributeStrategy | ||
{ | ||
private const string DIFF_IGNORE_POSTFIX = ":ignore"; | ||
|
||
/// <summary> | ||
/// The ignore attribute comparer. | ||
/// </summary> | ||
public static CompareResult Compare(in AttributeComparison comparison, CompareResult currentDecision) | ||
{ | ||
if (currentDecision.IsSameOrSkip) | ||
return currentDecision; | ||
|
||
return IsIgnoreAttribute(comparison.Control.Attribute) | ||
? CompareResult.Same | ||
: currentDecision; | ||
} | ||
|
||
/// <summary> | ||
/// Attribute name matcher strategy. | ||
/// </summary> | ||
public static IEnumerable<AttributeComparison> Match(IDiffContext context, SourceMap controlSources, SourceMap testSources) | ||
{ | ||
if (controlSources is null) | ||
throw new ArgumentNullException(nameof(controlSources)); | ||
if (testSources is null) | ||
throw new ArgumentNullException(nameof(testSources)); | ||
|
||
foreach (var control in controlSources.GetUnmatched()) | ||
{ | ||
// An unmatched :ignore attribute can just be matched with itself if it isn't | ||
// matched with a "test" attribute of the same name already. | ||
// this means an ignored attribute is ignored even if it does not appear in the test html. | ||
if (control.Attribute.Name.EndsWith(DIFF_IGNORE_POSTFIX, StringComparison.OrdinalIgnoreCase)) | ||
yield return new AttributeComparison(control, control); | ||
} | ||
} | ||
|
||
private static bool IsIgnoreAttribute(IAttr source) | ||
{ | ||
return source.Name.EndsWith(DIFF_IGNORE_POSTFIX, StringComparison.OrdinalIgnoreCase); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.