< 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@9d3a582b2d63930269564a7591aa77ef297cadeb
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

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    {
 1723        if (index < 0 || index > source.Length)
 24        {
 225            throw new ArgumentOutOfRangeException(nameof(index));
 26        }
 27
 28        // Count how many `\n` occur before the index
 1529        var line = 1;
 1271630        for (var i = 0; i < index; i++)
 31        {
 634332            if (source[i] == '\n')
 33            {
 16534                line++;
 35            }
 36        }
 1537        return line;
 38    }
 39}