38 lines
2.4 KiB
Swift
38 lines
2.4 KiB
Swift
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.badgeTitle == localized("memory.pressurePrefix") + 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.badgeTitle == "--")
|
|
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")
|
|
}
|
|
}
|