refactor(menubar): 精简内存卡片并对齐双列底部
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import Foundation
|
||||
|
||||
@main struct MemoryHeaderChecks {
|
||||
static func main() {
|
||||
let bundle = Bundle(path: CommandLine.arguments[1])!
|
||||
for (language, titles) in [("en", ["Normal", "Elevated", "Critical"]),
|
||||
("zh-Hans", ["正常", "偏高", "严重"]),
|
||||
("zh-Hant", ["正常", "偏高", "嚴重"])] {
|
||||
let locale = Locale(identifier: language)
|
||||
func localized(_ key: String) -> String { AppLocalization.string(key, locale: locale, bundle: bundle) }
|
||||
for (pressure, title) in zip([1, 2, 4], titles) {
|
||||
let memory = MemoryMetrics(total: 48 << 30, used: 20 << 30, wired: 3 << 30,
|
||||
compressed: 2 << 30, swapUsed: 0, pressure: pressure, cached: 12 << 30)
|
||||
let header = MemoryHeaderInfo(memory: memory, locale: locale, bundle: bundle)
|
||||
precondition(header.title == title)
|
||||
precondition(header.help.components(separatedBy: "\n") == [
|
||||
"\(localized("memory.pressure")): \(title)",
|
||||
"\(localized("memory.cached")): 12.0 GiB",
|
||||
"\(localized("memory.swap")): 0 B"
|
||||
], "Hover details must retain the selected language, current cache and valid zero Swap")
|
||||
}
|
||||
for pressure: Int? in [nil, 8] {
|
||||
let unknown = MemoryMetrics(total: 0, used: 0, wired: 0, compressed: 0,
|
||||
swapUsed: nil, pressure: pressure)
|
||||
let header = MemoryHeaderInfo(memory: unknown, locale: locale, bundle: bundle)
|
||||
precondition(header.title == "--")
|
||||
precondition(header.help.components(separatedBy: "\n").allSatisfy { $0.hasSuffix(": --") })
|
||||
}
|
||||
let absent = MemoryHeaderInfo(memory: nil, locale: locale, bundle: bundle)
|
||||
precondition(absent.title == "--" && absent.help.components(separatedBy: "\n").allSatisfy { $0.hasSuffix(": --") },
|
||||
"Unavailable samples must not become a normal pressure or zero usage")
|
||||
}
|
||||
print("PASS: three-language pressure and hover details, current cache, valid zero Swap and unknown/unavailable samples")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user