< Summary - Kestrun — Combined Coverage

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetYamlDocuments(...)100%22100%
GetRootNodes(...)100%11100%
DeserializeToObjects(...)100%22100%

File(s)

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

#LineLine coverage
 1using YamlDotNet.Core;
 2using YamlDotNet.RepresentationModel;
 3
 4namespace Kestrun.Utilities.Yaml;
 5
 6/// <summary>
 7/// Utility class for loading and parsing YAML documents
 8/// </summary>
 9public static class YamlLoader
 10{
 11    /// <summary>
 12    /// Parses one or more YAML documents from a string and returns a YamlStream.
 13    /// Set <paramref name="useMergingParser"/> to true to enable YAML anchors/aliases mergehandling.
 14    /// </summary>
 15    /// <param name="yaml">The YAML string to parse.</param>
 16    /// <param name="useMergingParser">Whether to use a merging parser to handle anchors and aliases.</param>
 17    /// <returns>A YamlStream containing the parsed documents.</returns>
 18    /// <exception cref="ArgumentNullException">Thrown if the input YAML string is null.</exception>
 19    public static YamlStream GetYamlDocuments(string yaml, bool useMergingParser = false)
 20    {
 321        ArgumentNullException.ThrowIfNull(yaml);
 22
 323        using var reader = new StringReader(yaml);
 24
 325        IParser parser = new Parser(reader);          // YamlDotNet.Core.Parser
 326        if (useMergingParser)
 27        {
 28            // YamlDotNet.Core.MergingParser wraps an existing parser
 129            parser = new MergingParser(parser);
 30        }
 31
 332        var stream = new YamlStream();                // YamlDotNet.RepresentationModel.YamlStream
 333        stream.Load(parser);                          // parse the stream (may contain multiple docs)
 334        return stream;
 335    }
 36
 37    /// <summary>
 38    /// Convenience: returns each document's root node from a yaml string.
 39    /// </summary>
 40    public static IReadOnlyList<YamlNode> GetRootNodes(string yaml, bool useMergingParser = false)
 41    {
 242        var ys = GetYamlDocuments(yaml, useMergingParser);
 543        return [.. ys.Documents.Select(d => d.RootNode)];
 44    }
 45
 46    /// <summary>
 47    /// Convenience: fully convert to .NET objects using your converter (mapping→dict, seq→array, scalar→typed).
 48    /// </summary>
 49    public static IReadOnlyList<object?> DeserializeToObjects(string yaml, bool useMergingParser = false)
 50    {
 151        var ys = GetYamlDocuments(yaml, useMergingParser);
 152        var result = new List<object?>(ys.Documents.Count);
 453        foreach (var doc in ys.Documents)
 54        {
 155            result.Add(YamlTypeConverter.ConvertYamlDocumentToPSObject(doc.RootNode, ordered: false));
 56        }
 157        return result;
 58    }
 59}