< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Utilities.RegexUtils
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Utilities/RegexUtils.cs
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
100%
Covered lines: 5
Uncovered lines: 0
Coverable lines: 5
Total lines: 25
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IsGlobMatch(...)100%22100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Utilities/RegexUtils.cs

#LineLine coverage
 1using System.Text.RegularExpressions;
 2
 3namespace Kestrun.Utilities;
 4
 5internal static class RegexUtils
 6{
 7    /// <summary>
 8    /// Checks if the input string matches the glob pattern.
 9    /// The pattern can contain '*' for any sequence of characters and '?' for a single character.
 10    /// </summary>
 11    /// <param name="input">The input string to match against the pattern.</param>
 12    /// <param name="pattern">The glob pattern to match.</param>
 13    /// <param name="ignoreCase">Whether to ignore case when matching.</param>
 14    /// <returns>True if the input matches the pattern, otherwise false.</returns>
 15    public static bool IsGlobMatch(string input, string pattern, bool ignoreCase = true)
 16    {
 17        // Escape regex metacharacters then bring back * and ?
 1218        var re = "^" + Regex.Escape(pattern)
 1219                            .Replace(@"\*", ".*")
 1220                            .Replace(@"\?", ".") + "$";
 21
 1222        var flags = ignoreCase ? RegexOptions.IgnoreCase : RegexOptions.None;
 1223        return Regex.IsMatch(input, re, flags);
 24    }
 25}