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

loresoft / EntityFrameworkCore.Generator / 27730465225

18 Jun 2026 01:21AM UTC coverage: 74.693% (+19.8%) from 54.885%
27730465225

push

github

pwelter34
update tests

922 of 1609 branches covered (57.3%)

Branch coverage included in aggregate %.

7 of 7 new or added lines in 2 files covered. (100.0%)

230 existing lines in 23 files now uncovered.

4007 of 4990 relevant lines covered (80.3%)

1258.69 hits per line

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

41.27
/src/EntityFrameworkCore.Generator.Core/Extensions/StringExtensions.cs
1
using System.Diagnostics.CodeAnalysis;
2
using System.Runtime.CompilerServices;
3
using System.Text;
4
using System.Text.RegularExpressions;
5

6
namespace EntityFrameworkCore.Generator.Extensions;
7

8
public static partial class StringExtensions
9
{
10
    [GeneratedRegex("([A-Z][a-z]*)|([0-9]+)", RegexOptions.ExplicitCapture, matchTimeoutMilliseconds: 1000)]
11
    private static partial Regex WordsExpression();
12

13
    private static readonly Regex _splitNameRegex = new Regex(@"[\W_]+");
5✔
14

15
    /// <summary>
16
    /// Truncates the specified text.
17
    /// </summary>
18
    /// <param name="text">The text to truncate.</param>
19
    /// <param name="keep">The number of characters to keep.</param>
20
    /// <param name="ellipsis">The ellipsis string to use when truncating. (Default ...)</param>
21
    /// <returns>
22
    /// A truncate string.
23
    /// </returns>
24
    [return: NotNullIfNotNull(nameof(text))]
25
    public static string? Truncate(this string? text, int keep, string ellipsis = "...")
26
    {
UNCOV
27
        if (string.IsNullOrEmpty(text))
×
UNCOV
28
            return text;
×
29

30
        if (text!.Length <= keep)
×
UNCOV
31
            return text;
×
32

33
        ellipsis ??= string.Empty;
×
34

35
        if (text.Length <= keep + ellipsis.Length || keep < ellipsis.Length)
×
UNCOV
36
            return text[..keep];
×
37

38
        int prefix = keep - ellipsis.Length;
×
UNCOV
39
        return string.Concat(text[..prefix], ellipsis);
×
40
    }
41

42
    /// <summary>
43
    /// Indicates whether the specified String object is null or an empty string
44
    /// </summary>
45
    /// <param name="item">A String reference</param>
46
    /// <returns>
47
    ///     <see langword="true"/> if is null or empty; otherwise, <see langword="false"/>.
48
    /// </returns>
49
    public static bool IsNullOrEmpty([NotNullWhen(false)] this string? item)
50
    {
51
        return string.IsNullOrEmpty(item);
6,276✔
52
    }
53

54
    /// <summary>
55
    /// Indicates whether a specified string is null, empty, or consists only of white-space characters
56
    /// </summary>
57
    /// <param name="item">A String reference</param>
58
    /// <returns>
59
    ///      <see langword="true"/> if is null or empty; otherwise, <see langword="false"/>.
60
    /// </returns>
61
    public static bool IsNullOrWhiteSpace([NotNullWhen(false)] this string? item)
62
    {
63
        if (item == null)
79,470!
UNCOV
64
            return true;
×
65

66
        for (int i = 0; i < item.Length; i++)
158,940✔
67
        {
68
            if (!char.IsWhiteSpace(item[i]))
79,469!
69
                return false;
79,469✔
70
        }
71

72
        return true;
1✔
73
    }
74

75
    /// <summary>
76
    /// Determines whether the specified string is not <see cref="IsNullOrEmpty"/>.
77
    /// </summary>
78
    /// <param name="value">The value to check.</param>
79
    /// <returns>
80
    ///   <see langword="true"/> if the specified <paramref name="value"/> is not <see cref="IsNullOrEmpty"/>; otherwise, <see langword="false"/>.
81
    /// </returns>
82
    public static bool HasValue([NotNullWhen(true)] this string? value)
83
    {
84
        return !string.IsNullOrEmpty(value);
68,156✔
85
    }
86

87
    /// <summary>
88
    /// Does string contain both uppercase and lowercase characters?
89
    /// </summary>
90
    /// <param name="s">The value.</param>
91
    /// <returns>True if contain mixed case.</returns>
92
    public static bool IsMixedCase(this string s)
93
    {
94
        if (s.IsNullOrEmpty())
4,539!
UNCOV
95
            return false;
×
96

97
        var containsUpper = s.Any(Char.IsUpper);
4,539✔
98
        var containsLower = s.Any(Char.IsLower);
4,539✔
99

100
        return containsLower && containsUpper;
4,539✔
101
    }
102

103
    /// <summary>
104
    /// Converts a string to use camelCase.
105
    /// </summary>
106
    /// <param name="value">The value.</param>
107
    /// <returns>The to camel case. </returns>
108
    public static string ToCamelCase(this string value)
109
    {
110
        if (string.IsNullOrEmpty(value))
1,477!
UNCOV
111
            return value;
×
112

113
        string output = ToPascalCase(value);
1,477✔
114
        if (output.Length > 2)
1,477✔
115
            return char.ToLower(output[0]) + output[1..];
1,013✔
116

117
        return output.ToLower();
464✔
118
    }
119

120
    /// <summary>
121
    /// Converts a string to use PascalCase.
122
    /// </summary>
123
    /// <param name="value">Text to convert</param>
124
    /// <returns>The string</returns>
125
    public static string ToPascalCase(this string value)
126
    {
127
        return value.ToPascalCase(_splitNameRegex);
4,539✔
128
    }
129

130
    /// <summary>
131
    /// Converts a string to use PascalCase.
132
    /// </summary>
133
    /// <param name="value">Text to convert</param>
134
    /// <param name="splitRegex">Regular Expression to split words on.</param>
135
    /// <returns>The string</returns>
136
    public static string ToPascalCase(this string value, Regex splitRegex)
137
    {
138
        if (string.IsNullOrEmpty(value))
4,539!
UNCOV
139
            return value;
×
140

141
        var mixedCase = value.IsMixedCase();
4,539✔
142
        var names = splitRegex.Split(value);
4,539✔
143
        var output = new StringBuilder();
4,539✔
144

145
        if (names.Length > 1)
4,539✔
146
        {
147
            foreach (string name in names)
490✔
148
            {
149
                if (name.Length > 1)
166✔
150
                {
151
                    output.Append(char.ToUpper(name[0]));
158✔
152
                    output.Append(mixedCase ? name[1..] : name[1..].ToLower());
158✔
153
                }
154
                else
155
                {
156
                    output.Append(name.ToUpper());
8✔
157
                }
158
            }
159
        }
160
        else if (value.Length > 1)
4,460!
161
        {
162
            output.Append(char.ToUpper(value[0]));
4,460✔
163
            output.Append(mixedCase ? value[1..] : value[1..].ToLower());
4,460✔
164
        }
165
        else
166
        {
UNCOV
167
            output.Append(value.ToUpper());
×
168
        }
169

170
        return output.ToString();
4,539✔
171
    }
172

173
    /// <summary>
174
    /// Combines two strings with the specified separator.
175
    /// </summary>
176
    /// <param name="first">The first string.</param>
177
    /// <param name="second">The second string.</param>
178
    /// <param name="separator">The separator string.</param>
179
    /// <returns>A string combining the <paramref name="first"/> and <paramref name="second"/> parameters with the <paramref name="separator"/> between them</returns>
180
    [return: NotNullIfNotNull(nameof(first))]
181
    [return: NotNullIfNotNull(nameof(second))]
182
    public static string? Combine(this string? first, string? second, char separator = '/')
183
    {
UNCOV
184
        if (string.IsNullOrEmpty(first))
×
UNCOV
185
            return second;
×
186

187
        if (string.IsNullOrEmpty(second))
×
UNCOV
188
            return first;
×
189

190
        var firstEndsWith = first[^1] == separator;
×
UNCOV
191
        var secondStartsWith = second[0] == separator;
×
192

193
        if (firstEndsWith && !secondStartsWith)
×
UNCOV
194
            return string.Concat(first, second);
×
195

196
        if (!firstEndsWith && secondStartsWith)
×
UNCOV
197
            return string.Concat(first, second);
×
198

199
        if (firstEndsWith && secondStartsWith)
×
UNCOV
200
            return string.Concat(first, second[1..]);
×
201

202
        return $"{first}{separator}{second}";
×
203
    }
204

205
    /// <summary>
206
    /// Converts a NameIdentifier and spaces it out into words "Name Identifier".
207
    /// </summary>
208
    /// <param name="text">The text value to convert.</param>
209
    /// <returns>The text converted</returns>
210
    [return: NotNullIfNotNull(nameof(text))]
211
    public static string? ToTitle(this string? text)
212
    {
UNCOV
213
        if (text.IsNullOrEmpty() || text.Length < 2)
×
UNCOV
214
            return text;
×
215

216
        var words = WordsExpression().Matches(text);
×
217

218
        var wrote = false;
×
UNCOV
219
        var builder = new DefaultInterpolatedStringHandler(literalLength: text.Length + 5, formattedCount: 1);
×
220
        foreach (Match word in words)
×
221
        {
222
            if (wrote)
×
UNCOV
223
                builder.AppendLiteral(" ");
×
224

225
            builder.AppendLiteral(word.Value);
×
UNCOV
226
            wrote = true;
×
227
        }
228

UNCOV
229
        return builder.ToStringAndClear();
×
230
    }
231
}
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