< Summary

Information
Class: Allyaria.Theming.StyleTypes.StyleWordBreak
Assembly: Allyaria.Theming
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Theming/StyleTypes/StyleWordBreak.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 95
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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Parse(...)100%22100%
TryParse(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%22100%

File(s)

/home/runner/work/allyaria/allyaria/src/Allyaria.Theming/StyleTypes/StyleWordBreak.cs

#LineLine coverage
 1namespace Allyaria.Theming.StyleTypes;
 2
 3/// <summary>
 4/// Represents a CSS <c>word-break</c> value within the Allyaria theming system. Provides a strongly typed wrapper for
 5/// controlling how lines should break within words when text overflows its container.
 6/// </summary>
 7public sealed record StyleWordBreak : StyleValueBase
 8{
 9    /// <summary>
 10    /// Initializes a new instance of the <see cref="StyleWordBreak" /> record using the specified <see cref="Kind" /> v
 11    /// </summary>
 12    /// <param name="kind">The word-breaking behavior to represent.</param>
 13    public StyleWordBreak(Kind kind)
 3014        : base(value: kind.GetDescription()) { }
 15
 16    /// <summary>Defines the supported CSS <c>word-break</c> property values.</summary>
 17    public enum Kind
 18    {
 19        /// <summary>
 20        /// Breaks words at arbitrary points if necessary to prevent overflow. Useful for non-language-based content or 
 21        /// strings.
 22        /// </summary>
 23        [Description(description: "break-all")]
 24        BreakAll,
 25
 26        /// <summary>
 27        /// Allows unbreakable words to be broken if necessary to prevent overflow, but otherwise uses normal line-break
 28        /// </summary>
 29        [Description(description: "break-word")]
 30        BreakWord,
 31
 32        /// <summary>
 33        /// Prevents line breaks within words in East Asian text (CJK), maintaining whole-word wrapping where possible.
 34        /// </summary>
 35        [Description(description: "keep-all")]
 36        KeepAll,
 37
 38        /// <summary>Uses the default line-breaking rules for the document’s language and writing system.</summary>
 39        [Description(description: "normal")]
 40        Normal
 41    }
 42
 43    /// <summary>
 44    /// Parses a string representation of a CSS <c>word-break</c> value into a <see cref="StyleWordBreak" /> instance.
 45    /// </summary>
 46    /// <param name="value">The string representation of the word-break value.</param>
 47    /// <returns>A new <see cref="StyleWordBreak" /> instance representing the parsed value.</returns>
 48    /// <exception cref="AryArgumentException">
 49    /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />.
 50    /// </exception>
 51    public static StyleWordBreak Parse(string? value)
 1152        => value.TryParseEnum<Kind>(result: out var kind)
 1153            ? new StyleWordBreak(kind: kind)
 1154            : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value));
 55
 56    /// <summary>Attempts to parse a string into a <see cref="StyleWordBreak" /> instance.</summary>
 57    /// <param name="value">The string representation of the word-break value to parse.</param>
 58    /// <param name="result">
 59    /// When this method returns, contains the parsed <see cref="StyleWordBreak" /> instance or <see langword="null" /> 
 60    /// parsing failed.
 61    /// </param>
 62    /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns>
 63    public static bool TryParse(string? value, out StyleWordBreak? result)
 64    {
 65        try
 66        {
 367            result = Parse(value: value);
 68
 169            return true;
 70        }
 271        catch
 72        {
 273            result = null;
 74
 275            return false;
 76        }
 377    }
 78
 79    /// <summary>Implicitly converts a string into a <see cref="StyleWordBreak" /> instance.</summary>
 80    /// <param name="value">The string representation of the word-break value.</param>
 81    /// <returns>A <see cref="StyleWordBreak" /> instance representing the provided value.</returns>
 82    /// <exception cref="AryArgumentException">
 83    /// Thrown when the provided string cannot be parsed into a valid
 84    /// <see cref="Kind" />.
 85    /// </exception>
 286    public static implicit operator StyleWordBreak(string? value) => Parse(value: value);
 87
 88    /// <summary>Implicitly converts a <see cref="StyleWordBreak" /> instance to its string representation.</summary>
 89    /// <param name="value">The <see cref="StyleWordBreak" /> instance to convert.</param>
 90    /// <returns>
 91    /// The underlying CSS <c>word-break</c> string value, or an empty string if <paramref name="value" /> is
 92    /// <see langword="null" />.
 93    /// </returns>
 294    public static implicit operator string(StyleWordBreak? value) => (value?.Value).OrDefaultIfEmpty();
 95}