Skip to content

Commit 78d73e8

Browse files
authored
Update assertions to use new HTML assertions for improved legibility and error messages (#1430)
1 parent cb72d5e commit 78d73e8

File tree

11 files changed

+95
-76
lines changed

11 files changed

+95
-76
lines changed

tests/Elastic.Markdown.Tests/CodeBlocks/CallOutTests.cs

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,23 @@ public void ParsesMagicCallOuts() => Block!.CallOuts
118118

119119
[Fact]
120120
public void RendersExpectedHtml() =>
121-
Html.ReplaceLineEndings().Should().Contain("""
122-
<div class="highlight-csharp notranslate">
123-
<div class="highlight">
124-
<pre><code class="language-csharp">var x = 1;<span style="display: inline-block; width: 1ch"></span><span class="code-callout" data-index="1"></span>
125-
var y = x - 2;
126-
var z = y - 2;<span style="display: inline-block; width: 1ch"></span><span class="code-callout" data-index="2"></span>
127-
</code></pre>
128-
</div>
129-
</div>
130-
<p><strong>OUTPUT:</strong></p>
131-
<ol class="code-callouts">
132-
<li>Marking the first callout</li>
133-
<li>Marking the second callout</li>
134-
</ol>
135-
""".ReplaceLineEndings());
121+
Html.ShouldBeHtml(
122+
"""
123+
<div class="highlight-csharp notranslate">
124+
<div class="highlight">
125+
<pre><code class="language-csharp">var x = 1;<span style="display: inline-block; width: 1ch"></span><span class="code-callout" data-index="1"></span>
126+
var y = x - 2;
127+
var z = y - 2;<span style="display: inline-block; width: 1ch"></span><span class="code-callout" data-index="2"></span>
128+
</code></pre>
129+
</div>
130+
</div>
131+
<p><strong>OUTPUT:</strong></p>
132+
<ol class="code-callouts">
133+
<li>Marking the first callout</li>
134+
<li>Marking the second callout</li>
135+
</ol>
136+
"""
137+
);
136138

137139

138140
[Fact]
@@ -367,12 +369,14 @@ public void ParsesCallouts() => Block!.CallOuts
367369

368370
[Fact]
369371
public void RenderedHtmlContainsCallouts() =>
370-
Html.ReplaceLineEndings().Should().Contain("""
371-
<ol class="code-callouts">
372-
<li>First callout</li>
373-
<li>Second callout</li>
374-
</ol>
375-
""".ReplaceLineEndings());
372+
Html.ShouldContainHtml(
373+
"""
374+
<ol class="code-callouts">
375+
<li>First callout</li>
376+
<li>Second callout</li>
377+
</ol>
378+
"""
379+
);
376380
}
377381

378382
public class CodeBlockWithMultipleCommentTypesThenList(ITestOutputHelper output) : CodeBlockCallOutTests(output, "csharp",
@@ -426,10 +430,15 @@ public void ParsesCallouts() => Block!.CallOuts
426430

427431
[Fact]
428432
public void RendersIntermediateParagraph() =>
429-
Html.ReplaceLineEndings().Should().Contain("""
430-
<p><strong>This is an intermediate paragraph</strong></p>
431-
<ol class="code-callouts">
432-
""".ReplaceLineEndings());
433+
Html.ShouldContainHtml(
434+
"""
435+
<p><strong>This is an intermediate paragraph</strong></p>
436+
<ol class="code-callouts">
437+
<li>First callout</li>
438+
<li>Second callout</li>
439+
</ol>
440+
"""
441+
);
433442
}
434443

435444
public class CodeBlockWithCommentBlocksTwoParagraphsThenList(ITestOutputHelper output) : CodeBlockCallOutTests(output, "csharp",

tests/Elastic.Markdown.Tests/FileInclusion/IncludeTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ protected override void AddToFileSystem(MockFileSystem fileSystem)
3131

3232
[Fact]
3333
public void IncludesInclusionHtml() =>
34-
Html.Should()
35-
.Contain("Hello world")
36-
.And.Be("<p><em>Hello world</em></p>")
37-
;
34+
Html.ShouldBeHtml("<p><em>Hello world</em></p>");
3835
}
3936

4037

tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ public class InPageAnchorTests(ITestOutputHelper output) : AnchorLinkTestBase(ou
5656
{
5757
[Fact]
5858
public void GeneratesHtml() =>
59-
// language=html
60-
Html.Should().Contain(
59+
Html.ShouldContainHtml(
6160
"""<p><a href="#hello-world">Hello</a></p>"""
6261
);
6362

tests/Elastic.Markdown.Tests/Inline/CommentTest.cs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@ not a comment
1414
{
1515

1616
[Fact]
17-
public void GeneratesAttributesInHtml() =>
17+
public void GeneratesAttributesInHtml()
18+
{
1819
// language=html
1920
Html.Should().NotContain(
20-
"""<p>% comment"""
21-
)
22-
.And.Contain(
23-
"""<p>not a comment</p>"""
24-
).And.Be(
21+
"""<p>% comment"""
22+
)
23+
.And.Contain(
24+
"""<p>not a comment</p>"""
25+
);
26+
Html.ShouldBeHtml(
2527
"""
2628
<p>not a comment</p>
2729
"""
2830
);
31+
}
2932
}
3033

3134
public class MultipleLineCommentTest(ITestOutputHelper output) : InlineTest(output,
@@ -43,23 +46,27 @@ also not a comment
4346
{
4447

4548
[Fact]
46-
public void GeneratesAttributesInHtml() =>
49+
public void GeneratesAttributesInHtml()
50+
{
4751
// language=html
48-
Html.ReplaceLineEndings().Should().NotContainAny(
52+
Html.Should().NotContainAny(
4953
"<p><!--",
5054
"<p>Multi line comment, first line",
5155
"<p>Another line inside the commented area",
5256
"<p>end of comments",
53-
"<p>-->")
57+
"<p>-->"
58+
)
5459
.And.ContainAll(
5560
"<p>not a comment, and multi line comment below</p>",
5661
"<p>also not a comment</p>"
57-
).And.Be(
58-
"""
59-
<p>not a comment, and multi line comment below</p>
60-
<p>also not a comment</p>
61-
""".ReplaceLineEndings()
62-
);
62+
);
63+
Html.ShouldBeHtml(
64+
"""
65+
<p>not a comment, and multi line comment below</p>
66+
<p>also not a comment</p>
67+
"""
68+
);
69+
}
6370
}
6471

6572
public class MultipleLineCommentWithLinkTest(ITestOutputHelper output) : InlineTest(output,
@@ -80,7 +87,8 @@ also not a comment
8087
public void HasNoErrors() => Collector.Diagnostics.Should().HaveCount(0);
8188

8289
[Fact]
83-
public void GeneratesAttributesInHtml() =>
90+
public void GeneratesAttributesInHtml()
91+
{
8492
// language=html
8593
Html.ReplaceLineEndings().Should().NotContainAny(
8694
"<p><!--",
@@ -92,10 +100,12 @@ public void GeneratesAttributesInHtml() =>
92100
.And.ContainAll(
93101
"<p>not a comment, and multi line comment below</p>",
94102
"<p>also not a comment</p>"
95-
).And.Be(
96-
"""
97-
<p>not a comment, and multi line comment below</p>
98-
<p>also not a comment</p>
99-
""".ReplaceLineEndings()
100103
);
104+
Html.ShouldBeHtml(
105+
"""
106+
<p>not a comment, and multi line comment below</p>
107+
<p>also not a comment</p>
108+
"""
109+
);
110+
}
101111
}

tests/Elastic.Markdown.Tests/Inline/DirectiveBlockLinkTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class InPageDirectiveLinkTests(ITestOutputHelper output) : DirectiveBlock
4848
[Fact]
4949
public void GeneratesHtml() =>
5050
// language=html
51-
Html.Should().Contain(
51+
Html.ShouldContainHtml(
5252
"""<p><a href="#caution_ref">Hello</a></p>"""
5353
);
5454

tests/Elastic.Markdown.Tests/Inline/HardBreakTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class AllowBrTagTest(ITestOutputHelper output)
1212
{
1313
[Fact]
1414
public void GeneratesHtml() =>
15-
Html.Should().Contain(
15+
Html.ShouldContainHtml(
1616
"<p>Hello,<br>World!</p>"
1717
);
1818
}
@@ -23,7 +23,7 @@ public class BrTagNeedsToBeExact(ITestOutputHelper output)
2323
{
2424
[Fact]
2525
public void GeneratesHtml() =>
26-
Html.Should().Contain(
26+
Html.ShouldContainHtml(
2727
"<p>Hello,&lt;br &gt;World&lt;br /&gt;!</p>"
2828
);
2929
}
@@ -35,7 +35,7 @@ public class DisallowSpanTag(ITestOutputHelper output)
3535
[Fact]
3636
// span tag is rendered as text
3737
public void GeneratesHtml() =>
38-
Html.Should().Contain(
38+
Html.ShouldContainHtml(
3939
"<p>Hello,&lt;span&gt;World!&lt;/span&gt;</p>"
4040
);
4141
}

tests/Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ public void ParsesBlock()
2626

2727
[Fact]
2828
public void GeneratesAttributesInHtml() =>
29-
// language=html
30-
Html.Should().Contain(
29+
Html.ShouldContainHtml(
3130
"""<p>this is regular text and this <a id="is-an-inline-anchor"></a> and this continues to be regular text</p>"""
3231
);
3332
}
@@ -69,7 +68,7 @@ public void ParsesBlock()
6968
[Fact]
7069
public void GeneratesAttributesInHtml() =>
7170
// language=html
72-
Html.Should().Contain(
71+
Html.ShouldContainHtml(
7372
"""<p>this is regular text and this <a id="is-an-inline-anchor"></a></p>"""
7473
);
7574
}
@@ -97,7 +96,7 @@ this is regular text and this $$$is-an-inline-anchor$$
9796
[Fact]
9897
public void GeneratesAttributesInHtml() =>
9998
// language=html
100-
Html.Should().Contain(
99+
Html.ShouldContainHtml(
101100
"""<p>this is regular text and this $$$is-an-inline-anchor$$</p>"""
102101
);
103102
}
@@ -111,11 +110,11 @@ public class InlineAnchorInHeading(ITestOutputHelper output) : BlockTest<Heading
111110
[Fact]
112111
public void GeneratesAttributesInHtml() =>
113112
// language=html
114-
Html.ReplaceLineEndings().TrimEnd().Should().Be(
113+
Html.ShouldBeHtml(
115114
"""
116115
<div class="heading-wrapper" id="hello-world"><h2><a class="headerlink" href="#hello-world">Hello world <a id="my-anchor"></a></a></h2>
117116
</div>
118-
""".ReplaceLineEndings().TrimEnd()
117+
"""
119118
);
120119
}
121120

@@ -128,11 +127,12 @@ public class ExplicitSlugInHeader(ITestOutputHelper output) : BlockTest<HeadingB
128127
[Fact]
129128
public void GeneratesAttributesInHtml() =>
130129
// language=html
131-
Html.ReplaceLineEndings().TrimEnd().Should().Be(
130+
Html.ShouldBeHtml(
132131
"""
133-
<div class="heading-wrapper" id="my-anchor"><h2><a class="headerlink" href="#my-anchor">Hello world</a></h2>
132+
<div class="heading-wrapper" id="my-anchor">
133+
<h2><a class="headerlink" href="#my-anchor">Hello world</a></h2>
134134
</div>
135-
""".ReplaceLineEndings().TrimEnd()
135+
"""
136136
);
137137
}
138138

@@ -182,7 +182,7 @@ public class InlineAnchorCanBeLinkedToo(ITestOutputHelper output) : InlineAnchor
182182
[Fact]
183183
public void GeneratesHtml() =>
184184
// language=html
185-
Html.Should().Contain(
185+
Html.ShouldContainHtml(
186186
"""<p><a href="#same-page-anchor">Hello</a></p>"""
187187
);
188188

tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class InlineImageTest(ITestOutputHelper output) : InlineTest<LinkInline>(
1818
[Fact]
1919
public void GeneratesAttributesInHtml() =>
2020
// language=html
21-
Html.Should().Contain(
21+
Html.ShouldContainHtml(
2222
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" /></p>"""
2323
);
2424
}
@@ -35,7 +35,7 @@ public class RelativeInlineImageTest(ITestOutputHelper output) : InlineTest<Link
3535
[Fact]
3636
public void GeneratesAttributesInHtml() =>
3737
// language=html
38-
Html.Should().Contain(
38+
Html.ShouldContainHtml(
3939
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" /></p>"""
4040
);
4141
}

tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ public class CrossLinkReferenceTest(ITestOutputHelper output) : LinkTestBase(out
124124
{
125125
[Fact]
126126
public void GeneratesHtml() =>
127-
// language=html
128-
Html.Should().Contain(
127+
Html.ShouldContainHtml(
129128
"""<p><a href="https://docs-v3-preview.elastic.dev/elastic/kibana/tree/main/">test</a></p>"""
130129
);
131130

@@ -188,8 +187,7 @@ [link to app]({{some-url-with-a-version}})
188187
{
189188
[Fact]
190189
public void GeneratesHtml() =>
191-
// language=html
192-
Html.Should().Contain(
190+
Html.ShouldContainHtml(
193191
"""<p><a href="https://github.com/elastic/fake-repo/tree/v1.17.0" target="_blank" rel="noopener noreferrer">link to app</a></p>"""
194192
);
195193

@@ -262,7 +260,7 @@ public class CommentedNonExistingLinks2(ITestOutputHelper output) : LinkTestBase
262260
{
263261
[Fact]
264262
public void GeneratesHtml() =>
265-
Html.ShouldMatchHtml(
263+
Html.ShouldBeHtml(
266264
"""
267265
<p>Links:</p>
268266
<ul>

tests/Elastic.Markdown.Tests/Inline/SubstitutionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public class ReplaceInHeader(ITestOutputHelper output) : InlineTest(output,
159159

160160
[Fact]
161161
public void OnlySeesGlobalVariable() =>
162-
Html.Should().Contain("<h2><a class=\"headerlink\" href=\"#custom-anchor\">Hello World!</a></h2>");
162+
Html.ShouldContainHtml("""<h2><a class="headerlink" href="#custom-anchor">Hello World!</a></h2>""");
163163

164164
[Fact]
165165
public void HasNoErrors() => Collector.Diagnostics.Should().HaveCount(0);

0 commit comments

Comments
 (0)