Skip to content

Commit

Permalink
Merge pull request #21 from Pedrokostam/psm-based-version-recognition
Browse files Browse the repository at this point in the history
Psm based version recognition
  • Loading branch information
Pedrokostam authored Apr 8, 2024
2 parents c30d867 + c2c404f commit 87ff2e5
Show file tree
Hide file tree
Showing 31 changed files with 283 additions and 447 deletions.
7 changes: 5 additions & 2 deletions WriteProgressPlus.Tests/FormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public class FormatterTests
{
static PowerShell Pwsh { get; }

public ItemFormatter GetFormatter(ScriptBlock? script = null, string[]? properties = null, string? separator = null)
public static ItemFormatter GetFormatter(ScriptBlock? script = null, string[]? properties = null, string? separator = null)
{
var formatter = new ItemFormatter();
formatter.Update(script, properties, separator);
return formatter;
}
public static readonly DateTime TestDate = new DateTime(year: 2005,
public static readonly DateTime TestDate = new(year: 2005,
month: 4,
day: 2,
hour: 21,
Expand Down Expand Up @@ -55,6 +55,7 @@ static FormatterTests()
public static readonly string[] Standard_PropertyPattern = ["hour", "minute"];
public static readonly object[] Standard_PropertyTargets = [21, 37];

[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Required for dynamic data")]
public static string DefaultFormatterTestValuesDisplayName(MethodInfo methodInfo, object[] data)
{
var first = data[0];
Expand All @@ -75,6 +76,7 @@ [new Point(21,37)],
[Guid.NewGuid()],
[null],
];
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Required for dynamic data")]
public static string CaseSensitiveTestValuesDisplayName(MethodInfo methodInfo, object[] data)
{
var obj = data[0];
Expand Down Expand Up @@ -105,6 +107,7 @@ public static IEnumerable<object?[]> CaseSensitiveTestValues
}
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Required for dynamic data")]
public static string PropertyOrderTestValuesDisplayName(MethodInfo methodInfo, object[] data)
{
var obj = data[0];
Expand Down
217 changes: 0 additions & 217 deletions WriteProgressPlus.Tests/FormatterTests.cs.bak

This file was deleted.

9 changes: 5 additions & 4 deletions WriteProgressPlus.Tests/TimeBufferTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using System.Web.Services.Description;
using WriteProgressPlus.Components;
using WriteProgressPlus.Components.Time;

namespace WriteProgressPlus.Tests;

Expand Down Expand Up @@ -48,9 +49,9 @@ public void TestReplacement(int length)
buff.AddTime(DateTime.MaxValue, i);
}
buff.AddTime(e2);
var aver = buff.CalculateMovingAverageTime();
var average = buff.CalculateMovingAverageTime();
var span = (d2 - d) / (length - 1);
Assert.AreEqual(span.Ticks, buff.CalculateMovingAverageTime().Ticks, 10);
Assert.AreEqual(span.Ticks, average.Ticks, 10);

}

Expand All @@ -69,8 +70,8 @@ public void TestRunningAverage(double millis, int increment)
var buff = new TimeBuffer(0);
buff.AddTime(start, 0);
buff.AddTime(end, increment);
var aver = buff.CalculateMovingAverageTime();
Assert.AreEqual(avg, buff.CalculateMovingAverageTime());
var average = buff.CalculateMovingAverageTime();
Assert.AreEqual(avg, average);
}

[DataTestMethod]
Expand Down
9 changes: 0 additions & 9 deletions WriteProgressPlus/Components/IdConflictException.cs

This file was deleted.

9 changes: 3 additions & 6 deletions WriteProgressPlus/Components/ItemFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace WriteProgressPlus.Components;

public partial class ItemFormatter
public class ItemFormatter
{
public enum FormatSource
{
Expand Down Expand Up @@ -73,14 +73,11 @@ public void Update(ScriptBlock? script, string[]? props, string? sep)
}

object? firstObject = objects[0];
if (Properties.Length > 0)
{
return GetFormattedProperties(firstObject);
}
else
if (Properties.Length == 0)
{
return firstObject?.ToString();
}
return GetFormattedProperties(firstObject);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Text;
using System.Text.RegularExpressions;

namespace WriteProgressPlus.Components;
namespace WriteProgressPlus.Components.Layout;

/// <summary>
/// All inputs needed to populate a progress bar with data.
Expand All @@ -14,18 +14,18 @@ internal readonly record struct BarInput
public readonly Counter Counter;
public readonly string Activity;
public readonly int RemainingTime;
public readonly Size BufferSize;
public readonly ProgressAreaLayout Layout;
public readonly Elements Visible;
public int LineWidth => BufferSize.Width;
public int LineHeight => BufferSize.Height;
public int LineWidth => Layout.Width;
public int LineHeight => Layout.Height;

public BarInput(string? formattedItem, Counter counter, string activity, int remainingTime, Size buffer, Elements visible)
public BarInput(string? formattedItem, Counter counter, string activity, int remainingTime, ProgressAreaLayout buffer, Elements visible)
{
FormattedItem = Regex.Replace((formattedItem ?? string.Empty), @"[\r\n]", "", RegexOptions.None, TimeSpan.FromMilliseconds(500));
FormattedItem = Regex.Replace(formattedItem ?? string.Empty, @"[\r\n]", "", RegexOptions.None, TimeSpan.FromMilliseconds(500));
Counter = counter;
Activity = activity;
RemainingTime = remainingTime;
BufferSize = buffer;
Layout = buffer;
Visible = visible;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace WriteProgressPlus.Components;
namespace WriteProgressPlus.Components.Layout;

internal readonly record struct BarOutput
{
Expand Down
Loading

0 comments on commit 87ff2e5

Please sign in to comment.