Files
Explorer-Workbench/tests/Explorer.Application.Tests/MarkdownParserTests.cs

70 lines
2.0 KiB
C#

using Explorer.Application;
namespace Explorer.Application.Tests;
public class MarkdownParserTests
{
[Fact]
public void Parses_headings_lists_and_tables()
{
var doc = MarkdownParser.Parse("""
# Title
Intro paragraph.
## Locations
- One
- Two
| A | B |
| --- | --- |
| 1 | 2 |
""");
Assert.Contains(doc.Blocks, b => b is MarkdownHeading h && h.Level == 1 && h.Text == "Title");
Assert.Equal("Locations", Assert.Single(doc.Headings).Text);
var list = Assert.IsType<MarkdownList>(doc.Blocks.First(b => b is MarkdownList));
Assert.Equal(["One", "Two"], list.Items);
var table = Assert.IsType<MarkdownTable>(doc.Blocks.First(b => b is MarkdownTable));
Assert.Equal(["A", "B"], table.Headers);
Assert.Equal(["1", "2"], Assert.Single(table.Rows));
}
[Fact]
public void Parses_fenced_code()
{
var doc = MarkdownParser.Parse("""
```powershell
dotnet build
```
""");
var code = Assert.IsType<MarkdownCode>(Assert.Single(doc.Blocks));
Assert.Equal("powershell", code.Language);
Assert.Equal("dotnet build", code.Text);
}
[Fact]
public void User_guide_in_the_repo_parses()
{
var dir = new DirectoryInfo(AppContext.BaseDirectory);
string? path = null;
while (dir is not null)
{
var candidate = Path.Combine(dir.FullName, "docs", "Documentation.md");
if (File.Exists(candidate))
{
path = candidate;
break;
}
dir = dir.Parent;
}
Assert.NotNull(path);
var doc = MarkdownParser.Parse(File.ReadAllText(path));
Assert.Contains(doc.Headings, h => h.Text == "Locations");
Assert.Contains(doc.Headings, h => h.Text == "File Operations Queue");
Assert.Contains(doc.Blocks, b => b is MarkdownTable);
}
}