|
| 1 | +using System.Linq; |
| 2 | + |
| 3 | +using AngleSharp.Diffing.Core; |
| 4 | + |
| 5 | +using Shouldly; |
| 6 | + |
| 7 | +using Xunit; |
| 8 | + |
| 9 | +namespace AngleSharp.Diffing.Strategies.ElementStrategies |
| 10 | +{ |
| 11 | + public class IgnoreChildrenElementComparerTest : DiffingTestBase |
| 12 | + { |
| 13 | + public IgnoreChildrenElementComparerTest(DiffingTestFixture fixture) : base(fixture) |
| 14 | + { |
| 15 | + } |
| 16 | + |
| 17 | + [Theory(DisplayName = "When a control element does not contain the 'diff:ignoreChildren' attribute or it is 'diff:ignoreChildren=false', the current decision is returned")] |
| 18 | + [InlineData(@"<p></p>")] |
| 19 | + [InlineData(@"<p diff:ignoreChildren=""false""></p>")] |
| 20 | + [InlineData(@"<p diff:ignoreChildren=""FALSE""></p>")] |
| 21 | + [InlineData(@"<p diff:ignoreChildren=""faLsE""></p>")] |
| 22 | + public void Test001(string controlHtml) |
| 23 | + { |
| 24 | + var comparison = ToComparison(controlHtml, "<p><em></em></p>"); |
| 25 | + |
| 26 | + IgnoreChildrenElementComparer.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Different); |
| 27 | + IgnoreChildrenElementComparer.Compare(comparison, CompareResult.Same).ShouldBe(CompareResult.Same); |
| 28 | + IgnoreChildrenElementComparer.Compare(comparison, CompareResult.Skip).ShouldBe(CompareResult.Skip); |
| 29 | + } |
| 30 | + |
| 31 | + [Theory(DisplayName = "When a control element has 'diff:ignoreChildren' attribute, SameAndBreak is returned")] |
| 32 | + [InlineData(@"<p diff:ignoreChildren></p>")] |
| 33 | + [InlineData(@"<p diff:ignoreChildren=""true""></p>")] |
| 34 | + [InlineData(@"<p diff:ignoreChildren=""TRUE""></p>")] |
| 35 | + [InlineData(@"<p diff:ignoreChildren=""TrUe""></p>")] |
| 36 | + public void Test002(string controlHtml) |
| 37 | + { |
| 38 | + var comparison = ToComparison(controlHtml, "<p><em></em></p>"); |
| 39 | + |
| 40 | + IgnoreChildrenElementComparer.Compare(comparison, CompareResult.Same).ShouldBe(CompareResult.Same | CompareResult.SkipChildren); |
| 41 | + IgnoreChildrenElementComparer.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Different | CompareResult.SkipChildren); |
| 42 | + } |
| 43 | + |
| 44 | + [Fact(DisplayName = "When a control element has 'diff:ignoreChildren', calling Build() with DefaultOptions() returns expected diffs")] |
| 45 | + public void Test003() |
| 46 | + { |
| 47 | + var control = @"<p attr=""foo"" missing diff:ignoreChildren>hello <em>world</em></p>"; |
| 48 | + var test = @"<p attr=""bar"" unexpected>world says <strong>hello</strong></p>"; |
| 49 | + |
| 50 | + var diffs = DiffBuilder |
| 51 | + .Compare(control) |
| 52 | + .WithTest(test) |
| 53 | + .Build() |
| 54 | + .ToList(); |
| 55 | + |
| 56 | + diffs.Count.ShouldBe(3); |
| 57 | + diffs.SingleOrDefault(x => x is AttrDiff).ShouldNotBeNull(); |
| 58 | + diffs.SingleOrDefault(x => x is MissingAttrDiff).ShouldNotBeNull(); |
| 59 | + diffs.SingleOrDefault(x => x is UnexpectedAttrDiff).ShouldNotBeNull(); |
| 60 | + } |
| 61 | + |
| 62 | + [Theory(DisplayName = "When a control element has 'diff:ignoreChildren', calling Build() with DefaultOptions() returns empty diffs")] |
| 63 | + [InlineData(@"<p attr=""foo"" diff:ignoreChildren>hello <em>world</em></p>", |
| 64 | + @"<p attr=""foo"">world says <strong>hello</strong></p>")] |
| 65 | + [InlineData(@"<p attr=""foo"" expected diff:ignoreChildren>hello <em>world</em></p>", |
| 66 | + @"<p attr=""foo"" expected>world says <strong>hello</strong></p>")] |
| 67 | + public void Test004(string control, string test) |
| 68 | + { |
| 69 | + var diffs = DiffBuilder |
| 70 | + .Compare(control) |
| 71 | + .WithTest(test) |
| 72 | + .Build() |
| 73 | + .ToList(); |
| 74 | + |
| 75 | + diffs.ShouldBeEmpty(); |
| 76 | + } |
| 77 | + } |
| 78 | +} |
0 commit comments