Skip to content

Commit 8954fa5

Browse files
authored
Add constructor overload to SliderOption<T> (#3101)
* Add constructor overload to SliderOption * Adjust whitespace * Move tests to SliderOptionTests * Empty commit for CI
1 parent 55bf533 commit 8954fa5

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Terminal.Gui/Views/Slider.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ public class SliderOption<T> {
4848
/// </summary>
4949
public T Data { get; set; }
5050

51+
/// <summary>
52+
/// Creates a new empty instance of the <see cref="SliderOption{T}"/> class.
53+
/// </summary>
54+
public SliderOption ()
55+
{
56+
57+
}
58+
59+
/// <summary>
60+
/// Creates a new instance of the <see cref="SliderOption{T}"/> class with values for
61+
/// each property.
62+
/// </summary>
63+
public SliderOption (string legend, Rune legendAbbr, T data)
64+
{
65+
Legend = legend;
66+
LegendAbbr = legendAbbr;
67+
Data = data;
68+
}
69+
5170
/// <summary>
5271
/// To Raise the <see cref="Set"/> event from the Slider.
5372
/// </summary>

UnitTests/Views/SliderTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@
99
namespace Terminal.Gui.ViewsTests;
1010

1111
public class SliderOptionTests {
12+
13+
14+
[Fact]
15+
public void Slider_Option_Default_Constructor ()
16+
{
17+
var o = new SliderOption<int> ();
18+
Assert.Null (o.Legend);
19+
Assert.Equal (default, o.LegendAbbr);
20+
Assert.Equal (default, o.Data);
21+
}
22+
23+
[Fact]
24+
public void Slider_Option_Values_Constructor ()
25+
{
26+
var o = new SliderOption<int> ("1 thousand", new Rune ('y'), 1000);
27+
Assert.Equal ("1 thousand", o.Legend);
28+
Assert.Equal (new Rune ('y'), o.LegendAbbr);
29+
Assert.Equal (1000, o.Data);
30+
}
31+
1232
[Fact]
1333
public void OnSet_Should_Raise_SetEvent ()
1434
{

0 commit comments

Comments
 (0)