Просмотр исходного кода

Add constructor overload to SliderOption<T> (#3101)

* Add constructor overload to SliderOption

* Adjust whitespace

* Move tests to SliderOptionTests

* Empty commit for CI
Thomas Nind 1 год назад
Родитель
Сommit
8954fa5ecf
2 измененных файлов с 39 добавлено и 0 удалено
  1. 19 0
      Terminal.Gui/Views/Slider.cs
  2. 20 0
      UnitTests/Views/SliderTests.cs

+ 19 - 0
Terminal.Gui/Views/Slider.cs

@@ -48,6 +48,25 @@ public class SliderOption<T> {
 	/// </summary>
 	public T Data { get; set; }
 
+	/// <summary>
+	/// Creates a new empty instance of the <see cref="SliderOption{T}"/> class.
+	/// </summary>
+	public SliderOption ()
+	{
+
+	}
+
+	/// <summary>
+	/// Creates a new instance of the <see cref="SliderOption{T}"/> class with values for
+	/// each property.
+	/// </summary>
+	public SliderOption (string legend, Rune legendAbbr, T data)
+	{
+		Legend = legend;
+		LegendAbbr = legendAbbr;
+		Data = data;
+	}
+
 	/// <summary>
 	/// To Raise the <see cref="Set"/> event from the Slider.
 	/// </summary>

+ 20 - 0
UnitTests/Views/SliderTests.cs

@@ -9,6 +9,26 @@ using System.Threading.Tasks;
 namespace Terminal.Gui.ViewsTests;
 
 public class SliderOptionTests {
+
+
+	[Fact]
+	public void Slider_Option_Default_Constructor ()
+	{
+		var o = new SliderOption<int> ();
+		Assert.Null (o.Legend);
+		Assert.Equal (default, o.LegendAbbr);
+		Assert.Equal (default, o.Data);
+	}
+
+	[Fact]
+	public void Slider_Option_Values_Constructor ()
+	{
+		var o = new SliderOption<int> ("1 thousand", new Rune ('y'), 1000);
+		Assert.Equal ("1 thousand", o.Legend);
+		Assert.Equal (new Rune ('y'), o.LegendAbbr);
+		Assert.Equal (1000, o.Data);
+	}
+
 	[Fact]
 	public void OnSet_Should_Raise_SetEvent ()
 	{