Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 34 additions & 25 deletions tests/Elastic.Markdown.Tests/CodeBlocks/CallOutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,23 @@ public void ParsesMagicCallOuts() => Block!.CallOuts

[Fact]
public void RendersExpectedHtml() =>
Html.ReplaceLineEndings().Should().Contain("""
<div class="highlight-csharp notranslate">
<div class="highlight">
<pre><code class="language-csharp">var x = 1;<span style="display: inline-block; width: 1ch"></span><span class="code-callout" data-index="1"></span>
var y = x - 2;
var z = y - 2;<span style="display: inline-block; width: 1ch"></span><span class="code-callout" data-index="2"></span>
</code></pre>
</div>
</div>
<p><strong>OUTPUT:</strong></p>
<ol class="code-callouts">
<li>Marking the first callout</li>
<li>Marking the second callout</li>
</ol>
""".ReplaceLineEndings());
Html.ShouldBeHtml(
"""
<div class="highlight-csharp notranslate">
<div class="highlight">
<pre><code class="language-csharp">var x = 1;<span style="display: inline-block; width: 1ch"></span><span class="code-callout" data-index="1"></span>
var y = x - 2;
var z = y - 2;<span style="display: inline-block; width: 1ch"></span><span class="code-callout" data-index="2"></span>
</code></pre>
</div>
</div>
<p><strong>OUTPUT:</strong></p>
<ol class="code-callouts">
<li>Marking the first callout</li>
<li>Marking the second callout</li>
</ol>
"""
);


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

[Fact]
public void RenderedHtmlContainsCallouts() =>
Html.ReplaceLineEndings().Should().Contain("""
<ol class="code-callouts">
<li>First callout</li>
<li>Second callout</li>
</ol>
""".ReplaceLineEndings());
Html.ShouldContainHtml(
"""
<ol class="code-callouts">
<li>First callout</li>
<li>Second callout</li>
</ol>
"""
);
}

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

[Fact]
public void RendersIntermediateParagraph() =>
Html.ReplaceLineEndings().Should().Contain("""
<p><strong>This is an intermediate paragraph</strong></p>
<ol class="code-callouts">
""".ReplaceLineEndings());
Html.ShouldContainHtml(
"""
<p><strong>This is an intermediate paragraph</strong></p>
<ol class="code-callouts">
<li>First callout</li>
<li>Second callout</li>
</ol>
"""
);
}

public class CodeBlockWithCommentBlocksTwoParagraphsThenList(ITestOutputHelper output) : CodeBlockCallOutTests(output, "csharp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ protected override void AddToFileSystem(MockFileSystem fileSystem)

[Fact]
public void IncludesInclusionHtml() =>
Html.Should()
.Contain("Hello world")
.And.Be("<p><em>Hello world</em></p>")
;
Html.ShouldBeHtml("<p><em>Hello world</em></p>");
}


Expand Down
3 changes: 1 addition & 2 deletions tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public class InPageAnchorTests(ITestOutputHelper output) : AnchorLinkTestBase(ou
{
[Fact]
public void GeneratesHtml() =>
// language=html
Html.Should().Contain(
Html.ShouldContainHtml(
"""<p><a href="#hello-world">Hello</a></p>"""
);

Expand Down
52 changes: 31 additions & 21 deletions tests/Elastic.Markdown.Tests/Inline/CommentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ not a comment
{

[Fact]
public void GeneratesAttributesInHtml() =>
public void GeneratesAttributesInHtml()
{
// language=html
Html.Should().NotContain(
"""<p>% comment"""
)
.And.Contain(
"""<p>not a comment</p>"""
).And.Be(
"""<p>% comment"""
)
.And.Contain(
"""<p>not a comment</p>"""
);
Html.ShouldBeHtml(
"""
<p>not a comment</p>
"""
);
}
}

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

[Fact]
public void GeneratesAttributesInHtml() =>
public void GeneratesAttributesInHtml()
{
// language=html
Html.ReplaceLineEndings().Should().NotContainAny(
Html.Should().NotContainAny(
"<p><!--",
"<p>Multi line comment, first line",
"<p>Another line inside the commented area",
"<p>end of comments",
"<p>-->")
"<p>-->"
)
.And.ContainAll(
"<p>not a comment, and multi line comment below</p>",
"<p>also not a comment</p>"
).And.Be(
"""
<p>not a comment, and multi line comment below</p>
<p>also not a comment</p>
""".ReplaceLineEndings()
);
);
Html.ShouldBeHtml(
"""
<p>not a comment, and multi line comment below</p>
<p>also not a comment</p>
"""
);
}
}

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

[Fact]
public void GeneratesAttributesInHtml() =>
public void GeneratesAttributesInHtml()
{
// language=html
Html.ReplaceLineEndings().Should().NotContainAny(
"<p><!--",
Expand All @@ -92,10 +100,12 @@ public void GeneratesAttributesInHtml() =>
.And.ContainAll(
"<p>not a comment, and multi line comment below</p>",
"<p>also not a comment</p>"
).And.Be(
"""
<p>not a comment, and multi line comment below</p>
<p>also not a comment</p>
""".ReplaceLineEndings()
);
Html.ShouldBeHtml(
"""
<p>not a comment, and multi line comment below</p>
<p>also not a comment</p>
"""
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class InPageDirectiveLinkTests(ITestOutputHelper output) : DirectiveBlock
[Fact]
public void GeneratesHtml() =>
// language=html
Html.Should().Contain(
Html.ShouldContainHtml(
"""<p><a href="#caution_ref">Hello</a></p>"""
);

Expand Down
6 changes: 3 additions & 3 deletions tests/Elastic.Markdown.Tests/Inline/HardBreakTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class AllowBrTagTest(ITestOutputHelper output)
{
[Fact]
public void GeneratesHtml() =>
Html.Should().Contain(
Html.ShouldContainHtml(
"<p>Hello,<br>World!</p>"
);
}
Expand All @@ -23,7 +23,7 @@ public class BrTagNeedsToBeExact(ITestOutputHelper output)
{
[Fact]
public void GeneratesHtml() =>
Html.Should().Contain(
Html.ShouldContainHtml(
"<p>Hello,&lt;br &gt;World&lt;br /&gt;!</p>"
);
}
Expand All @@ -35,7 +35,7 @@ public class DisallowSpanTag(ITestOutputHelper output)
[Fact]
// span tag is rendered as text
public void GeneratesHtml() =>
Html.Should().Contain(
Html.ShouldContainHtml(
"<p>Hello,&lt;span&gt;World!&lt;/span&gt;</p>"
);
}
20 changes: 10 additions & 10 deletions tests/Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public void ParsesBlock()

[Fact]
public void GeneratesAttributesInHtml() =>
// language=html
Html.Should().Contain(
Html.ShouldContainHtml(
"""<p>this is regular text and this <a id="is-an-inline-anchor"></a> and this continues to be regular text</p>"""
);
}
Expand Down Expand Up @@ -69,7 +68,7 @@ public void ParsesBlock()
[Fact]
public void GeneratesAttributesInHtml() =>
// language=html
Html.Should().Contain(
Html.ShouldContainHtml(
"""<p>this is regular text and this <a id="is-an-inline-anchor"></a></p>"""
);
}
Expand Down Expand Up @@ -97,7 +96,7 @@ this is regular text and this $$$is-an-inline-anchor$$
[Fact]
public void GeneratesAttributesInHtml() =>
// language=html
Html.Should().Contain(
Html.ShouldContainHtml(
"""<p>this is regular text and this $$$is-an-inline-anchor$$</p>"""
);
}
Expand All @@ -111,11 +110,11 @@ public class InlineAnchorInHeading(ITestOutputHelper output) : BlockTest<Heading
[Fact]
public void GeneratesAttributesInHtml() =>
// language=html
Html.ReplaceLineEndings().TrimEnd().Should().Be(
Html.ShouldBeHtml(
"""
<div class="heading-wrapper" id="hello-world"><h2><a class="headerlink" href="#hello-world">Hello world <a id="my-anchor"></a></a></h2>
</div>
""".ReplaceLineEndings().TrimEnd()
"""
);
}

Expand All @@ -128,11 +127,12 @@ public class ExplicitSlugInHeader(ITestOutputHelper output) : BlockTest<HeadingB
[Fact]
public void GeneratesAttributesInHtml() =>
// language=html
Html.ReplaceLineEndings().TrimEnd().Should().Be(
Html.ShouldBeHtml(
"""
<div class="heading-wrapper" id="my-anchor"><h2><a class="headerlink" href="#my-anchor">Hello world</a></h2>
<div class="heading-wrapper" id="my-anchor">
<h2><a class="headerlink" href="#my-anchor">Hello world</a></h2>
</div>
""".ReplaceLineEndings().TrimEnd()
"""
);
}

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

Expand Down
4 changes: 2 additions & 2 deletions tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class InlineImageTest(ITestOutputHelper output) : InlineTest<LinkInline>(
[Fact]
public void GeneratesAttributesInHtml() =>
// language=html
Html.Should().Contain(
Html.ShouldContainHtml(
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" /></p>"""
);
}
Expand All @@ -35,7 +35,7 @@ public class RelativeInlineImageTest(ITestOutputHelper output) : InlineTest<Link
[Fact]
public void GeneratesAttributesInHtml() =>
// language=html
Html.Should().Contain(
Html.ShouldContainHtml(
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" /></p>"""
);
}
8 changes: 3 additions & 5 deletions tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ public class CrossLinkReferenceTest(ITestOutputHelper output) : LinkTestBase(out
{
[Fact]
public void GeneratesHtml() =>
// language=html
Html.Should().Contain(
Html.ShouldContainHtml(
"""<p><a href="https://docs-v3-preview.elastic.dev/elastic/kibana/tree/main/">test</a></p>"""
);

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

Expand Down Expand Up @@ -262,7 +260,7 @@ public class CommentedNonExistingLinks2(ITestOutputHelper output) : LinkTestBase
{
[Fact]
public void GeneratesHtml() =>
Html.ShouldMatchHtml(
Html.ShouldBeHtml(
"""
<p>Links:</p>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion tests/Elastic.Markdown.Tests/Inline/SubstitutionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public class ReplaceInHeader(ITestOutputHelper output) : InlineTest(output,

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

[Fact]
public void HasNoErrors() => Collector.Diagnostics.Should().HaveCount(0);
Expand Down
10 changes: 8 additions & 2 deletions tests/Elastic.Markdown.Tests/PrettyHtmlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static string PrettyHtml([LanguageInjection("html")] this string html, bo
return sw.ToString().TrimStart('\n');
}

public static void ShouldMatchHtml(
public static void ShouldBeHtml(
[LanguageInjection("html")] this string actual,
[LanguageInjection("html")] string expected,
bool sanitize = true
Expand Down Expand Up @@ -79,7 +79,13 @@ public static void ShouldContainHtml(
expected = expected.Trim('\n').PrettyHtml(sanitize);
actual = actual.Trim('\n').PrettyHtml(sanitize);

actual.Should().Contain(expected);
var actualCompare = actual.Replace("\t", string.Empty);
var expectedCompare = actual.Replace("\t", string.Empty);

// we compare over unindented HTML, but if that fails, we rely on the pretty HTML Contain().
// to throw for improved error messages
if (!actualCompare.Contains(expectedCompare))
actual.Should().Contain(expected);
}

public static string CreateDiff(this string actual, string expected, bool sanitize = true)
Expand Down
Loading