|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Egil.AngleSharp.Diffing.Core; |
| 7 | +using Shouldly; |
| 8 | +using Xunit; |
| 9 | + |
| 10 | +namespace Egil.AngleSharp.Diffing.Strategies.TextNodeStrategies |
| 11 | +{ |
| 12 | + public class StyleSheetTextNodeComparerTest : TextNodeTestBase |
| 13 | + { |
| 14 | + [Fact(DisplayName = "When input node is not a IText node, comparer does not run nor change the current decision")] |
| 15 | + public void Test000() |
| 16 | + { |
| 17 | + var comparison = ToComparison("<p></p>", "<p></p>"); |
| 18 | + |
| 19 | + StyleSheetTextNodeComparer.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Different); |
| 20 | + StyleSheetTextNodeComparer.Compare(comparison, CompareResult.DifferentAndBreak).ShouldBe(CompareResult.DifferentAndBreak); |
| 21 | + StyleSheetTextNodeComparer.Compare(comparison, CompareResult.Same).ShouldBe(CompareResult.Same); |
| 22 | + StyleSheetTextNodeComparer.Compare(comparison, CompareResult.SameAndBreak).ShouldBe(CompareResult.SameAndBreak); |
| 23 | + } |
| 24 | + |
| 25 | + [Fact(DisplayName = "When input node is a IText node inside an element that is NOT a style tag, comparer does not run nor change the current decision")] |
| 26 | + public void Test0001() |
| 27 | + { |
| 28 | + var comparison = ToComparison("<p>h1{background:#000;}</p>", "<p>h1{background:#000;}</p>"); |
| 29 | + |
| 30 | + StyleSheetTextNodeComparer.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Different); |
| 31 | + StyleSheetTextNodeComparer.Compare(comparison, CompareResult.DifferentAndBreak).ShouldBe(CompareResult.DifferentAndBreak); |
| 32 | + StyleSheetTextNodeComparer.Compare(comparison, CompareResult.Same).ShouldBe(CompareResult.Same); |
| 33 | + StyleSheetTextNodeComparer.Compare(comparison, CompareResult.SameAndBreak).ShouldBe(CompareResult.SameAndBreak); |
| 34 | + } |
| 35 | + |
| 36 | + |
| 37 | + [Fact(DisplayName = "The comparer responses with Different when style information is different")] |
| 38 | + public void Test001() |
| 39 | + { |
| 40 | + var comparison = ToStyleComparison(@"h1{background:#000;}", @"h1{color:#000;}"); |
| 41 | + |
| 42 | + StyleSheetTextNodeComparer.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Different); |
| 43 | + } |
| 44 | + |
| 45 | + [Theory(DisplayName = "The comparer ignores insignificant whitespace")] |
| 46 | + [InlineData(" ")] |
| 47 | + [InlineData(" ")] |
| 48 | + [InlineData("\t")] |
| 49 | + [InlineData("\n")] |
| 50 | + [InlineData("\n\r")] |
| 51 | + public void Test003(string whitespace) |
| 52 | + { |
| 53 | + var comparison = ToStyleComparison($@"h1{whitespace}{{{whitespace}color:{whitespace}#000;{whitespace}}}", @"h1{color:#000;}"); |
| 54 | + |
| 55 | + StyleSheetTextNodeComparer.Compare(comparison, CompareResult.Different).ShouldBe(CompareResult.Same); |
| 56 | + } |
| 57 | + |
| 58 | + private Comparison ToStyleComparison(string controlStyleText, string testStyleText) |
| 59 | + { |
| 60 | + var controlStyle = ToComparisonSource($@"<style type=""text/css"">{controlStyleText}</style>"); |
| 61 | + var controlSource = new ComparisonSource(controlStyle.Node.FirstChild, 0, controlStyle.Path, ComparisonSourceType.Control); |
| 62 | + var testStyle = ToComparisonSource($@"<style type=""text/css"">{testStyleText}</style>"); |
| 63 | + var testSource = new ComparisonSource(testStyle.Node.FirstChild, 0, testStyle.Path, ComparisonSourceType.Test); |
| 64 | + return new Comparison(controlSource, testSource); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments