mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-31 02:08:03 +01:00
Fixed DimAuto and tests
This commit is contained in:
@@ -17,25 +17,30 @@ namespace Terminal.Gui;
|
||||
/// </remarks>
|
||||
public class DimAuto : Dim
|
||||
{
|
||||
private readonly Dim? _maximumContentDim;
|
||||
|
||||
private readonly Dim? _minimumContentDim;
|
||||
|
||||
private readonly DimAutoStyle _style;
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <inheritdoc />
|
||||
public override bool Equals (object? other)
|
||||
{
|
||||
if (ReferenceEquals (this, other))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (other is not DimAuto auto)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return auto.MinimumContentDim == MinimumContentDim && auto.MaximumContentDim == MaximumContentDim && auto.Style == Style;
|
||||
return EqualityComparer<Dim?>.Default.Equals (MinimumContentDim, auto.MinimumContentDim) &&
|
||||
EqualityComparer<Dim?>.Default.Equals (MaximumContentDim, auto.MaximumContentDim) &&
|
||||
Style == auto.Style;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode () { return HashCode.Combine (MinimumContentDim, MaximumContentDim, Style); }
|
||||
/// <inheritdoc />
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
return HashCode.Combine (MinimumContentDim, MaximumContentDim, Style);
|
||||
}
|
||||
private readonly Dim? _maximumContentDim;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum dimension the View's ContentSize will be fit to. NOT CURRENTLY SUPPORTED.
|
||||
@@ -48,6 +53,8 @@ public class DimAuto : Dim
|
||||
init => _maximumContentDim = value;
|
||||
}
|
||||
|
||||
private readonly Dim? _minimumContentDim;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the minimum dimension the View's ContentSize will be constrained to.
|
||||
/// </summary>
|
||||
@@ -59,6 +66,8 @@ public class DimAuto : Dim
|
||||
init => _minimumContentDim = value;
|
||||
}
|
||||
|
||||
private readonly DimAutoStyle _style;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the style of the DimAuto.
|
||||
/// </summary>
|
||||
|
||||
@@ -216,8 +216,50 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
||||
MinimumContentDim = 1,
|
||||
Style = DimAutoStyle.Auto
|
||||
};
|
||||
|
||||
var c = new DimAuto
|
||||
{
|
||||
MaximumContentDim = 2,
|
||||
MinimumContentDim = 1,
|
||||
Style = DimAutoStyle.Auto
|
||||
};
|
||||
|
||||
var d = new DimAuto
|
||||
{
|
||||
MaximumContentDim = null,
|
||||
MinimumContentDim = 1,
|
||||
Style = DimAutoStyle.Content
|
||||
};
|
||||
|
||||
var e = new DimAuto
|
||||
{
|
||||
MaximumContentDim = null,
|
||||
MinimumContentDim = 2,
|
||||
Style = DimAutoStyle.Auto
|
||||
};
|
||||
|
||||
// Test equality with same values
|
||||
Assert.True (a.Equals (b));
|
||||
Assert.True (a.GetHashCode () == b.GetHashCode ());
|
||||
|
||||
// Test inequality with different MaximumContentDim
|
||||
Assert.False (a.Equals (c));
|
||||
Assert.False (a.GetHashCode () == c.GetHashCode ());
|
||||
|
||||
// Test inequality with different Style
|
||||
Assert.False (a.Equals (d));
|
||||
Assert.False (a.GetHashCode () == d.GetHashCode ());
|
||||
|
||||
// Test inequality with different MinimumContentDim
|
||||
Assert.False (a.Equals (e));
|
||||
Assert.False (a.GetHashCode () == e.GetHashCode ());
|
||||
|
||||
// Test equality with self
|
||||
Assert.True (a.Equals (a));
|
||||
Assert.True (a.GetHashCode () == a.GetHashCode ());
|
||||
|
||||
// Test inequality with null
|
||||
Assert.False (a.Equals (null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user