-
-
Notifications
You must be signed in to change notification settings - Fork 601
Adding TransferSpeedColumn configuration to display bits/bytes + binary/decimal prefixes #904
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
Changes from 3 commits
9181f9b
dbb9074
cf57c51
4087a31
b60eeac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Spectre.Console; | ||
|
||
/// <summary> | ||
/// Determines possible file size base prefixes. (base 2/base 10). | ||
/// </summary> | ||
public enum FileSizeBase | ||
{ | ||
/// <summary> | ||
/// The SI prefix definition (base 10) of kilobyte, megabyte, etc. | ||
/// </summary> | ||
Decimal = 1000, | ||
|
||
/// <summary> | ||
/// The IEC binary prefix definition (base 2) of kibibyte, mebibyte, etc. | ||
/// </summary> | ||
Binary = 1024, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Spectre.Console; | ||
|
||
internal enum FileSizePrefix | ||
{ | ||
None = 0, | ||
Kilo = 1, | ||
Mega = 2, | ||
Giga = 3, | ||
Tera = 4, | ||
Peta = 5, | ||
Exa = 6, | ||
Zetta = 7, | ||
Yotta = 8, | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
namespace Spectre.Console.Tests.Unit.Internal; | ||
|
||
public sealed class FileSizeTests | ||
{ | ||
[Theory] | ||
[InlineData(0, "0 bytes")] | ||
[InlineData(37, "37 bytes")] | ||
[InlineData(512, "512 bytes")] | ||
[InlineData(15 * 1024, "15.0 KiB")] | ||
[InlineData(1024 * 512, "512.0 KiB")] | ||
[InlineData(5 * 1024 * 1024, "5.0 MiB")] | ||
[InlineData(9 * 1024 * 1024, "9.0 MiB")] | ||
public void Binary_Unit_In_Bytes_Should_Return_Expected(double bytes, string expected) | ||
{ | ||
// Given | ||
var filesize = new FileSize(bytes, FileSizeBase.Binary); | ||
|
||
// When | ||
var result = filesize.ToString(); | ||
|
||
// Then | ||
result.ShouldBe(expected); | ||
} | ||
|
||
[Theory] | ||
[InlineData(0, "0 bits")] | ||
[InlineData(37, "296 bits")] | ||
[InlineData(512, "4.0 Kibit")] | ||
[InlineData(15 * 1024, "120.0 Kibit")] | ||
[InlineData(1024 * 512, "4.0 Mibit")] | ||
[InlineData(5 * 1024 * 1024, "40.0 Mibit")] | ||
[InlineData(210 * 1024 * 1024, "1.6 Gibit")] | ||
[InlineData(900 * 1024 * 1024, "7.0 Gibit")] | ||
public void Binary_Unit_In_Bits_Should_Return_Expected(double bytes, string expected) | ||
{ | ||
// Given | ||
var filesize = new FileSize(bytes, FileSizeBase.Binary, displayBits: true); | ||
Check failure on line 37 in src/Tests/Spectre.Console.Tests/Unit/Internal/FileSizeTests.cs
|
||
|
||
// When | ||
var result = filesize.ToString(); | ||
|
||
// Then | ||
result.ShouldBe(expected); | ||
} | ||
|
||
[Theory] | ||
[InlineData(0, "0 bytes")] | ||
[InlineData(37, "37 bytes")] | ||
[InlineData(512, "512 bytes")] | ||
[InlineData(15 * 1024, "15.4 KB")] | ||
[InlineData(1024 * 512, "524.3 KB")] | ||
[InlineData(5 * 1024 * 1024, "5.2 MB")] | ||
[InlineData(9 * 1024 * 1024, "9.4 MB")] | ||
public void Decimal_Unit_In_Bytes_Should_Return_Expected(double bytes, string expected) | ||
{ | ||
// Given | ||
var filesize = new FileSize(bytes, FileSizeBase.Decimal); | ||
|
||
// When | ||
var result = filesize.ToString(); | ||
|
||
// Then | ||
result.ShouldBe(expected); | ||
} | ||
|
||
[Theory] | ||
[InlineData(0, "0 bits")] | ||
[InlineData(37, "296 bits")] | ||
[InlineData(512, "4.1 Kbit")] | ||
[InlineData(15 * 1024, "122.9 Kbit")] | ||
[InlineData(1024 * 512, "4.2 Mbit")] | ||
[InlineData(5 * 1024 * 1024, "41.9 Mbit")] | ||
[InlineData(900 * 1024 * 1024, "7.5 Gbit")] | ||
public void Decimal_Unit_In_Bits_Should_Return_Expected(double bytes, string expected) | ||
{ | ||
// Given | ||
var filesize = new FileSize(bytes, FileSizeBase.Decimal, displayBits: true); | ||
Check failure on line 77 in src/Tests/Spectre.Console.Tests/Unit/Internal/FileSizeTests.cs
|
||
|
||
// When | ||
var result = filesize.ToString(); | ||
|
||
// Then | ||
result.ShouldBe(expected); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.