Skip to content

Commit 0d031be

Browse files
committed
Add test
1 parent aa53b9a commit 0d031be

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using Elastic.Documentation.Diagnostics;
6+
using Elastic.Markdown.Tests.Inline;
7+
using FluentAssertions;
8+
9+
namespace Elastic.Markdown.Tests.TextFormat;
10+
11+
public class IrregularWhitespaceTest(ITestOutputHelper output) : InlineTest(output,
12+
"""
13+
# Heading with no-break space\u00A0character
14+
15+
This is a paragraph with some\u2002en space and\u200Bzero width space.
16+
17+
## Subheading with\u3000ideographic space
18+
19+
* List item with\u00A0no-break space
20+
* Another item
21+
22+
```csharp
23+
// Code with\u00A0no-break space
24+
var x = 1;
25+
```
26+
27+
> Blockquote with\u2003em space
28+
"""
29+
)
30+
{
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+
}
119+
}

0 commit comments

Comments
 (0)