Skip to content

Commit a937813

Browse files
author
Cédric Belin
committed
Rename the Token class to Tokens
1 parent 97ca106 commit a937813

File tree

9 files changed

+27
-27
lines changed

9 files changed

+27
-27
lines changed

src/BranchCoverage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public sealed class BranchCoverage(int found = 0, int hit = 0, IEnumerable<Branc
2929
/// <returns>The string representation of this object.</returns>
3030
public override string ToString() => string.Join('\n', [
3131
.. Data.Select(item => item.ToString()),
32-
$"{Token.BranchesFound}:{Found}",
33-
$"{Token.BranchesHit}:{Hit}"
32+
$"{Tokens.BranchesFound}:{Found}",
33+
$"{Tokens.BranchesHit}:{Hit}"
3434
]);
3535
}

src/BranchData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public sealed record BranchData(int LineNumber = 0, int BlockNumber = 0, int Bra
1414
/// </summary>
1515
/// <returns>The string representation of this object.</returns>
1616
public override string ToString() {
17-
var value = $"{Token.BranchData}:{LineNumber},{BlockNumber},{BranchNumber}";
17+
var value = $"{Tokens.BranchData}:{LineNumber},{BlockNumber},{BranchNumber}";
1818
return Taken > 0 ? $"{value},{Taken}" : $"{value},-";
1919
}
2020
}

src/FunctionCoverage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public sealed class FunctionCoverage(int found = 0, int hit = 0, IEnumerable<Fun
3030
public override string ToString() => string.Join('\n', [
3131
.. Data.Select(item => item.ToString(asDefinition: true)),
3232
.. Data.Select(item => item.ToString(asDefinition: false)),
33-
$"{Token.FunctionsFound}:{Found}",
34-
$"{Token.FunctionsHit}:{Hit}"
33+
$"{Tokens.FunctionsFound}:{Found}",
34+
$"{Tokens.FunctionsHit}:{Hit}"
3535
]);
3636
}

src/FunctionData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public sealed record FunctionData(string FunctionName = "", int LineNumber = 0,
2121
/// <param name="asDefinition">Whether to return the function definition instead of its data.</param>
2222
/// <returns>The string representation of this object.</returns>
2323
public string ToString(bool asDefinition) {
24-
var token = asDefinition ? Token.FunctionName : Token.FunctionData;
24+
var token = asDefinition ? Tokens.FunctionName : Tokens.FunctionData;
2525
var count = asDefinition ? LineNumber : ExecutionCount;
2626
return $"{token}:{count},{FunctionName}";
2727
}

src/LineCoverage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public sealed class LineCoverage(int found = 0, int hit = 0, IEnumerable<LineDat
2929
/// <returns>The string representation of this object.</returns>
3030
public override string ToString() => string.Join('\n', [
3131
.. Data.Select(item => item.ToString()),
32-
$"{Token.LinesFound}:{Found}",
33-
$"{Token.LinesHit}:{Hit}"
32+
$"{Tokens.LinesFound}:{Found}",
33+
$"{Tokens.LinesHit}:{Hit}"
3434
]);
3535
}

src/LineData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public sealed record LineData(int LineNumber = 0, int ExecutionCount = 0, string
1313
/// </summary>
1414
/// <returns>The string representation of this object.</returns>
1515
public override string ToString() {
16-
var value = $"{Token.LineData}:{LineNumber},{ExecutionCount}";
16+
var value = $"{Tokens.LineData}:{LineNumber},{ExecutionCount}";
1717
return string.IsNullOrWhiteSpace(Checksum) ? value : $"{value},{Checksum}";
1818
}
1919
}

src/Report.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ public static Report Parse(string coverage) {
3636
if (string.IsNullOrWhiteSpace(line)) continue;
3737

3838
var parts = line.Trim().Split(':');
39-
if (parts.Length < 2 && parts[0] != Token.EndOfRecord) throw new FormatException($"Invalid token format at line {offset}.");
39+
if (parts.Length < 2 && parts[0] != Tokens.EndOfRecord) throw new FormatException($"Invalid token format at line {offset}.");
4040

4141
var data = string.Join(':', parts[1..]).Split(',');
4242
var token = parts[0];
4343
switch (token) {
44-
case Token.TestName: if (string.IsNullOrWhiteSpace(report.TestName)) report.TestName = data[0]; break;
45-
case Token.SourceFile: sourceFile = new(data[0]) { Branches = new(), Functions = new(), Lines = new() }; break;
46-
case Token.EndOfRecord: report.SourceFiles.Add(sourceFile); break;
44+
case Tokens.TestName: if (string.IsNullOrWhiteSpace(report.TestName)) report.TestName = data[0]; break;
45+
case Tokens.SourceFile: sourceFile = new(data[0]) { Branches = new(), Functions = new(), Lines = new() }; break;
46+
case Tokens.EndOfRecord: report.SourceFiles.Add(sourceFile); break;
4747

48-
case Token.BranchData:
48+
case Tokens.BranchData:
4949
if (data.Length < 4) throw new FormatException($"Invalid branch data at line #{offset}.");
5050
sourceFile.Branches?.Data.Add(new() {
5151
BlockNumber = int.Parse(data[1]),
@@ -55,7 +55,7 @@ public static Report Parse(string coverage) {
5555
});
5656
break;
5757

58-
case Token.FunctionData:
58+
case Tokens.FunctionData:
5959
if (data.Length < 2) throw new FormatException($"Invalid function data at line #{offset}.");
6060
if (sourceFile.Functions is not null) {
6161
var items = sourceFile.Functions.Data;
@@ -66,12 +66,12 @@ public static Report Parse(string coverage) {
6666
}
6767
break;
6868

69-
case Token.FunctionName:
69+
case Tokens.FunctionName:
7070
if (data.Length < 2) throw new FormatException($"Invalid function name at line #{offset}.");
7171
sourceFile.Functions?.Data.Add(new() { FunctionName = data[1], LineNumber = int.Parse(data[0]) });
7272
break;
7373

74-
case Token.LineData:
74+
case Tokens.LineData:
7575
if (data.Length < 2) throw new FormatException($"Invalid line data at line #{offset}.");
7676
sourceFile.Lines?.Data.Add(new() {
7777
Checksum = data.Length >= 3 ? data[2] : string.Empty,
@@ -80,12 +80,12 @@ public static Report Parse(string coverage) {
8080
});
8181
break;
8282

83-
case Token.BranchesFound when sourceFile.Branches is not null: sourceFile.Branches.Found = int.Parse(data[0]); break;
84-
case Token.BranchesHit when sourceFile.Branches is not null: sourceFile.Branches.Hit = int.Parse(data[0]); break;
85-
case Token.FunctionsFound when sourceFile.Functions is not null: sourceFile.Functions.Found = int.Parse(data[0]); break;
86-
case Token.FunctionsHit when sourceFile.Functions is not null: sourceFile.Functions.Hit = int.Parse(data[0]); break;
87-
case Token.LinesFound when sourceFile.Lines is not null: sourceFile.Lines.Found = int.Parse(data[0]); break;
88-
case Token.LinesHit when sourceFile.Lines is not null: sourceFile.Lines.Hit = int.Parse(data[0]); break;
83+
case Tokens.BranchesFound when sourceFile.Branches is not null: sourceFile.Branches.Found = int.Parse(data[0]); break;
84+
case Tokens.BranchesHit when sourceFile.Branches is not null: sourceFile.Branches.Hit = int.Parse(data[0]); break;
85+
case Tokens.FunctionsFound when sourceFile.Functions is not null: sourceFile.Functions.Found = int.Parse(data[0]); break;
86+
case Tokens.FunctionsHit when sourceFile.Functions is not null: sourceFile.Functions.Hit = int.Parse(data[0]); break;
87+
case Tokens.LinesFound when sourceFile.Lines is not null: sourceFile.Lines.Found = int.Parse(data[0]); break;
88+
case Tokens.LinesHit when sourceFile.Lines is not null: sourceFile.Lines.Hit = int.Parse(data[0]); break;
8989
default: throw new FormatException($"Unknown token at line {offset}.");
9090
}
9191
}
@@ -115,7 +115,7 @@ public static bool TryParse(string coverage, [NotNullWhen(true)] out Report? rep
115115
/// </summary>
116116
/// <returns>The string representation of this object.</returns>
117117
public override string ToString() => string.Join('\n', [
118-
.. string.IsNullOrWhiteSpace(TestName) ? Array.Empty<string>() : [$"{Token.TestName}:{TestName}"],
118+
.. string.IsNullOrWhiteSpace(TestName) ? Array.Empty<string>() : [$"{Tokens.TestName}:{TestName}"],
119119
.. SourceFiles.Select(item => item.ToString())
120120
]);
121121
}

src/SourceFile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public sealed class SourceFile(string path, FunctionCoverage? functions = null,
3434
/// </summary>
3535
/// <returns>The string representation of this object.</returns>
3636
public override string ToString() {
37-
List<string> output = [$"{Token.SourceFile}:{Path}"];
37+
List<string> output = [$"{Tokens.SourceFile}:{Path}"];
3838
if (Functions is not null) output.Add(Functions.ToString());
3939
if (Branches is not null) output.Add(Branches.ToString());
4040
if (Lines is not null) output.Add(Lines.ToString());
41-
output.Add(Token.EndOfRecord);
41+
output.Add(Tokens.EndOfRecord);
4242
return string.Join('\n', output);
4343
}
4444
}

src/Token.cs renamed to src/Tokens.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace Belin.Lcov;
33
/// <summary>
44
/// Provides the list of tokens supported by the parser.
55
/// </summary>
6-
public static class Token {
6+
public static class Tokens {
77

88
/// <summary>
99
/// The coverage data of a branch.

0 commit comments

Comments
 (0)