-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMdSyntaxTreeCachedChildren.cs
More file actions
82 lines (61 loc) · 2.81 KB
/
Copy pathMdSyntaxTreeCachedChildren.cs
File metadata and controls
82 lines (61 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// ---------------------------------------------------------------------------------------------------------------------
// Imports
// ---------------------------------------------------------------------------------------------------------------------
using InfiniBlazor.Markdown.Syntax;
using InfiniBlazor.Markdown.Syntax.Nodes;
namespace InfiniBlazorTests.Core.Markdown.Syntax;
// ---------------------------------------------------------------------------------------------------------------------
// Code
// ---------------------------------------------------------------------------------------------------------------------
public class MdSyntaxTreeCachedChildrenTests {
public static IEnumerable<Func<(MdSyntaxTree, Type, IMdSyntaxNode[])>> GetCachedChildrenByTypeTestCases() {
yield return () => {
var tree = new MdSyntaxTree();
var p1 = new ParagraphMdSyntaxNode();
var p2 = new ParagraphMdSyntaxNode();
p1.AddChildNode(p2);
tree.RootNode.AddChildNode(p1);
tree.StoreChildAtCache(p2);
return (tree, typeof(ParagraphMdSyntaxNode), [
p2
]);
};
yield return () => {
var tree = new MdSyntaxTree();
var p2 = new ParagraphMdSyntaxNode();
tree.RootNode.AddChildNode(new ParagraphMdSyntaxNode());
tree.RootNode.AddChildNode(p2);
tree.StoreChildAtCache(p2);
return (tree, typeof(ParagraphMdSyntaxNode), [
p2
]);
};
yield return () => {
var tree = new MdSyntaxTree();
var p2 = new ParagraphMdSyntaxNode();
var i1 = new ItalicMdSyntaxNode();
p2.AddChildNode(i1);
tree.RootNode.AddChildNode(new ParagraphMdSyntaxNode());
tree.RootNode.AddChildNode(p2);
tree.StoreChildAtCache(i1);
return (tree, typeof(ItalicMdSyntaxNode), [
i1
]);
};
}
[Test]
[MethodDataSource(nameof(GetCachedChildrenByTypeTestCases))]
public async Task StoreCachedChildrenByType_ShouldCreateCorrectCache(MdSyntaxTree tree, Type cachedType, IMdSyntaxNode[] expectedChildren) {
// Arrange & Act
bool result = tree.TryGetCachedChildrenByType(cachedType, out IEnumerable<IMdSyntaxNode>? nodes);
IMdSyntaxNode[]? cachedChildren = nodes?.ToArray();
// Assert
await Assert.That(result).IsTrue();
await Assert.That(cachedChildren).Count().IsEqualTo(expectedChildren.Length);
for (int i = 0; i < expectedChildren.Length; i++) {
IMdSyntaxNode cached = cachedChildren![i];
IMdSyntaxNode expected = expectedChildren[i];
await Assert.That(cached).IsSameReferenceAs(expected);
}
}
}