src/SSC/Internal/ParallelDiffPathFormatter.cs

実行済み 31 · 未実行 6 · 対象外 72
Coverage source: 043e27b9e5febd713c747d2558802e450fad8edd

実行済みCoberturaのhit数が1以上の行です。
未実行カバレッジ対象ですがhit数が0の行です。
対象外Coberturaに実行対象として記録されていない行です。
行状態HitsSource
1 対象外 using System.Globalization;
2 対象外 using System.Text;
3 対象外
4 対象外 namespace SSC.Internal;
5 対象外
6 対象外 /// <summary>
7 対象外 /// 標準差分 path と利用側定義 path を共通の grammar で文字列化します。
8 対象外 /// </summary>
9 対象外 internal static class ParallelDiffPathFormatter
10 対象外 {
11 対象外 /// <summary>
12 対象外 /// すべての segment を連結して path 文字列を生成します。
13 対象外 /// </summary>
14 対象外 /// <param name="segments">文字列化する segment。</param>
15 対象外 /// <returns>生成した path 文字列。</returns>
16 対象外 public static string Format(IReadOnlyList<ParallelDiffPathSegment> segments)
17 対象外 {
18 実行済み 108 ArgumentNullException.ThrowIfNull(segments);
19 実行済み 108 return Format(segments, segments.Count);
20 対象外 }
21 対象外
22 対象外 /// <summary>
23 対象外 /// 先頭から指定件数の segment を連結して path 文字列を生成します。
24 対象外 /// </summary>
25 対象外 /// <param name="segments">文字列化する segment。</param>
26 対象外 /// <param name="count">文字列化する先頭 segment の件数。</param>
27 対象外 /// <returns>生成した path 文字列。</returns>
28 対象外 public static string Format(
29 対象外 IReadOnlyList<ParallelDiffPathSegment> segments,
30 対象外 int count)
31 対象外 {
32 実行済み 189 ArgumentNullException.ThrowIfNull(segments);
33 実行済み 189 if (count < 0 || count > segments.Count)
34 対象外 {
35 未実行 0 throw new ArgumentOutOfRangeException(nameof(count));
36 対象外 }
37 対象外
38 実行済み 189 if (count == 0)
39 対象外 {
40 未実行 0 return string.Empty;
41 対象外 }
42 対象外
43 実行済み 189 var builder = new StringBuilder();
44 実行済み 1052 for (var index = 0; index < count; index++)
45 対象外 {
46 実行済み 337 if (index > 0)
47 対象外 {
48 実行済み 148 builder.Append('.');
49 対象外 }
50 対象外
51 実行済み 337 AppendSegment(builder, segments[index]);
52 対象外 }
53 対象外
54 実行済み 189 return builder.ToString();
55 対象外 }
56 対象外
57 対象外 private static void AppendSegment(
58 対象外 StringBuilder builder,
59 対象外 ParallelDiffPathSegment segment)
60 対象外 {
61 実行済み 337 ArgumentNullException.ThrowIfNull(segment);
62 実行済み 337 builder.Append(segment.MemberName);
63 対象外
64 実行済み 337 if (segment.Selector is not ParallelDiffPathSelector selector)
65 対象外 {
66 実行済み 140 return;
67 対象外 }
68 対象外
69 実行済み 197 builder.Append('[');
70 実行済み 197 switch (selector.Kind)
71 対象外 {
72 対象外 case ParallelDiffPathSelectorKind.Key:
73 実行済み 195 if (selector.KeyText is null)
74 対象外 {
75 未実行 0 throw new InvalidOperationException("Key selector must contain key text.");
76 対象外 }
77 対象外
78 実行済み 195 builder.Append(EscapeKeyText(selector.KeyText));
79 実行済み 195 break;
80 対象外 case ParallelDiffPathSelectorKind.Ordinal:
81 実行済み 2 if (selector.Ordinal is not int ordinal)
82 対象外 {
83 未実行 0 throw new InvalidOperationException("Ordinal selector must contain an ordinal.");
84 対象外 }
85 対象外
86 実行済み 2 builder.Append('#');
87 実行済み 2 builder.Append(ordinal.ToString(CultureInfo.InvariantCulture));
88 実行済み 2 break;
89 対象外 default:
90 未実行 0 throw new InvalidOperationException(
91 未実行 0 $"Unknown diff path selector kind '{selector.Kind}'.");
92 対象外 }
93 対象外
94 実行済み 197 builder.Append(']');
95 実行済み 197 }
96 対象外
97 対象外 private static string EscapeKeyText(string keyText)
98 対象外 {
99 実行済み 195 var escaped = keyText.Replace("\\", "\\\\", StringComparison.Ordinal)
100 実行済み 195 .Replace("]", "\\]", StringComparison.Ordinal);
101 対象外
102 実行済み 195 if (escaped.Length > 0 && escaped[0] == '#')
103 対象外 {
104 実行済み 6 return $"\\{escaped}";
105 対象外 }
106 対象外
107 実行済み 189 return escaped;
108 対象外 }
109 対象外 }