Skip to content

Commit 62ae29e

Browse files
committed
fix(FormatUtilsTest): Consider locale-specific separator
1 parent e09fdbb commit 62ae29e

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/SyncTrayzor.Tests/FormatUtilsTests.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Globalization;
12
using SyncTrayzor.Utils;
23
using Xunit;
34

@@ -8,24 +9,27 @@ public class FormatUtilsTests
89
// ── BytesToHuman ────────────────────────────────────────────────────
910

1011
[Theory]
11-
[InlineData(0, 0, "0B")]
12-
[InlineData(1, 0, "1B")]
12+
[InlineData(0, 0, "0B")]
13+
[InlineData(1, 0, "1B")]
1314
[InlineData(1023, 0, "1023B")]
1415
[InlineData(1024, 0, "1KiB")]
15-
[InlineData(1536, 0, "2KiB")] // 1.5 KiB rounds to 2 with 0 decimal places
16-
[InlineData(1048576, 0, "1MiB")] // 1 MiB
17-
[InlineData(1073741824, 0, "1GiB")] // 1 GiB
16+
[InlineData(1536, 0, "2KiB")] // 1.5 KiB rounds to 2 with 0 decimal places
17+
[InlineData(1048576, 0, "1MiB")] // 1 MiB
18+
[InlineData(1073741824, 0, "1GiB")] // 1 GiB
1819
public void BytesToHuman_DefaultDecimalPlaces(double bytes, int decimalPlaces, string expected)
1920
{
2021
Assert.Equal(expected, FormatUtils.BytesToHuman(bytes, decimalPlaces));
2122
}
2223

2324
[Theory]
24-
[InlineData(1536, 1, "1.5KiB")] // exactly 1.5 KiB
25-
[InlineData(1024, 2, "1.00KiB")]
25+
[InlineData(1536, 1, "1.5KiB")] // exactly 1.5 KiB
26+
[InlineData(1024, 2, "1.00KiB")]
2627
[InlineData(1048576, 1, "1.0MiB")]
2728
public void BytesToHuman_WithDecimalPlaces(double bytes, int decimalPlaces, string expected)
2829
{
30+
// Some countries may be using other characters (,) instead of . for decimal separation
31+
var systemNumberSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
32+
expected = expected.Replace(".", systemNumberSeparator);
2933
Assert.Equal(expected, FormatUtils.BytesToHuman(bytes, decimalPlaces));
3034
}
3135

@@ -45,4 +49,4 @@ public void BytesToHuman_CapsAtGiB()
4549
Assert.EndsWith("GiB", result);
4650
}
4751
}
48-
}
52+
}

0 commit comments

Comments
 (0)