@@ -65,11 +65,80 @@ public void Test9(string whitespace)
6565 sut . Compare ( c4 , CompareResult . Different ) . ShouldBe ( CompareResult . Same ) ;
6666 }
6767
68- // When a parent node has overridden the global whitespace option, that overridden option is used
69- // When whitespace option is Preserve or RemoveWhitespaceNodes, a string ordinal comparison is performed
70- // When whitespace option is Preserve or RemoveWhitespaceNodes and IgnoreCase is true, a string ordinal ignore case comparison is performed
71- // When IgnoreCase is true, a case insensitve comparison is performed
72- // When the parent element is <pre>, the is implicitly set to Preserve, unless explicitly overridden on the element
68+ [ Theory ( DisplayName = "When a parent node has a inline whitespace option, that overrides the global whitespace option" ) ]
69+ [ InlineData ( @"<header><h1><em diff:whitespace=""normalize""> foo bar </em></h1></header>" , @"<header><h1><em>foo bar</em></h1></header>" ) ]
70+ [ InlineData ( @"<header><h1 diff:whitespace=""normalize""><em> foo bar </em></h1></header>" , @"<header><h1><em>foo bar</em></h1></header>" ) ]
71+ [ InlineData ( @"<header diff:whitespace=""normalize""><h1><em> foo bar </em></h1></header>" , @"<header><h1><em>foo bar</em></h1></header>" ) ]
72+ public void Test001 ( string controlHtml , string testHtml )
73+ {
74+ var sut = new TextNodeComparer ( WhitespaceOption . Preserve ) ;
75+ var controlSource = new ComparisonSource ( ToNode ( controlHtml ) . FirstChild . FirstChild . FirstChild , 0 , "dummypath" , ComparisonSourceType . Control ) ;
76+ var testSource = new ComparisonSource ( ToNode ( testHtml ) . FirstChild . FirstChild . FirstChild , 0 , "dummypath" , ComparisonSourceType . Test ) ;
77+ var comparison = new Comparison ( controlSource , testSource ) ;
78+
79+ sut . Compare ( comparison , CompareResult . Different ) . ShouldBe ( CompareResult . Same ) ;
80+ }
81+
82+ [ Theory ( DisplayName = "When whitespace option is Preserve or RemoveWhitespaceNodes, a string ordinal comparison is performed" ) ]
83+ [ InlineData ( WhitespaceOption . Preserve ) ]
84+ [ InlineData ( WhitespaceOption . RemoveWhitespaceNodes ) ]
85+ public void Test003 ( WhitespaceOption whitespaceOption )
86+ {
87+ var sut = new TextNodeComparer ( whitespaceOption ) ;
88+ var comparison = new Comparison ( ToComparisonSource ( " hello\n \n world " , ComparisonSourceType . Control ) ,
89+ ToComparisonSource ( " hello\n \n world " , ComparisonSourceType . Test ) ) ;
90+
91+ sut . Compare ( comparison , CompareResult . Different ) . ShouldBe ( CompareResult . Same ) ;
92+ }
93+
94+ [ Fact ( DisplayName = "When IgnoreCase is true, a string ordinal ignore case comparison is performed" ) ]
95+ public void Test004 ( )
96+ {
97+ var sut = new TextNodeComparer ( ignoreCase : true ) ;
98+ var comparison = new Comparison ( ToComparisonSource ( "HELLO WoRlD" , ComparisonSourceType . Control ) ,
99+ ToComparisonSource ( "hello world" , ComparisonSourceType . Test ) ) ;
100+
101+ sut . Compare ( comparison , CompareResult . Different ) . ShouldBe ( CompareResult . Same ) ;
102+ }
103+
104+ [ Fact ( DisplayName = "When the parent element is <pre>, the is implicitly set to Preserve" ) ]
105+ public void Test005 ( )
106+ {
107+ var sut = new TextNodeComparer ( WhitespaceOption . Normalize ) ;
108+ var pre = ToComparisonSource ( "<pre>foo bar</pre>" ) ;
109+ var controlSource = new ComparisonSource ( pre . Node . FirstChild , 0 , pre . Path , ComparisonSourceType . Control ) ;
110+ var testSource = ToComparisonSource ( "foo bar" , ComparisonSourceType . Test ) ;
111+ var comparison = new Comparison ( controlSource , testSource ) ;
112+
113+ sut . Compare ( comparison , CompareResult . Different ) . ShouldBe ( CompareResult . Different ) ;
114+ }
115+
116+ [ Fact ( DisplayName = "When the parent element is <pre> and the whitespace option is set inline, the inline option is used instead of Preserve" ) ]
117+ public void Test006 ( )
118+ {
119+ var sut = new TextNodeComparer ( WhitespaceOption . Normalize ) ;
120+ var pre = ToComparisonSource ( "<pre diff:whitespace=\" normalize\" >foo bar</pre>" ) ;
121+ var controlSource = new ComparisonSource ( pre . Node . FirstChild , 0 , pre . Path , ComparisonSourceType . Control ) ;
122+ var testSource = ToComparisonSource ( "foo bar" , ComparisonSourceType . Test ) ;
123+ var comparison = new Comparison ( controlSource , testSource ) ;
124+
125+ sut . Compare ( comparison , CompareResult . Different ) . ShouldBe ( CompareResult . Same ) ;
126+ }
127+
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 ( )
130+ {
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 ) ;
134+ var testSource = ToComparisonSource ( "hello world" , ComparisonSourceType . Test ) ;
135+ var comparison = new Comparison ( controlSource , testSource ) ;
136+
137+
138+ sut . Compare ( comparison , CompareResult . Different ) . ShouldBe ( CompareResult . Same ) ;
139+ }
140+
141+
73142 // 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.
74143 }
75144}
0 commit comments