mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
Prevents Runes throwing if Grapheme is null
This commit is contained in:
@@ -44,7 +44,7 @@ public record struct Cell (Attribute? Attribute = null, bool IsDirty = false, st
|
||||
/// In the case where <see cref="Grapheme"/> has more than one rune it is a combining sequence that is normalized to a
|
||||
/// single Text which may occupies 1 or 2 columns.
|
||||
/// </remarks>
|
||||
public IReadOnlyList<Rune> Runes => Grapheme.EnumerateRunes ().ToList ();
|
||||
public IReadOnlyList<Rune> Runes => string.IsNullOrEmpty (Grapheme) ? [] : Grapheme.EnumerateRunes ().ToList ();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString ()
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace UnitTests_Parallelizable.DrawingTests;
|
||||
using System.Text;
|
||||
|
||||
namespace UnitTests_Parallelizable.DrawingTests;
|
||||
|
||||
public class CellTests
|
||||
{
|
||||
@@ -7,11 +9,30 @@ public class CellTests
|
||||
{
|
||||
var c = new Cell ();
|
||||
Assert.True (c is { });
|
||||
Assert.Empty (c.Runes);
|
||||
Assert.Null (c.Attribute);
|
||||
Assert.False (c.IsDirty);
|
||||
Assert.Null (c.Grapheme);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (null, new uint [] { })]
|
||||
[InlineData ("", new uint [] { })]
|
||||
[InlineData ("a", new uint [] { 0x0061 })]
|
||||
[InlineData ("👩❤️💋👨", new uint [] { 0x1F469, 0x200D, 0x2764, 0xFE0F, 0x200D, 0x1F48B, 0x200D, 0x1F468 })]
|
||||
public void Runes_From_Grapheme (string grapheme, uint [] expected)
|
||||
{
|
||||
// Arrange
|
||||
var c = new Cell { Grapheme = grapheme };
|
||||
|
||||
// Act
|
||||
Rune [] runes = expected.Select (u => new Rune (u)).ToArray ();
|
||||
|
||||
// Assert
|
||||
Assert.Equal (grapheme, c.Grapheme);
|
||||
Assert.Equal (runes, c.Runes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_False ()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user