• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / FluentCommand / 29258656563

13 Jul 2026 02:36PM UTC coverage: 65.856% (+0.2%) from 65.698%
29258656563

push

github

pwelter34
Add JsonElement converter support

1872 of 3634 branches covered (51.51%)

Branch coverage included in aggregate %.

17 of 28 new or added lines in 3 files covered. (60.71%)

14 existing lines in 2 files now uncovered.

5741 of 7926 relevant lines covered (72.43%)

298.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.75
/src/FluentCommand/Extensions/StringBuilderExtensions.cs
1
using System.Diagnostics.CodeAnalysis;
2
using System.Text;
3

4
namespace FluentCommand.Extensions;
5

6
/// <summary>
7
/// <see cref="StringBuilder"/> extension methods
8
/// </summary>
9
public static class StringBuilderExtensions
10
{
11
    /// <summary>
12
    /// Appends a copy of the specified string followed by the default line terminator to the end of the StringBuilder object.
13
    /// </summary>
14
    /// <param name="sb">The StringBuilder instance to append to.</param>
15
    /// <param name="format">A composite format string.</param>
16
    /// <param name="args">An object array that contains zero or more objects to format.</param>
17
    public static StringBuilder AppendLine(this StringBuilder sb, [StringSyntax("CompositeFormat")] string format, params object[] args)
18
    {
19
        ArgumentNullException.ThrowIfNull(sb);
×
20

21
        sb.AppendFormat(format, args);
×
UNCOV
22
        sb.AppendLine();
×
UNCOV
23
        return sb;
×
24
    }
25

26
    /// <summary>
27
    /// Appends a copy of the specified string if <paramref name="condition"/> is met.
28
    /// </summary>
29
    /// <param name="sb">The StringBuilder instance to append to.</param>
30
    /// <param name="text">The string to append.</param>
31
    /// <param name="condition">The condition delegate to evaluate. If condition is null, String.IsNullOrEmpty method will be used.</param>
32
    public static StringBuilder AppendIf(this StringBuilder sb, string text, Func<string, bool>? condition = null)
33
    {
34
        ArgumentNullException.ThrowIfNull(sb);
2,499✔
35

36
        var c = condition ?? (s => !string.IsNullOrEmpty(s));
2,499!
37

38
        if (c(text))
2,499✔
39
            sb.Append(text);
2,088✔
40

41
        return sb;
2,499✔
42
    }
43

44
    /// <summary>
45
    /// Appends a copy of the specified string if <paramref name="condition"/> is met.
46
    /// </summary>
47
    /// <param name="sb">The StringBuilder instance to append to.</param>
48
    /// <param name="text">The string to append.</param>
49
    /// <param name="condition">The condition delegate to evaluate.</param>
50
    public static StringBuilder AppendIf(this StringBuilder sb, string text, bool condition)
51
    {
UNCOV
52
        ArgumentNullException.ThrowIfNull(sb);
×
53

UNCOV
54
        if (condition)
×
UNCOV
55
            sb.Append(text);
×
56

UNCOV
57
        return sb;
×
58
    }
59

60
    /// <summary>
61
    /// Appends a copy of the specified string followed by the default line terminator if <paramref name="condition"/> is met.
62
    /// </summary>
63
    /// <param name="sb">The StringBuilder instance to append to.</param>
64
    /// <param name="text">The string to append.</param>
65
    /// <param name="condition">The condition delegate to evaluate. If condition is null, String.IsNullOrEmpty method will be used.</param>
66
    public static StringBuilder AppendLineIf(this StringBuilder sb, string text, Func<string, bool>? condition = null)
67
    {
68
        ArgumentNullException.ThrowIfNull(sb);
842✔
69

70
        var c = condition ?? (s => !string.IsNullOrEmpty(s));
842!
71

72
        if (c(text))
842✔
73
            sb.AppendLine(text);
768✔
74

75
        return sb;
842✔
76
    }
77

78
    /// <summary>
79
    /// Appends a copy of the specified string followed by the default line terminator if <paramref name="condition"/> is met.
80
    /// </summary>
81
    /// <param name="sb">The StringBuilder instance to append to.</param>
82
    /// <param name="condition">The condition delegate to evaluate.</param>
83
    public static StringBuilder AppendLineIf(this StringBuilder sb, Func<bool> condition)
84
    {
UNCOV
85
        ArgumentNullException.ThrowIfNull(sb);
×
86

UNCOV
87
        if (condition())
×
UNCOV
88
            sb.AppendLine();
×
89

UNCOV
90
        return sb;
×
91
    }
92

93
    /// <summary>
94
    /// Appends a copy of the specified string truncated to the specified maximum length, using an ellipsis when truncated.
95
    /// </summary>
96
    /// <param name="sb">The StringBuilder instance to append to.</param>
97
    /// <param name="text">The string to append.</param>
98
    /// <param name="maxLength">The maximum number of characters to append.</param>
99
    /// <param name="ellipsis">The string to append when the value is truncated.</param>
100
    public static StringBuilder AppendTruncated(this StringBuilder sb, string? text, int maxLength, string? ellipsis = "...")
101
    {
102
        ArgumentNullException.ThrowIfNull(sb);
573✔
103

104
        if (text == null)
573!
UNCOV
105
            return sb;
×
106

107
        ArgumentOutOfRangeException.ThrowIfLessThan(maxLength, 0);
573✔
108

109
        if (text.Length <= maxLength)
573✔
110
        {
111
            sb.Append(text);
567✔
112
            return sb;
567✔
113
        }
114

115
        if (maxLength == 0)
6!
UNCOV
116
            return sb;
×
117

118
        if (string.IsNullOrEmpty(ellipsis))
6✔
119
        {
120
            sb.Append(text, 0, maxLength);
1✔
121
            return sb;
1✔
122
        }
123

124
        var truncationSuffix = ellipsis ?? string.Empty;
5!
125

126
        if (truncationSuffix.Length >= maxLength)
5✔
127
        {
128
            sb.Append(truncationSuffix, 0, maxLength);
1✔
129
            return sb;
1✔
130
        }
131

132
        sb.Append(text, 0, maxLength - truncationSuffix.Length);
4✔
133
        sb.Append(truncationSuffix);
4✔
134

135
        return sb;
4✔
136
    }
137

138
    /// <summary>
139
    /// Appends a string representation of the specified value truncated to the specified maximum length, using an ellipsis when truncated.
140
    /// </summary>
141
    /// <param name="sb">The StringBuilder instance to append to.</param>
142
    /// <param name="value">The value to append.</param>
143
    /// <param name="maxLength">The maximum number of characters to append.</param>
144
    /// <param name="ellipsis">The string to append when the value is truncated.</param>
145
    public static StringBuilder AppendTruncated(this StringBuilder sb, object? value, int maxLength, string? ellipsis = "...")
146
    {
147
        ArgumentNullException.ThrowIfNull(sb);
573✔
148

149
        if (value == null)
573✔
150
            return sb;
4✔
151

152
        ArgumentOutOfRangeException.ThrowIfLessThan(maxLength, 0);
569✔
153

154
        if (maxLength == 0)
569!
UNCOV
155
            return sb;
×
156

157
        return value is string text
569✔
158
            ? AppendTruncated(sb, text, maxLength, ellipsis)
569✔
159
            : AppendTruncated(sb, value.ToString(), maxLength, ellipsis);
569✔
160
    }
161
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc