-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMdSyntaxNodeModifierTests.cs
More file actions
82 lines (66 loc) · 3.58 KB
/
Copy pathMdSyntaxNodeModifierTests.cs
File metadata and controls
82 lines (66 loc) · 3.58 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;
namespace InfiniBlazorTests.Core.Markdown.Syntax;
// ---------------------------------------------------------------------------------------------------------------------
// Code
// ---------------------------------------------------------------------------------------------------------------------
public class MdSyntaxNodeModifierTests {
public static IEnumerable<Func<(string Input, int Count, string[][] ExpectedOutput)>> AttributeValueDataSources() {
yield return () => ("", 0, []);
yield return () => ("|", 0, []);
yield return () => ("|=", 0, []);
yield return () => ("|size=100x100", 1, []);
yield return () => ("|size=100x100|", 1, [["size", "100x100"]]);
yield return () => ("|size=100x100|something=else",2, [["size", "100x100"], ["something", "else"]]);
yield return () => ("|size=100x100|something=else|",2, [["size", "100x100"], ["something", "else"]]);
// On duplicate keys the default behavior should be to take the last one.
yield return () => ("|something=else|something=different",1, [["something", "different"]]);
yield return () => ("|something=else|something=different|",1, [["something", "different"]]);
// Test Escaped pipes
yield return () => (@"|something=\||",1, [["something", @"\|"]]);
yield return () => (@"|something=\\||",1, [["something", @"\\"]]);
yield return () => (@"|something=\\\||",1, [["something", @"\\\|"]]);
yield return () => ("|something=||",1, [["something", ""]]);
yield return () => ("|something=\"else\"|",1, [["something", "else"]]);
yield return () => ("|something=\"else\\\"\"|",1, [["something", "else\""]]);
yield return () => ("|something=\"with \\\"content\\\"\"|",1, [["something", "with \"content\""]]);
}
[Test]
[MethodDataSource(nameof(AttributeValueDataSources))]
public async Task TryGetAttributeValue(string input, int count, string[][] expectedOutput) {
// Arrange
// Act
MdSyntaxNodeModifier mod = MdSyntaxNodeModifier.FromString(input);
// Assert
await Assert.That(mod.Attributes).Count().IsEqualTo(count);
await Parallel.ForEachAsync(expectedOutput, async (expected, _) => {
string attributeKey = expected.First();
string attributeValue = expected.Last();
bool result = mod.TryGetValue(attributeKey, out string? value);
await Assert.That(result).IsTrue();
await Assert.That(value).IsEqualTo(attributeValue);
});
}
[Test]
[Arguments("|flag",true)]
[Arguments("|flag|",true)]
[Arguments("|flag=true",true)]
[Arguments("|flag=true|",true)]
[Arguments("|flag=false",false)]
[Arguments("|flag=false|",false)]
[Arguments("|flag=1",true)]
[Arguments("|flag=1|",true)]
[Arguments("|flag=0",false)]
[Arguments("|flag=0|",false)]
public async Task TryGetAttributeFlag(string input, bool expectedState) {
// Arrange
MdSyntaxNodeModifier mod = MdSyntaxNodeModifier.FromString(input);
// Act
bool result = mod.TryGetFlag("flag", out bool foundState);
// Assert
await Assert.That(result).IsTrue();
await Assert.That(foundState).IsEqualTo(expectedState);
}
}