< Summary - Kestrun — Combined Coverage

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.cctor()100%11100%
Emit(...)65.38%662661.11%

File(s)

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

#LineLine coverage
 1using System.Text.RegularExpressions;
 2using YamlDotNet.Core;
 3using YamlDotNet.Serialization;
 4using YamlDotNet.Serialization.EventEmitters;
 5
 6namespace Kestrun.Utilities.Yaml;
 7
 8/// <summary>
 9/// YAML emitter that quotes strings that might be misinterpreted as other types
 10/// </summary>
 11/// <param name="next">The next event emitter in the chain</param>
 2112public partial class StringQuotingEmitter(IEventEmitter next) : ChainedEventEmitter(next)
 13{
 14    // Patterns from https://yaml.org/spec/1.2/spec.html#id2804356
 115    private static readonly Regex quotedRegex = MyRegex();
 16
 17    /// <summary>
 18    /// Emit a scalar event, quoting strings that might be misinterpreted as other types
 19    /// </summary>
 20    /// <param name="eventInfo">The event information</param>
 21    /// <param name="emitter">The YAML emitter</param>
 22    public override void Emit(ScalarEventInfo eventInfo, IEmitter emitter)
 23    {
 9124        var typeCode = eventInfo.Source.Value != null
 9125        ? Type.GetTypeCode(eventInfo.Source.Type)
 9126        : TypeCode.Empty;
 27
 28        switch (typeCode)
 29        {
 30            case TypeCode.Char:
 031                if (eventInfo.Source.Value is char c && char.IsDigit(c))
 32                {
 033                    eventInfo.Style = ScalarStyle.DoubleQuoted;
 34                }
 035                break;
 36            case TypeCode.String:
 6237                var val = eventInfo.Source.Value?.ToString() ?? string.Empty;
 6238                var tagVal = eventInfo.Tag.IsEmpty ? null : eventInfo.Tag.Value;
 39                // Standard YAML null tag with empty value -> leave blank plain scalar (no quotes or 'null' literal)
 6240                if (string.Equals(tagVal, "tag:yaml.org,2002:null", StringComparison.Ordinal) && val.Length == 0)
 41                {
 042                    eventInfo.Style = ScalarStyle.Plain;
 43                    // Remove tag to avoid explicit tag output; blank value implies null
 044                    eventInfo.Tag = TagName.Empty;
 045                    break;
 46                }
 6247                if (val.Length > 0 && quotedRegex.IsMatch(val))
 48                {
 449                    eventInfo.Style = ScalarStyle.DoubleQuoted;
 50                }
 5851                else if (val.IndexOf('\n') > -1)
 52                {
 053                    eventInfo.Style = ScalarStyle.Literal;
 54                }
 55                break;
 56        }
 57
 9158        base.Emit(eventInfo, emitter);
 9159    }
 60
 61    [GeneratedRegex(@"^(\~|null|true|false|on|off|yes|no|y|n|[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?|[-+]?(\
 62    private static partial Regex MyRegex();
 63}