Skip to content
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
3 changes: 3 additions & 0 deletions Sources/removemacai/SelfTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ func selfTest() -> Bool {
"CLICOLOR_FORCE turns color on and off regardless of the terminal")
check(Term.paint("x", "31", useColor: true).contains("\u{1B}[31m") && !Term.paint("x", "31", useColor: false).contains("\u{1B}"),
"stderr text is only colored when its own stream allows it")
check(Term.size(999_999_999) == "1.0 GB" && Term.size(999_500_000) == "1.0 GB"
&& Term.size(999_499_999) == "999 MB" && Term.size(1_000_000_000) == "1.0 GB"
&& Term.size(5_000_000) == "5 MB", "sizes that round to 1000 MB are shown in GB")
check(Storage.isAppleCache("/x/com.apple.Safari") && Storage.isAppleCache("/x/CloudKit")
&& Storage.isAppleCache("/x/GeoServices") && !Storage.isAppleCache("/x/Homebrew")
&& !Storage.isAppleCache("/x/com.google.Chrome"), "macOS caches without the com.apple. prefix are left alone")
Expand Down
3 changes: 2 additions & 1 deletion Sources/removemacai/Term.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ enum Term {

static func size(_ bytes: Int64) -> String {
if bytes <= 0 { return "0 MB" }
if bytes >= 1_000_000_000 { return String(format: "%.1f GB", Double(bytes) / 1e9) }
// Anything that would round to "1000 MB" is shown in GB instead.
if bytes >= 999_500_000 { return String(format: "%.1f GB", Double(bytes) / 1e9) }
return String(format: "%.0f MB", max(1, Double(bytes) / 1e6))
}

Expand Down
Loading