diff --git a/Terminal.Gui/Views/Slider.cs b/Terminal.Gui/Views/Slider.cs index 2b161bc297..6a69f6c0eb 100644 --- a/Terminal.Gui/Views/Slider.cs +++ b/Terminal.Gui/Views/Slider.cs @@ -86,6 +86,12 @@ internal void OnChanged (bool isSet) /// Event fired when the an option has changed. /// public event EventHandler Changed; + + /// + /// Creates a human-readable string that represents this . + /// + public override string ToString () => "{Legend=" + Legend + ", LegendAbbr=" + LegendAbbr.ToString () + ", Data=" + Data?.ToString () + "}"; + } /// diff --git a/UnitTests/Views/SliderTests.cs b/UnitTests/Views/SliderTests.cs index ba634ad801..d593450bea 100644 --- a/UnitTests/Views/SliderTests.cs +++ b/UnitTests/Views/SliderTests.cs @@ -53,6 +53,38 @@ public void OnChanged_Should_Raise_ChangedEvent () // Assert Assert.True (eventRaised); } + + [Fact] + public void SliderOption_ToString_WhenEmpty () + { + var sliderOption = new SliderOption (); + Assert.Equal ("{Legend=, LegendAbbr=\0, Data=}", sliderOption.ToString ()); + } + + [Fact] + public void SliderOption_ToString_WhenPopulated_WithInt () + { + var sliderOption = new SliderOption { + Legend = "Lord flibble", + LegendAbbr = new Rune ('l'), + Data = 1, + }; + + Assert.Equal ("{Legend=Lord flibble, LegendAbbr=l, Data=1}", sliderOption.ToString ()); + } + + + [Fact] + public void SliderOption_ToString_WhenPopulated_WithSizeF () + { + var sliderOption = new SliderOption { + Legend = "Lord flibble", + LegendAbbr = new Rune ('l'), + Data = new SizeF(32,11), + }; + + Assert.Equal ("{Legend=Lord flibble, LegendAbbr=l, Data={Width=32, Height=11}}", sliderOption.ToString ()); + } } public class SliderEventArgsTests { @@ -411,7 +443,7 @@ public void Set_Should_Not_UnSetFocusedOption_When_EmptyNotAllowed () // Assert Assert.False (result); - Assert.NotEmpty (slider.GetSetOptions()); + Assert.NotEmpty (slider.GetSetOptions ()); } // Add more tests for different scenarios and edge cases.