Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-7753: simplify file size string #15629

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/DynamoUtilities/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ static DynamoUtilities.PathHelper.IsValidPath(string filePath) -> bool
static DynamoUtilities.PathHelper.isValidXML(string path, out System.Xml.XmlDocument xmlDoc, out System.Exception ex) -> bool
static DynamoUtilities.PathHelper.LoadEmbeddedResourceAsString(string resourcePath, System.Reflection.Assembly assembly) -> string
static DynamoUtilities.StringUtilities.CapitalizeFirstLetter(string word) -> string
static DynamoUtilities.StringUtilities.SimplifyFileSizeUnit(string size) -> string
static DynamoUtilities.TypeSwitch.Case<T>(System.Action action) -> DynamoUtilities.TypeSwitch.CaseInfo
static DynamoUtilities.TypeSwitch.Case<T>(System.Action<T> action) -> DynamoUtilities.TypeSwitch.CaseInfo
static DynamoUtilities.TypeSwitch.Default(System.Action action) -> DynamoUtilities.TypeSwitch.CaseInfo
Expand Down
21 changes: 15 additions & 6 deletions src/DynamoUtilities/StringUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DynamoUtilities
{
/// <summary>
Expand All @@ -23,5 +17,20 @@ public static string CapitalizeFirstLetter(string word)

return char.ToUpper(word[0]) + word.Substring(1);
}

/// <summary>
/// Replaces 'i' in a file size string
/// </summary>
/// <param name="size">The file size string</param>
/// <returns></returns>
public static string SimplifyFileSizeUnit(string size)
{
if (string.IsNullOrEmpty(size))
{
return size;
}

return size.Replace("i", "");
}
}
}
5 changes: 3 additions & 2 deletions src/PackageDetailsViewExtension/PackageDetailItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Dynamo.Core;
using Dynamo.PackageManager;
using Dynamo.PythonServices;
using DynamoUtilities;
using Greg.Responses;

namespace Dynamo.PackageDetails
Expand Down Expand Up @@ -283,7 +284,7 @@ public PackageDetailItem(string packageName, PackageVersion packageVersion, bool
this.CopyRightYear = PackageVersion.copyright_year;
this.CanInstall = canInstall;
this.IsEnabledForInstall = isEnabledForInstall && canInstall;
this.PackageSize = string.IsNullOrEmpty(PackageVersion.size) ? "--" : PackageVersion.size;
this.PackageSize = string.IsNullOrEmpty(PackageVersion.size) ? "--" : StringUtilities.SimplifyFileSizeUnit (PackageVersion.size);
this.Created = GetFormattedDate(PackageVersion.created);
this.VersionInformation = GetFlattenedCompatibilityInformation(packageVersion.compatibility_matrix);
this.ReleaseNotes = PackageVersion.release_notes_url;
Expand Down Expand Up @@ -315,7 +316,7 @@ public PackageDetailItem(List<VersionInformation> versionDetails, string package
this.CopyRightYear = PackageVersion.copyright_year;
this.CanInstall = canInstall;
this.IsEnabledForInstall = isEnabledForInstall && canInstall;
this.PackageSize = string.IsNullOrEmpty(PackageVersion.size) ? "--" : PackageVersion.size;
this.PackageSize = string.IsNullOrEmpty(PackageVersion.size) ? "--" : StringUtilities.SimplifyFileSizeUnit (PackageVersion.size);
this.Created = GetFormattedDate(PackageVersion.created);
this.VersionInformation = GetFlattenedCompatibilityInformation(packageVersion.compatibility_matrix);
this.IsCompatible = PackageManager.VersionInformation.GetVersionCompatibility(versionDetails, PackageVersionNumber);
Expand Down
49 changes: 49 additions & 0 deletions test/DynamoCoreTests/StringUtilitiesTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using DynamoUtilities;
using NUnit.Framework;

namespace Dynamo.Tests
{
[TestFixture]
class StringUtilitiesTest
{
[TestCase("512 MiB", ExpectedResult = "512 MB")]
[TestCase("1 GiB", ExpectedResult = "1 GB")]
[TestCase("128 KiB", ExpectedResult = "128 KB")]
[TestCase("2 TiB", ExpectedResult = "2 TB")]
[TestCase("0 PiB", ExpectedResult = "0 PB")]
[TestCase("1024 EiB", ExpectedResult = "1024 EB")]
public string ConvertToSIFileSize_StandardUnitsWithI_RemovesI(string input)
{
return StringUtilities.SimplifyFileSizeUnit (input);
}

[TestCase("512 MB", ExpectedResult = "512 MB")]
[TestCase("1 GB", ExpectedResult = "1 GB")]
[TestCase("128 KB", ExpectedResult = "128 KB")]
public string ConvertToSIFileSize_StandardUnitsWithoutI_Unchanged(string input)
{
return StringUtilities.SimplifyFileSizeUnit (input);
}

[TestCase("Random Text", ExpectedResult = "Random Text")]
[TestCase("128", ExpectedResult = "128")]
[TestCase("", ExpectedResult = "")]
[TestCase(null, ExpectedResult = null)]
public string ConvertToSIFileSize_NonStandardInputs_Unchanged(string input)
{
return StringUtilities.SimplifyFileSizeUnit (input);
}

[Test]
public void ConvertToSIFileSize_NullInput_ReturnsNull()
{
Assert.IsNull(StringUtilities.SimplifyFileSizeUnit (null));
}

[Test]
public void ConvertToSIFileSize_EmptyString_ReturnsEmptyString()
{
Assert.AreEqual("", StringUtilities.SimplifyFileSizeUnit (""));
}
}
}
Loading