From 37c971851019cafce9c5477b700131a03804a9b7 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 12 Nov 2025 15:40:05 +0000 Subject: [PATCH] Prevents Runes throwing if Grapheme is null --- Terminal.Gui/Drawing/Cell.cs | 2 +- .../Drawing/CellTests.cs | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/Drawing/Cell.cs b/Terminal.Gui/Drawing/Cell.cs index c3f613038..96670e296 100644 --- a/Terminal.Gui/Drawing/Cell.cs +++ b/Terminal.Gui/Drawing/Cell.cs @@ -44,7 +44,7 @@ public record struct Cell (Attribute? Attribute = null, bool IsDirty = false, st /// In the case where has more than one rune it is a combining sequence that is normalized to a /// single Text which may occupies 1 or 2 columns. /// - public IReadOnlyList Runes => Grapheme.EnumerateRunes ().ToList (); + public IReadOnlyList Runes => string.IsNullOrEmpty (Grapheme) ? [] : Grapheme.EnumerateRunes ().ToList (); /// public override string ToString () diff --git a/Tests/UnitTestsParallelizable/Drawing/CellTests.cs b/Tests/UnitTestsParallelizable/Drawing/CellTests.cs index 3ee2dea54..c3bc4786a 100644 --- a/Tests/UnitTestsParallelizable/Drawing/CellTests.cs +++ b/Tests/UnitTestsParallelizable/Drawing/CellTests.cs @@ -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 () {