diff --git a/Sources/removemacai/SelfTest.swift b/Sources/removemacai/SelfTest.swift index 029eb06..6873e4e 100644 --- a/Sources/removemacai/SelfTest.swift +++ b/Sources/removemacai/SelfTest.swift @@ -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") diff --git a/Sources/removemacai/Term.swift b/Sources/removemacai/Term.swift index 17793a3..5469579 100644 --- a/Sources/removemacai/Term.swift +++ b/Sources/removemacai/Term.swift @@ -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)) }