Skip to content

Commit

Permalink
(WIP) (BUGS) Merge branch '19-convert-postests-to-constraint-model' i…
Browse files Browse the repository at this point in the history
…nto convert-tests-to-constraint-model

* 19-convert-postests-to-constraint-model:
  More coverage. Bugs revealed.
  Add test for method that wasn't covered. Revealed a bug
  That was accidentally committed a while back. Remove it.
  Convert the rest but ignore them, because they're redundant
  Remove this test, as it's solely a Terminal.Gui test
  Remove redundant test
  Convert this case
  That's not valid
  Fix nullability context in PosExtensions
  Remove redundant test
  Finish unrolling and expanding IsAnchorEnd tests
  Remove redundant tests
  More refactoring
  New tests revealed this bug
  Significant refactor
  Global usings
  Add a couple of handy helper types for tests to cut down on boilerplate
Still work in progress.
Revealed several bugs through increased test coverage.
#19
  • Loading branch information
dodexahedron committed Dec 19, 2023
2 parents fe36b01 + 8d6eedd commit 845076f
Show file tree
Hide file tree
Showing 6 changed files with 572 additions and 272 deletions.
34 changes: 19 additions & 15 deletions src/PosExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static class PosExtensions
/// </summary>
/// <param name="p"><see cref="Pos"/> to classify.</param>
/// <returns>True if <paramref name="p"/> is absolute.</returns>
public static bool IsAbsolute(this Pos p)
public static bool IsAbsolute(this Pos? p)
{
if (p == null)
{
Expand All @@ -32,7 +32,7 @@ public static bool IsAbsolute(this Pos p)
/// <param name="p"><see cref="Pos"/> to classify.</param>
/// <param name="n">The absolute size or 0.</param>
/// <returns>True if <paramref name="p"/> is absolute.</returns>
public static bool IsAbsolute(this Pos p, out int n)
public static bool IsAbsolute(this Pos? p, out int n)
{
if (p.IsAbsolute())
{
Expand All @@ -58,7 +58,7 @@ public static bool IsAbsolute(this Pos p, out int n)
/// </summary>
/// <param name="p"><see cref="Pos"/> to classify.</param>
/// <returns>True if <paramref name="p"/> is <see cref="Pos.Percent(float)"/>.</returns>
public static bool IsPercent(this Pos p)
public static bool IsPercent(this Pos? p)
{
if (p == null)
{
Expand All @@ -74,7 +74,7 @@ public static bool IsPercent(this Pos p)
/// to <see cref="Pos.Percent(float)"/> to produce <paramref name="p"/> or 0 if <paramref name="p"/>
/// is not a percent <see cref="Pos"/>.</param>
/// <returns>True if <paramref name="p"/> is <see cref="Pos.Percent(float)"/>.</returns>
public static bool IsPercent(this Pos p, out float percent)
public static bool IsPercent(this Pos? p, out float percent)
{
if (p != null && p.IsPercent())
{
Expand All @@ -95,7 +95,7 @@ public static bool IsPercent(this Pos p, out float percent)
/// </summary>
/// <param name="p"><see cref="Pos"/> to classify.</param>
/// <returns>True if <see cref="Pos.Center"/>.</returns>
public static bool IsCenter(this Pos p)
public static bool IsCenter(this Pos? p)
{
if (p == null)
{
Expand All @@ -110,7 +110,8 @@ public static bool IsCenter(this Pos p)
/// </summary>
/// <param name="p"><see cref="Pos"/> to classify.</param>
/// <returns>True if <paramref name="p"/> is <see cref="Pos.AnchorEnd(int)"/>.</returns>
public static bool IsAnchorEnd(this Pos p)
// BUG: This should not return true on null, because 0 is an absolute Pos
public static bool IsAnchorEnd(this Pos? p)
{
if (p == null)
{
Expand All @@ -125,7 +126,7 @@ public static bool IsAnchorEnd(this Pos p)
/// <param name="margin">The margin passed to <see cref="Pos.AnchorEnd(int)"/>. Typically should
/// be 1 or more otherwise things tend to drift off screen.</param>
/// <returns></returns>
public static bool IsAnchorEnd(this Pos p, out int margin)
public static bool IsAnchorEnd(this Pos? p, out int margin)
{
if (p.IsAnchorEnd())
{
Expand Down Expand Up @@ -153,7 +154,7 @@ public static bool IsAnchorEnd(this Pos p, out int margin)
/// <param name="p"><see cref="Pos"/> to classify.</param>
/// <returns>True if <paramref name="p"/> is the result of a call to one of the relative methods
/// (e.g. <see cref="Pos.Right(View)"/>).</returns>
public static bool IsRelative(this Pos p)
public static bool IsRelative(this Pos? p)
{
return p.IsRelative(out _);
}
Expand All @@ -165,7 +166,8 @@ public static bool IsRelative(this Pos p)
/// or null if <paramref name="p"/> is not <see cref="PosType.Relative"/>.</param>
/// <param name="side"><see cref="Enum"/> representing the method that was used e.g. <see cref="Pos.Right(View)"/>, <see cref="Pos.Left(View)"/> etc.</param>
/// <returns></returns>
public static bool IsRelative(this Pos p, IList<Design> knownDesigns, out Design? relativeTo, out Side side)
// BUG: Side should be nullable, because it gets an explicit value in all cases
public static bool IsRelative(this Pos? p, IList<Design> knownDesigns, out Design? relativeTo, out Side side)
{
relativeTo = null;
side = default;
Expand Down Expand Up @@ -210,7 +212,7 @@ public static bool IsRelative(this Pos p, IList<Design> knownDesigns, out Design
/// </summary>
/// <param name="p"><see cref="Pos"/> to classify.</param>
/// <returns>True if <paramref name="p"/> is a PosCombine.</returns>
public static bool IsCombine(this Pos p)
public static bool IsCombine(this Pos? p)
{
if (p == null)
{
Expand All @@ -226,7 +228,7 @@ public static bool IsCombine(this Pos p)
/// <param name="right">The right hand operand of the summation/subtraction.</param>
/// <param name="add"><see langword="true"/> if addition or <see langword="false"/> if subtraction.</param>
/// <returns>True if <paramref name="p"/> is PosCombine.</returns>
public static bool IsCombine(this Pos p, out Pos left, out Pos right, out bool add)
public static bool IsCombine(this Pos? p, out Pos left, out Pos right, out bool add)
{
if (p.IsCombine())
{
Expand Down Expand Up @@ -259,7 +261,7 @@ public static bool IsCombine(this Pos p, out Pos left, out Pos right, out bool a
/// <param name="side">Only populated for <see cref="PosType.Relative"/>, this is the direction of offset from <paramref name="relativeTo"/>.</param>
/// <param name="offset">The offset from the listed position. Is provided if the input has addition/subtraction e.g.<code>Pos.Center() + 2</code></param>
/// <returns>True if it was possible to determine what <see cref="PosType"/> <paramref name="p"/> is.</returns>
public static bool GetPosType(this Pos p, IList<Design> knownDesigns, out PosType type, out float value, out Design? relativeTo, out Side side, out int offset)
public static bool GetPosType(this Pos? p, IList<Design> knownDesigns, out PosType type, out float value, out Design? relativeTo, out Side side, out int offset)
{
type = default;
relativeTo = null;
Expand Down Expand Up @@ -325,7 +327,7 @@ public static bool GetPosType(this Pos p, IList<Design> knownDesigns, out PosTyp
/// <param name="p"><see cref="Pos"/> to classify.</param>
/// <param name="knownDesigns">All <see cref="Design"/> that we might be expressed as relative to (e.g. see <see cref="Design.GetAllDesigns"/>).</param>
/// <returns>Code to generate <paramref name="p"/>.</returns>
public static string? ToCode(this Pos p, List<Design> knownDesigns)
public static string? ToCode(this Pos? p, List<Design> knownDesigns)
{
if (!p.GetPosType(knownDesigns, out var type, out var val, out var relativeTo, out var side, out var offset))
{
Expand Down Expand Up @@ -409,7 +411,9 @@ public static bool GetPosType(this Pos p, IList<Design> knownDesigns, out PosTyp
/// <param name="offset">The offset if any to use e.g. if you want:
/// <code>Pos.Left(myView) + 5</code></param>
/// <returns>The resulting <see cref="Pos"/> of the invoked method (e.g. <see cref="Pos.Right(View)"/>.</returns>
public static Pos CreatePosRelative(Design relativeTo, Side side, int offset)
// BUG: This returns absolute positions when offsets are applied
// It's a Terminal.Gui issue, but we can probably work around it.
public static Pos CreatePosRelative(this Design relativeTo, Side side, int offset)
{
Pos pos;
switch (side)
Expand Down Expand Up @@ -437,7 +441,7 @@ public static Pos CreatePosRelative(Design relativeTo, Side side, int offset)
return pos;
}

private static bool IsRelative(this Pos p, out Pos posView)
private static bool IsRelative(this Pos? p, out Pos posView)
{
// Terminal.Gui will often use Pos.Combine with RHS of 0 instead of just PosView alone
if (p != null && p.IsCombine(out var left, out var right, out _))
Expand Down
1 change: 0 additions & 1 deletion src/TerminalGuiDesigner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<PackAsTool>true</PackAsTool>
<ToolCommandName>TerminalGuiDesigner</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<PackageId>TerminalGuiDesigner</PackageId>
<Version>1.1.0-rc1</Version>
Expand Down
Loading

0 comments on commit 845076f

Please sign in to comment.