Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Add unit tests ✅
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Jun 20, 2022
1 parent a54f783 commit 7538a7f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
1 change: 1 addition & 0 deletions tests/Nfdi4Plants.Fornax.Tests/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open Tests.MarkdigExtensions
let allTests = testList "" [
Nfdi4PlantsSidebarHeader.tests
Nfdi4PlantsHeader.tests
Nfdi4PlantsCodeBlock.tests
]

[<EntryPoint>]
Expand Down
11 changes: 4 additions & 7 deletions tests/Nfdi4Plants.Fornax.Tests/Nfdi4Plants.Fornax.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>

<ItemGroup>
<Compile Include="nfdi-code.tests.fs" />
<Compile Include="nfdi-header.tests.fs" />
<Compile Include="nfdi-sidebar-element-header.tests.fs" />
<Compile Include="main.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Expecto" Version="9.*" />
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Nfdi4Plants.Fornax\Nfdi4Plants.Fornax.fsproj" />
<ProjectReference Include="..\..\src\Nfdi4Plants.Fornax\Nfdi4Plants.Fornax.fsproj" />
</ItemGroup>
</Project>
</Project>
44 changes: 44 additions & 0 deletions tests/Nfdi4Plants.Fornax.Tests/nfdi-code.tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module Tests.MarkdigExtensions.Nfdi4PlantsCodeBlock

open Expecto
open Fornax.Nfdi4Plants
open Fornax.Nfdi4Plants.MarkdigExtensions.NfdiCode
open Markdig

let pipeline =
let builder = new MarkdownPipelineBuilder()
builder
.UseAdvancedExtensions()
.UseEmojiAndSmiley()
.UseNFDICodeBlock()
.Build()

[<Tests>]
let tests =
testList "UseNFDICodeBlock" [
test "basic case" {
let markdown = """Here is some inline `code`!"""
let result = Markdown.ToHtml(markdown, pipeline)
Expect.equal result $"""<p>Here is some inline <code>code</code>!</p>{'\010'}""" ""
}
test "Fenced code block, no language" {
let markdown = """Test line
```
let someCode = 42
```
"""
let result = Markdown.ToHtml(markdown, pipeline).Trim()
let expected = $"""<p>Test line</p>{'\010'}<nfdi-code>let someCode = 42</nfdi-code>""".Trim()
Expect.equal result expected ""
}
test "Fenced code block" {
let markdown = """Test line
```fsharp
let someCode = 42
```
"""
let result = Markdown.ToHtml(markdown, pipeline)
let expected = $"""<p>Test line</p>{'\010'}<nfdi-code class="language-fsharp">let someCode = 42</nfdi-code>"""
Expect.equal result expected ""
}
]

0 comments on commit 7538a7f

Please sign in to comment.