< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Utilities.Yaml.YamlHelper
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Utilities/Yaml/YamlHelper.cs
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
100%
Covered lines: 5
Uncovered lines: 0
Coverable lines: 5
Total lines: 35
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 10/13/2025 - 16:52:37 Line coverage: 100% (5/5) Branch coverage: 100% (2/2) Total lines: 35 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e 10/13/2025 - 16:52:37 Line coverage: 100% (5/5) Branch coverage: 100% (2/2) Total lines: 35 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e

Metrics

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

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Utilities/Yaml/YamlHelper.cs

#LineLine coverage
 1using System.Text.RegularExpressions;
 2
 3namespace Kestrun.Utilities.Yaml;
 4
 5/// <summary>
 6/// Provides helper methods for serializing and deserializing YAML content, with special handling for PowerShell objects
 7/// </summary>
 8public static partial class YamlHelper
 9{
 10    /// <summary>
 11    /// Serializes any PowerShell object to YAML format, with specified serialization options.
 12    /// </summary>
 13    /// <param name="input">The PowerShell object to serialize. Can be null.</param>
 14    /// <param name="options">The serialization options to apply.</param>
 15    /// <returns>A string containing the YAML representation of the input object.</returns>
 16    public static string ToYaml(object? input, SerializationOptions? options = null)
 17    {
 1618        var wrt = new StringWriter();
 19        // Default options intentionally omit Roundtrip to allow serialization of anonymous types
 20        // without requiring default constructors (Roundtrip enforces reconstructable object graphs).
 1621        options ??= SerializationOptions.DisableAliases | SerializationOptions.EmitDefaults | SerializationOptions.WithI
 1622        var serializer = YamlSerializerFactory.GetSerializer(options.Value);
 23
 1624        serializer.Serialize(wrt, input);
 25        // Post-process: convert null dictionary entries serialized as '' into blank null form (key: \n)
 26        // Safe regex: only targets single-quoted empty string immediately after colon with optional space.
 1627        return MyRegex().Replace(wrt.ToString(), "${k}:");
 28    }
 29
 30    // This regex matches dictionary entries in YAML that have a key followed by a colon and a single-quoted empty strin
 31    // It captures the key name in the named group 'k'. The replacement string "${k}:" rewrites such entries to the blan
 32    // which is the preferred YAML representation for null values. This post-processing step ensures that null dictionar
 33    [GeneratedRegex(@"^(?<k>[^:\r\n]+):\s*''\s*$", RegexOptions.Multiline)]
 34    private static partial Regex MyRegex();
 35}