< Summary - Kestrun — Combined Coverage

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

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 08/26/2025 - 01:25:22 Line coverage: 100% (9/9) Branch coverage: 100% (8/8) Total lines: 39 Tag: Kestrun/Kestrun@07f821172e5dc3657f1be7e6818f18d6721cf38a 08/26/2025 - 01:25:22 Line coverage: 100% (9/9) Branch coverage: 100% (8/8) Total lines: 39 Tag: Kestrun/Kestrun@07f821172e5dc3657f1be7e6818f18d6721cf38a

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
PreviewFeaturesEnabled()100%11100%
GetLineNumber(...)100%88100%

File(s)

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

#LineLine coverage
 1namespace Kestrun.Utilities;
 2/// <summary>
 3/// Provides utility methods for Kestrun.
 4/// </summary>
 5public static class CcUtilities
 6{
 7    /// <summary>
 8    /// Determines whether preview features are enabled in the current AppContext.
 9    /// </summary>
 10    public static bool PreviewFeaturesEnabled() =>
 611        AppContext.TryGetSwitch(
 612            "System.Runtime.EnablePreviewFeatures", out var on) && on;
 13
 14    /// <summary>
 15    /// Returns the line number in the source string at the specified character index.
 16    /// </summary>
 17    /// <param name="source">The source string to search.</param>
 18    /// <param name="index">The character index for which to find the line number.</param>
 19    /// <returns>The line number at the specified index.</returns>
 20    /// <exception cref="ArgumentOutOfRangeException">Thrown when index is out of range.</exception>
 21    public static int GetLineNumber(string source, int index)
 22    {
 2023        if (index < 0 || index > source.Length)
 24        {
 225            throw new ArgumentOutOfRangeException(nameof(index));
 26        }
 27
 28        // Count how many `\n` occur before the index
 1829        var line = 1;
 1587830        for (var i = 0; i < index; i++)
 31        {
 792132            if (source[i] == '\n')
 33            {
 21034                line++;
 35            }
 36        }
 1837        return line;
 38    }
 39}