22// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33// See the LICENSE file in the project root for more information
44
5+ using System . Linq ;
6+
57using Elastic . Documentation . Diagnostics ;
68using Elastic . Markdown . Tests . Inline ;
79using FluentAssertions ;
810
11+ using Xunit ;
12+ using Xunit . Abstractions ;
13+
914namespace Elastic . Markdown . Tests . TextFormat ;
1015
1116public class IrregularWhitespaceTest ( ITestOutputHelper output ) : InlineTest ( output ,
@@ -28,92 +33,92 @@ This is a paragraph with some\u2002en space and\u200Bzero width space.
2833"""
2934)
3035{
31- [ Fact ]
32- public void DetectsIrregularWhitespaceInHeading ( )
33- {
34- var diagnostics = Collector . Diagnostics
35- . Where ( d => d . Line == 1 )
36- . Where ( d => d . Message . Contains ( "U+00A0" ) )
37- . ToList ( ) ;
38-
39- diagnostics . Should ( ) . HaveCount ( 1 ) ;
40- diagnostics [ 0 ] . Severity . Should ( ) . Be ( Severity . Warning ) ;
41- }
42-
43- [ Fact ]
44- public void DetectsIrregularWhitespaceInParagraph ( )
45- {
46- var diagnostics = Collector . Diagnostics
47- . Where ( d => d . Line == 3 )
48- . Where ( d => d . Message . Contains ( "irregular whitespace" ) )
49- . ToList ( ) ;
50-
51- diagnostics . Should ( ) . HaveCountGreaterThanOrEqualTo ( 2 ) ;
52-
53- // Verify en space detection
54- diagnostics . Should ( ) . Contain ( d => d . Message . Contains ( "U+2002" ) ) ;
55-
56- // Verify zero width space detection
57- diagnostics . Should ( ) . Contain ( d => d . Message . Contains ( "U+200B" ) ) ;
58- }
59-
60- [ Fact ]
61- public void DetectsIrregularWhitespaceInSubheading ( )
62- {
63- var diagnostics = Collector . Diagnostics
64- . Where ( d => d . Line == 5 )
65- . Where ( d => d . Message . Contains ( "U+3000" ) )
66- . ToList ( ) ;
67-
68- diagnostics . Should ( ) . HaveCount ( 1 ) ;
69- diagnostics [ 0 ] . Severity . Should ( ) . Be ( Severity . Warning ) ;
70- }
71-
72- [ Fact ]
73- public void DetectsIrregularWhitespaceInListItem ( )
74- {
75- var diagnostics = Collector . Diagnostics
76- . Where ( d => d . Line == 7 )
77- . Where ( d => d . Message . Contains ( "U+00A0" ) )
78- . ToList ( ) ;
79-
80- diagnostics . Should ( ) . HaveCount ( 1 ) ;
81- diagnostics [ 0 ] . Severity . Should ( ) . Be ( Severity . Warning ) ;
82- }
83-
84- [ Fact ]
85- public void DetectsIrregularWhitespaceInCodeBlock ( )
86- {
87- var diagnostics = Collector . Diagnostics
88- . Where ( d => d . Line == 11 )
89- . Where ( d => d . Message . Contains ( "U+00A0" ) )
90- . ToList ( ) ;
91-
92- diagnostics . Should ( ) . HaveCount ( 1 ) ;
93- diagnostics [ 0 ] . Severity . Should ( ) . Be ( Severity . Warning ) ;
94- }
95-
96- [ Fact ]
97- public void DetectsIrregularWhitespaceInBlockquote ( )
98- {
99- var diagnostics = Collector . Diagnostics
100- . Where ( d => d . Line == 15 )
101- . Where ( d => d . Message . Contains ( "U+2003" ) )
102- . ToList ( ) ;
103-
104- diagnostics . Should ( ) . HaveCount ( 1 ) ;
105- diagnostics [ 0 ] . Severity . Should ( ) . Be ( Severity . Warning ) ;
106- }
107-
108- [ Fact ]
109- public void GeneratesProperWarningMessage ( )
110- {
111- var noBreakSpaceWarning = Collector . Diagnostics
112- . FirstOrDefault ( d => d . Message . Contains ( "U+00A0" ) ) ;
113-
114- noBreakSpaceWarning . Should ( ) . NotBeNull ( ) ;
115- noBreakSpaceWarning ! . Message . Should ( )
116- . Contain ( "Irregular whitespace character detected: U+00A0 (No-Break Space (NBSP))" )
117- . And . Contain ( "may impair Markdown rendering" ) ;
118- }
36+ [ Fact ]
37+ public void DetectsIrregularWhitespaceInHeading ( )
38+ {
39+ var diagnostics = Collector . Diagnostics
40+ . Where ( d => d . Line == 1 )
41+ . Where ( d => d . Message . Contains ( "U+00A0" ) )
42+ . ToList ( ) ;
43+
44+ diagnostics . Should ( ) . HaveCount ( 1 ) ;
45+ diagnostics [ 0 ] . Severity . Should ( ) . Be ( Severity . Warning ) ;
46+ }
47+
48+ [ Fact ]
49+ public void DetectsIrregularWhitespaceInParagraph ( )
50+ {
51+ var diagnostics = Collector . Diagnostics
52+ . Where ( d => d . Line == 3 )
53+ . Where ( d => d . Message . Contains ( "irregular whitespace" ) )
54+ . ToList ( ) ;
55+
56+ diagnostics . Should ( ) . HaveCountGreaterThanOrEqualTo ( 2 ) ;
57+
58+ // Verify en space detection
59+ diagnostics . Should ( ) . Contain ( d => d . Message . Contains ( "U+2002" ) ) ;
60+
61+ // Verify zero width space detection
62+ diagnostics . Should ( ) . Contain ( d => d . Message . Contains ( "U+200B" ) ) ;
63+ }
64+
65+ [ Fact ]
66+ public void DetectsIrregularWhitespaceInSubheading ( )
67+ {
68+ var diagnostics = Collector . Diagnostics
69+ . Where ( d => d . Line == 5 )
70+ . Where ( d => d . Message . Contains ( "U+3000" ) )
71+ . ToList ( ) ;
72+
73+ diagnostics . Should ( ) . HaveCount ( 1 ) ;
74+ diagnostics [ 0 ] . Severity . Should ( ) . Be ( Severity . Warning ) ;
75+ }
76+
77+ [ Fact ]
78+ public void DetectsIrregularWhitespaceInListItem ( )
79+ {
80+ var diagnostics = Collector . Diagnostics
81+ . Where ( d => d . Line == 7 )
82+ . Where ( d => d . Message . Contains ( "U+00A0" ) )
83+ . ToList ( ) ;
84+
85+ diagnostics . Should ( ) . HaveCount ( 1 ) ;
86+ diagnostics [ 0 ] . Severity . Should ( ) . Be ( Severity . Warning ) ;
87+ }
88+
89+ [ Fact ]
90+ public void DetectsIrregularWhitespaceInCodeBlock ( )
91+ {
92+ var diagnostics = Collector . Diagnostics
93+ . Where ( d => d . Line == 11 )
94+ . Where ( d => d . Message . Contains ( "U+00A0" ) )
95+ . ToList ( ) ;
96+
97+ diagnostics . Should ( ) . HaveCount ( 1 ) ;
98+ diagnostics [ 0 ] . Severity . Should ( ) . Be ( Severity . Warning ) ;
99+ }
100+
101+ [ Fact ]
102+ public void DetectsIrregularWhitespaceInBlockquote ( )
103+ {
104+ var diagnostics = Collector . Diagnostics
105+ . Where ( d => d . Line == 15 )
106+ . Where ( d => d . Message . Contains ( "U+2003" ) )
107+ . ToList ( ) ;
108+
109+ diagnostics . Should ( ) . HaveCount ( 1 ) ;
110+ diagnostics [ 0 ] . Severity . Should ( ) . Be ( Severity . Warning ) ;
111+ }
112+
113+ [ Fact ]
114+ public void GeneratesProperWarningMessage ( )
115+ {
116+ var noBreakSpaceWarning = Collector . Diagnostics
117+ . FirstOrDefault ( d => d . Message . Contains ( "U+00A0" ) ) ;
118+
119+ noBreakSpaceWarning . Should ( ) . NotBeNull ( ) ;
120+ noBreakSpaceWarning ! . Message . Should ( )
121+ . Contain ( "Irregular whitespace character detected: U+00A0 (No-Break Space (NBSP))" )
122+ . And . Contain ( "may impair Markdown rendering" ) ;
123+ }
119124}
0 commit comments