-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextTreeRenderer.cs
57 lines (51 loc) · 1.66 KB
/
TextTreeRenderer.cs
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
using System.Text;
using LightBDD.Core.Metadata;
using LightBDD.Core.Results.Parameters.Trees;
namespace LightBDD.Contrib.ProgressNotifierEnhancements;
/// <summary>
/// Copy and paste of LightBDD class as the original is internal
/// </summary>
internal static class TextTreeRenderer
{
private static void Render(TextWriter writer, string prefix, ITreeParameterDetails tree)
{
var first = true;
foreach (var node in tree.Root.EnumerateAll())
{
if (!first)
writer.WriteLine();
writer.Write(prefix);
writer.Write(GetNodeStatus(node));
writer.Write(" ");
writer.Write(node.Path);
writer.Write(": ");
if (node.VerificationStatus > ParameterVerificationStatus.Success)
{
writer.Write(Escape(node.Expectation));
writer.Write('/');
}
writer.Write(Escape(node.Value));
first = false;
}
}
public static string Render(string prefix, ITreeParameterDetails tree)
{
var sb = new StringBuilder();
using var writer = new StringWriter(sb);
Render(writer, prefix, tree);
return sb.ToString();
}
private static char GetNodeStatus(ITreeParameterNodeResult node)
{
return node.VerificationStatus switch
{
ParameterVerificationStatus.NotApplicable => ' ',
ParameterVerificationStatus.Success => '=',
_ => '!'
};
}
private static string Escape(string text)
{
return text.Replace("\r", "").Replace('\t', ' ').Replace("\n", " ").Replace("\b", "");
}
}