@@ -6,6 +6,18 @@ namespace Egil.AngleSharp.Diffing.Strategies.TextNodeStrategies
66{
77 public class TextNodeComparerTest : TextnodeStrategyTestBase
88 {
9+ [ Fact ( DisplayName = "When input node is not a IText node, comparer does not run nor change the current decision" ) ]
10+ public void Test2 ( )
11+ {
12+ var comparison = new Comparison ( ToComparisonSource ( "<p></p>" , ComparisonSourceType . Control ) , ToComparisonSource ( "<p></p>" , ComparisonSourceType . Test ) ) ;
13+ var sut = new TextNodeComparer ( ) ;
14+
15+ sut . Compare ( comparison , CompareResult . Different ) . ShouldBe ( CompareResult . Different ) ;
16+ sut . Compare ( comparison , CompareResult . DifferentAndBreak ) . ShouldBe ( CompareResult . DifferentAndBreak ) ;
17+ sut . Compare ( comparison , CompareResult . Same ) . ShouldBe ( CompareResult . Same ) ;
18+ sut . Compare ( comparison , CompareResult . SameAndBreak ) . ShouldBe ( CompareResult . SameAndBreak ) ;
19+ }
20+
921 [ Theory ( DisplayName = "When option is Preserve or RemoveWhitespaceNodes, comparer does not run nor change the current decision" ) ]
1022 [ InlineData ( WhitespaceOption . Preserve ) ]
1123 [ InlineData ( WhitespaceOption . RemoveWhitespaceNodes ) ]
@@ -97,7 +109,7 @@ public void Test004()
97109 var sut = new TextNodeComparer ( ignoreCase : true ) ;
98110 var comparison = new Comparison ( ToComparisonSource ( "HELLO WoRlD" , ComparisonSourceType . Control ) ,
99111 ToComparisonSource ( "hello world" , ComparisonSourceType . Test ) ) ;
100-
112+
101113 sut . Compare ( comparison , CompareResult . Different ) . ShouldBe ( CompareResult . Same ) ;
102114 }
103115
@@ -125,21 +137,74 @@ public void Test006()
125137 sut . Compare ( comparison , CompareResult . Different ) . ShouldBe ( CompareResult . Same ) ;
126138 }
127139
128- [ Fact ( DisplayName = "When IgnoreCase='true' inline attribute is present in a parent element, a string ordinal ignore case comparison is performed" ) ]
129- public void Test007 ( )
140+ [ Theory ( DisplayName = "When IgnoreCase='true' inline attribute is present in a parent element, a string ordinal ignore case comparison is performed" ) ]
141+ [ InlineData ( @"<header><h1><em diff:ignoreCase=""true"">HELLO WoRlD</em></h1></header>" ) ]
142+ [ InlineData ( @"<header><h1 diff:ignoreCase=""True""><em>HELLO WoRlD</em></h1></header>" ) ]
143+ [ InlineData ( @"<header diff:ignoreCase=""TRUE""><h1><em>HELLO WoRlD</em></h1></header>" ) ]
144+ public void Test008 ( string controlHtml )
130145 {
131- var sut = new TextNodeComparer ( ignoreCase : false ) ;
132- var pre = ToComparisonSource ( "<h1 diff:ignoreCase=\" True\" >HELLO WoRlD</pre>" ) ;
133- var controlSource = new ComparisonSource ( pre . Node . FirstChild , 0 , pre . Path , ComparisonSourceType . Control ) ;
146+ var sut = new TextNodeComparer ( ignoreCase : false ) ;
147+ var rootSource = ToComparisonSource ( controlHtml ) ;
148+ var controlSource = new ComparisonSource ( rootSource . Node . FirstChild . FirstChild . FirstChild , 0 , rootSource . Path , ComparisonSourceType . Control ) ;
149+ var testSource = ToComparisonSource ( "hello world" , ComparisonSourceType . Test ) ;
150+ var comparison = new Comparison ( controlSource , testSource ) ;
151+
152+ sut . Compare ( comparison , CompareResult . Different ) . ShouldBe ( CompareResult . Same ) ;
153+ }
154+
155+ [ Theory ( DisplayName = "When IgnoreCase='false' inline attribute is present in a parent element, a string ordinal case comparison is performed" ) ]
156+ [ InlineData ( @"<header><h1><em diff:ignoreCase=""false"">HELLO WoRlD</em></h1></header>" ) ]
157+ [ InlineData ( @"<header><h1 diff:ignoreCase=""False""><em>HELLO WoRlD</em></h1></header>" ) ]
158+ [ InlineData ( @"<header diff:ignoreCase=""FALSE""><h1><em>HELLO WoRlD</em></h1></header>" ) ]
159+ public void Test009 ( string controlHtml )
160+ {
161+ var sut = new TextNodeComparer ( ignoreCase : true ) ;
162+ var rootSource = ToComparisonSource ( controlHtml ) ;
163+ var controlSource = new ComparisonSource ( rootSource . Node . FirstChild . FirstChild . FirstChild , 0 , rootSource . Path , ComparisonSourceType . Control ) ;
134164 var testSource = ToComparisonSource ( "hello world" , ComparisonSourceType . Test ) ;
135165 var comparison = new Comparison ( controlSource , testSource ) ;
136166
167+ sut . Compare ( comparison , CompareResult . Different ) . ShouldBe ( CompareResult . Different ) ;
168+ }
169+
170+ [ Theory ( DisplayName = "When diff:regex attribute is found on the immediate parent element, the control text is expected to a regex and that used when comparing to the test text node." ) ]
171+ [ InlineData ( @"<p diff:regex>\d{4}</p>" ) ]
172+ [ InlineData ( @"<p diff:regex=""true"">\d{4}</p>" ) ]
173+ public void Test010 ( string controlHtml )
174+ {
175+ var sut = new TextNodeComparer ( ) ;
176+ var paragraphSource = ToComparisonSource ( controlHtml ) ;
177+ var controlSource = new ComparisonSource ( paragraphSource . Node . FirstChild , 0 , paragraphSource . Path , ComparisonSourceType . Control ) ;
178+ var testSource = ToComparisonSource ( "1234" , ComparisonSourceType . Test ) ;
179+ var comparison = new Comparison ( controlSource , testSource ) ;
137180
138181 sut . Compare ( comparison , CompareResult . Different ) . ShouldBe ( CompareResult . Same ) ;
139182 }
140183
184+ [ Fact ( DisplayName = "When diff:regex attribute is found on the immediate parent element and ignoreCase is true, the regex compare is done as case insensitive." ) ]
185+ public void Test011 ( )
186+ {
187+ var sut = new TextNodeComparer ( ignoreCase : true ) ;
188+ var paragraphSource = ToComparisonSource ( @"<p diff:regex>FOO\d{4}</p>" ) ;
189+ var controlSource = new ComparisonSource ( paragraphSource . Node . FirstChild , 0 , paragraphSource . Path , ComparisonSourceType . Control ) ;
190+ var testSource = ToComparisonSource ( "foo1234" , ComparisonSourceType . Test ) ;
191+ var comparison = new Comparison ( controlSource , testSource ) ;
141192
142- // When diff:regex attribute is found on the containing element, the control text is expected to a regex and that used when comparing to the test text node.
193+ sut . Compare ( comparison , CompareResult . Different ) . ShouldBe ( CompareResult . Same ) ;
194+ }
195+
196+ [ Theory ( DisplayName = "When diff:regex='false' attribute is found on the immediate parent element, a string ordinal case comparison is performed." ) ]
197+ [ InlineData ( @"<p diff:regex=""false"">1234</p>" ) ]
198+ public void Test012 ( string controlHtml )
199+ {
200+ var sut = new TextNodeComparer ( ) ;
201+ var paragraphSource = ToComparisonSource ( controlHtml ) ;
202+ var controlSource = new ComparisonSource ( paragraphSource . Node . FirstChild , 0 , paragraphSource . Path , ComparisonSourceType . Control ) ;
203+ var testSource = ToComparisonSource ( "1234" , ComparisonSourceType . Test ) ;
204+ var comparison = new Comparison ( controlSource , testSource ) ;
205+
206+ sut . Compare ( comparison , CompareResult . Different ) . ShouldBe ( CompareResult . Same ) ;
207+ }
143208 }
144209}
145210
0 commit comments