< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Sse.SseEventFormatter
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Sse/SseEventFormatter.cs
Tag: Kestrun/Kestrun@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 58
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 01/12/2026 - 18:03:06 Line coverage: 0% (0/14) Branch coverage: 0% (0/8) Total lines: 58 Tag: Kestrun/Kestrun@956332ccc921363590dccd99d5707fb20b50966b01/16/2026 - 03:52:31 Line coverage: 100% (14/14) Branch coverage: 100% (8/8) Total lines: 58 Tag: Kestrun/Kestrun@0077556dd757d1b7434cf700cd5c7be05cea3514 01/12/2026 - 18:03:06 Line coverage: 0% (0/14) Branch coverage: 0% (0/8) Total lines: 58 Tag: Kestrun/Kestrun@956332ccc921363590dccd99d5707fb20b50966b01/16/2026 - 03:52:31 Line coverage: 100% (14/14) Branch coverage: 100% (8/8) Total lines: 58 Tag: Kestrun/Kestrun@0077556dd757d1b7434cf700cd5c7be05cea3514

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Format(...)100%88100%
FormatComment(...)100%11100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Sse/SseEventFormatter.cs

#LineLine coverage
 1using System.Text;
 2
 3namespace Kestrun.Sse;
 4
 5/// <summary>
 6/// Formats Server-Sent Events (SSE) payloads according to the SSE wire format.
 7/// </summary>
 8public static class SseEventFormatter
 9{
 10    /// <summary>
 11    /// Formats a single SSE event payload.
 12    /// </summary>
 13    /// <param name="eventName">Optional event name.</param>
 14    /// <param name="data">Event payload data (may be multi-line).</param>
 15    /// <param name="id">Optional event ID.</param>
 16    /// <param name="retryMs">Optional reconnect interval in milliseconds.</param>
 17    /// <returns>A formatted SSE payload string.</returns>
 18    public static string Format(string? eventName, string data, string? id = null, int? retryMs = null)
 19    {
 720        var sb = new StringBuilder(capacity: Math.Max(64, data.Length + 32));
 21
 722        if (retryMs is not null)
 23        {
 324            _ = sb.Append("retry: ").Append(retryMs.Value).Append('\n');
 25        }
 26
 727        if (!string.IsNullOrWhiteSpace(id))
 28        {
 329            _ = sb.Append("id: ").Append(id).Append('\n');
 30        }
 31
 732        if (!string.IsNullOrWhiteSpace(eventName))
 33        {
 534            _ = sb.Append("event: ").Append(eventName).Append('\n');
 35        }
 36
 737        using (var sr = new StringReader(data))
 38        {
 39            string? line;
 1540            while ((line = sr.ReadLine()) is not null)
 41            {
 842                _ = sb.Append("data: ").Append(line).Append('\n');
 43            }
 744        }
 45
 746        _ = sb.Append('\n');
 747        return sb.ToString();
 48    }
 49
 50    /// <summary>
 51    /// Formats an SSE comment payload (useful for keep-alives).
 52    /// </summary>
 53    /// <param name="comment">Comment text.</param>
 54    /// <returns>A formatted SSE comment payload string.</returns>
 55    public static string FormatComment(string comment) =>
 56        // Comment lines start with ':'
 157        $": {comment}\n\n";
 58}