-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathCoveredCollection.cs
92 lines (86 loc) · 2.63 KB
/
CoveredCollection.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
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
83
84
85
86
87
88
89
90
91
92
using Neo.SmartContract.Testing.Coverage.Formats;
using System;
using System.Collections.Generic;
namespace Neo.SmartContract.Testing.Coverage
{
public class CoveredCollection : CoverageBase
{
/// <summary>
/// Entries
/// </summary>
public CoverageBase[] Entries { get; }
/// <summary>
/// Coverage Lines
/// </summary>
public override IEnumerable<CoverageHit> Lines
{
get
{
foreach (var entry in Entries)
{
foreach (var line in entry.Lines)
{
yield return line;
}
}
}
}
/// <summary>
/// Coverage Branches
/// </summary>
public override IEnumerable<CoverageBranch> Branches
{
get
{
foreach (var entry in Entries)
{
foreach (var branch in entry.Branches)
{
yield return branch;
}
}
}
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="entries">Entries</param>
public CoveredCollection(params CoverageBase[] entries)
{
Entries = entries;
}
/// <summary>
/// Dump coverage
/// </summary>
/// <param name="format">Format</param>
/// <returns>Coverage dump</returns>
public override string Dump(DumpFormat format = DumpFormat.Console)
{
return format switch
{
DumpFormat.Console => new ConsoleFormat(GetEntries()).Dump(),
DumpFormat.Html => new IntructionHtmlFormat(GetEntries()).Dump(),
_ => throw new NotImplementedException(),
};
}
/// <summary>
/// Get covered entries
/// </summary>
/// <returns>IEnumerable</returns>
private IEnumerable<(CoveredContract, Func<CoveredMethod, bool>?)> GetEntries()
{
foreach (var entry in Entries)
{
if (entry is CoveredContract co) yield return (co, null);
if (entry is CoveredMethod cm) yield return (cm.Contract, (CoveredMethod method) => ReferenceEquals(method, cm));
if (entry is CoveredCollection cl)
{
foreach (var subEntry in cl.GetEntries())
{
yield return subEntry;
}
}
}
}
}
}