< 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@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
70%
Covered lines: 14
Uncovered lines: 6
Coverable lines: 20
Total lines: 63
Line coverage: 70%
Branch coverage
69%
Covered branches: 18
Total branches: 26
Branch coverage: 69.2%
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@10d476bee71c71ad215bb8ab59f219887b5b4a5e01/15/2026 - 23:50:39 Line coverage: 70% (14/20) Branch coverage: 69.2% (18/26) Total lines: 63 Tag: Kestrun/Kestrun@2d823cb7ceae127151c8880ca073ffbb9c6322aa 10/13/2025 - 16:52:37 Line coverage: 65% (13/20) Branch coverage: 65.3% (17/26) Total lines: 63 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e01/15/2026 - 23:50:39 Line coverage: 70% (14/20) Branch coverage: 69.2% (18/26) Total lines: 63 Tag: Kestrun/Kestrun@2d823cb7ceae127151c8880ca073ffbb9c6322aa

Metrics

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

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>
 2512public 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    {
 9924        var typeCode = eventInfo.Source.Value != null
 9925        ? Type.GetTypeCode(eventInfo.Source.Type)
 9926        : 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:
 6737                var val = eventInfo.Source.Value?.ToString() ?? string.Empty;
 6738                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)
 6740                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                }
 6747                if (val.Length > 0 && quotedRegex.IsMatch(val))
 48                {
 549                    eventInfo.Style = ScalarStyle.DoubleQuoted;
 50                }
 6251                else if (val.IndexOf('\n') > -1)
 52                {
 153                    eventInfo.Style = ScalarStyle.Literal;
 54                }
 55                break;
 56        }
 57
 9958        base.Emit(eventInfo, emitter);
 9959    }
 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}