Skip to content

Commit 8972167

Browse files
🩹 [Patch]: Adjust GitHubRepository format to show aligned sizes (#507)
This pull request updates the file size formatting logic in `GitHubFormatter` to ensure consistent output with two decimal places for all units, including bytes, and adjusts the related tests to match the new output format. The most important changes are grouped below: - Fixes #506 File size formatting improvements: * Modified `FormatFileSize` in `GitHubFormatter.ps1` to always display byte values with two decimal places (e.g., "0.00 B" instead of "0 B"). Test updates for new formatting: * Updated test cases in `GitHubFormatter.Tests.ps1` to expect two-decimal formatting for bytes and adjusted regex patterns to match the new output (e.g., `\d+[.,]\d{2}\s{2}B`). * Refactored the test to directly validate the output of the formatter against the new expected patterns, ensuring the tests accurately reflect the updated formatting logic. * Removed outdated comments and redundant test setup to streamline and clarify the test file. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com> Co-authored-by: Marius Storhaug <marstor@hotmail.com>
1 parent 8ef51f0 commit 8972167

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

src/classes/public/GitHubFormatter.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
{ $_ -ge 1MB } { return '{0:N2} MB' -f ($size / 1MB) }
2929
{ $_ -ge 1KB } { return '{0:N2} KB' -f ($size / 1KB) }
3030
}
31-
return "$size B"
31+
return '{0:N2} B' -f $size
3232
}
3333
}

tests/GitHubFormatter.Tests.ps1

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
[CmdletBinding()]
88
param()
99

10-
# This test file validates size property standardization across GitHub classes
11-
# It focuses on unit conversion and formatting expectations rather than live API calls
12-
1310
Describe 'Size Property Standardization Tests' {
14-
1511
Context 'Unit Conversion Logic' {
1612
It 'Validates KB to Bytes conversion formula' {
1713
# Test the conversion used in GitHubRepository and GitHubOrganization
@@ -41,23 +37,19 @@ Describe 'Size Property Standardization Tests' {
4137
}
4238

4339
Context 'Expected Format Output Patterns' {
44-
It 'Validates expected format patterns for size display' {
45-
# These tests verify the expected output patterns without requiring the actual formatter
46-
# They document what the GitHubFormatter::FormatFileSize method should produce
47-
48-
$testCases = @(
49-
@{ Bytes = 0; ExpectedPattern = '\d+\s+B' } # "0 B"
50-
@{ Bytes = 512; ExpectedPattern = '\d+\s+B' } # "512 B"
51-
@{ Bytes = 1024; ExpectedPattern = '\d+\.\d{2} KB' } # "1.00 KB"
52-
@{ Bytes = 1048576; ExpectedPattern = '\d+\.\d{2} MB' } # "1.00 MB"
53-
@{ Bytes = 1073741824; ExpectedPattern = '\d+\.\d{2} GB' } # "1.00 GB"
54-
@{ Bytes = 110592; ExpectedPattern = '\d+\.\d{2} KB' } # "108.00 KB"
55-
)
56-
57-
foreach ($case in $testCases) {
58-
# Document expected pattern - actual formatting tested in integration tests
59-
$case.ExpectedPattern | Should -Match '\w+' # Verify pattern is non-empty
60-
}
40+
$testCases = @(
41+
@{ Bytes = 0; ExpectedPattern = '\d+[.,]\d{2}\s{2}B' } # "0.00 B"
42+
@{ Bytes = 512; ExpectedPattern = '\d+[.,]\d{2}\s{2}B' } # "512.00 B"
43+
@{ Bytes = 1024; ExpectedPattern = '\d+[.,]\d{2} KB' } # "1.00 KB"
44+
@{ Bytes = 1048576; ExpectedPattern = '\d+[.,]\d{2} MB' } # "1.00 MB"
45+
@{ Bytes = 1073741824; ExpectedPattern = '\d+[.,]\d{2} GB' } # "1.00 GB"
46+
@{ Bytes = 110592; ExpectedPattern = '\d+[.,]\d{2} KB' } # "108.00 KB"
47+
)
48+
49+
It 'Validates formatter output pattern for <Bytes> bytes' -ForEach $testCases {
50+
# Test the formatter against the expected pattern
51+
$result = [GitHubFormatter]::FormatFileSize($Bytes)
52+
$result | Should -Match $ExpectedPattern
6153
}
6254
}
6355

0 commit comments

Comments
 (0)