Skip to content

Commit 5cac420

Browse files
committed
Add breadcrumb tests
1 parent 8840326 commit 5cac420

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

src/Elastic.Markdown/IO/MarkdownFile.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ public string? NavigationTitle
5454

5555
private bool _instructionsParsed;
5656

57+
public MarkdownFile[] YieldParents()
58+
{
59+
var parents = new List<MarkdownFile>();
60+
var parent = Parent;
61+
do
62+
{
63+
if (parent is { Index: not null } && parent.Index != this)
64+
parents.Add(parent.Index);
65+
parent = parent?.Parent;
66+
} while (parent != null);
67+
return parents.ToArray();
68+
}
69+
5770
public async Task<MarkdownDocument> MinimalParse(Cancel ctx)
5871
{
5972
var document = await MarkdownParser.MinimalParseAsync(SourceFile, ctx);

src/Elastic.Markdown/Slices/_ViewModels.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,7 @@ public MarkdownFile[] Parents
3535
if (_parents is not null)
3636
return _parents;
3737

38-
var parents = new List<MarkdownFile>();
39-
var current = CurrentDocument.Parent;
40-
do
41-
{
42-
if (current is { Index: not null } && current.Index != CurrentDocument)
43-
parents.Add(current.Index);
44-
current = current?.Parent;
45-
} while (current != null);
46-
47-
_parents = [.. parents];
38+
_parents = [.. CurrentDocument.YieldParents()];
4839
return _parents;
4940
}
5041
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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.Markdown.IO;
6+
using FluentAssertions;
7+
using Xunit.Abstractions;
8+
9+
namespace Elastic.Markdown.Tests.SiteMap;
10+
11+
public class BreadCrumbTests(ITestOutputHelper output) : NavigationTestsBase(output)
12+
{
13+
[Fact]
14+
public void ParsesATableOfContents()
15+
{
16+
var doc = Generator.DocumentationSet.Files.FirstOrDefault(f => f.RelativePath == "testing/nested/index.md") as MarkdownFile;
17+
18+
doc.Should().NotBeNull();
19+
20+
doc!.Parent.Should().NotBeNull();
21+
22+
doc.YieldParents().Should().HaveCount(2);
23+
24+
}
25+
}

0 commit comments

Comments
 (0)