< Summary

Information
Class: SwiftCollections.Diagnostics.SwiftThrowInterpolatedStringHandler
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Diagnostics/SwiftThrowInterpolatedStringHandler.cs
Line coverage
26%
Covered lines: 7
Uncovered lines: 19
Coverable lines: 26
Total lines: 156
Line coverage: 26.9%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_IsEnabled()100%210%
GetFormattedText()100%11100%
AppendLiteral(...)100%11100%
AppendFormatted(...)100%11100%
AppendFormatted(...)100%210%
AppendFormatted(...)100%210%
AppendFormatted(...)100%210%
AppendFormatted(...)100%210%
AppendFormatted(...)100%210%
AppendFormatted(...)100%210%
AppendFormatted(...)100%210%
AppendFormatted(...)100%210%
AppendFormatted(...)100%210%

File(s)

/home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Diagnostics/SwiftThrowInterpolatedStringHandler.cs

#LineLine coverage
 1//=======================================================================
 2// SwiftThrowInterpolatedStringHandler.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024-present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8namespace SwiftCollections.Diagnostics;
 9
 10using System;
 11using System.Runtime.CompilerServices;
 12
 13/// <summary>
 14/// Builds exception messages only when the guarded throw condition is true.
 15/// </summary>
 16[InterpolatedStringHandler]
 17public ref struct SwiftThrowInterpolatedStringHandler
 18{
 19    private DiagnosticInterpolatedStringHandler _message;
 20
 21    /// <summary>
 22    /// Initializes a new instance of the <see cref="SwiftThrowInterpolatedStringHandler"/> struct.
 23    /// </summary>
 24    /// <param name="literalLength">The combined length of literal portions in the interpolated string.</param>
 25    /// <param name="formattedCount">The number of formatted expressions in the interpolated string.</param>
 26    /// <param name="condition">The throw condition that controls whether formatting occurs.</param>
 27    /// <param name="isEnabled">Set to <see langword="true"/> when formatted expressions should be evaluated.</param>
 28    public SwiftThrowInterpolatedStringHandler(
 29        int literalLength,
 30        int formattedCount,
 31        bool condition,
 32        out bool isEnabled)
 33    {
 334        _message = new DiagnosticInterpolatedStringHandler(literalLength, formattedCount, condition, out isEnabled);
 335    }
 36
 37    /// <summary>
 38    /// Gets whether this handler is actively building an exception message.
 39    /// </summary>
 040    public bool IsEnabled => _message.IsEnabled;
 41
 142    internal string GetFormattedText() => _message.GetFormattedText();
 43
 44    /// <summary>
 45    /// Appends a literal string segment.
 46    /// </summary>
 47    /// <param name="value">The literal string segment.</param>
 48    public void AppendLiteral(string value)
 49    {
 250        _message.AppendLiteral(value);
 251    }
 52
 53    /// <summary>
 54    /// Appends a formatted value.
 55    /// </summary>
 56    /// <typeparam name="T">The type of value to append.</typeparam>
 57    /// <param name="value">The value to append.</param>
 58    public void AppendFormatted<T>(T value)
 59    {
 160        _message.AppendFormatted(value);
 161    }
 62
 63    /// <summary>
 64    /// Appends a formatted value using the specified format string.
 65    /// </summary>
 66    /// <typeparam name="T">The type of value to append.</typeparam>
 67    /// <param name="value">The value to append.</param>
 68    /// <param name="format">The format string to apply.</param>
 69    public void AppendFormatted<T>(T value, string? format)
 70    {
 071        _message.AppendFormatted(value, format);
 072    }
 73
 74    /// <summary>
 75    /// Appends a formatted value with the specified alignment.
 76    /// </summary>
 77    /// <typeparam name="T">The type of value to append.</typeparam>
 78    /// <param name="value">The value to append.</param>
 79    /// <param name="alignment">The minimum width for the formatted value.</param>
 80    public void AppendFormatted<T>(T value, int alignment)
 81    {
 082        _message.AppendFormatted(value, alignment);
 083    }
 84
 85    /// <summary>
 86    /// Appends a formatted value with the specified alignment and format string.
 87    /// </summary>
 88    /// <typeparam name="T">The type of value to append.</typeparam>
 89    /// <param name="value">The value to append.</param>
 90    /// <param name="alignment">The minimum width for the formatted value.</param>
 91    /// <param name="format">The format string to apply.</param>
 92    public void AppendFormatted<T>(T value, int alignment, string? format)
 93    {
 094        _message.AppendFormatted(value, alignment, format);
 095    }
 96
 97    /// <summary>
 98    /// Appends a string value.
 99    /// </summary>
 100    /// <param name="value">The value to append.</param>
 101    public void AppendFormatted(string? value)
 102    {
 0103        _message.AppendFormatted(value);
 0104    }
 105
 106    /// <summary>
 107    /// Appends a string value with the specified alignment.
 108    /// </summary>
 109    /// <param name="value">The value to append.</param>
 110    /// <param name="alignment">The minimum width for the formatted value.</param>
 111    public void AppendFormatted(string? value, int alignment)
 112    {
 0113        _message.AppendFormatted(value, alignment);
 0114    }
 115
 116    /// <summary>
 117    /// Appends a string value with the specified alignment and format string.
 118    /// </summary>
 119    /// <param name="value">The value to append.</param>
 120    /// <param name="alignment">The minimum width for the formatted value.</param>
 121    /// <param name="format">The format string to apply.</param>
 122    public void AppendFormatted(string? value, int alignment, string? format)
 123    {
 0124        _message.AppendFormatted(value, alignment, format);
 0125    }
 126
 127    /// <summary>
 128    /// Appends a character span.
 129    /// </summary>
 130    /// <param name="value">The span to append.</param>
 131    public void AppendFormatted(ReadOnlySpan<char> value)
 132    {
 0133        _message.AppendFormatted(value);
 0134    }
 135
 136    /// <summary>
 137    /// Appends a character span with the specified alignment.
 138    /// </summary>
 139    /// <param name="value">The span to append.</param>
 140    /// <param name="alignment">The minimum width for the formatted value.</param>
 141    public void AppendFormatted(ReadOnlySpan<char> value, int alignment)
 142    {
 0143        _message.AppendFormatted(value, alignment);
 0144    }
 145
 146    /// <summary>
 147    /// Appends a character span with the specified alignment and format string.
 148    /// </summary>
 149    /// <param name="value">The span to append.</param>
 150    /// <param name="alignment">The minimum width for the formatted value.</param>
 151    /// <param name="format">The format string to apply.</param>
 152    public void AppendFormatted(ReadOnlySpan<char> value, int alignment, string? format)
 153    {
 0154        _message.AppendFormatted(value, alignment, format);
 0155    }
 156}