Files
Termind/TermindTests/ChatMessageTimestampTests.swift
T
Kaede Akino ba46e90e30 Format with swift-format
`swift-format lint --strict --recursive Termind TermindTests
TermindMCPBridge` is in the contribution instructions but had never been
run to completion: 4133 violations across 141 files, most of them
indentation and line breaking the pretty-printer would have settled on
its own.

`swift-format format -i` accounts for all but five. The rest are
lint-only rules it will not rewrite for you:

- `SSHKeyMaterial` declared its libssh2 entry point in the C symbol's
  own spelling. `@_silgen_name` already carries the linkage name, so the
  Swift side is free to be `libssh2PublicKeyFromPrivateMemory`.
- Four `.forEach { ... }` calls become for-in loops, two in
  `PortForwardingController` and two in tests.

Formatting only, and checked as such rather than assumed: all 5409
string literals under `Termind` are byte-identical across the change, so
no localization key moved. Comparing whitespace-stripped token streams
leaves 43 files with any real change, and each is one of the rules
above, a dropped semicolon, a `case a, b` split onto separate lines with
its raw values kept explicit, or a file-scope `private` respelled
`fileprivate` — which is the same access level in that position.

Builds, and the suite stays at 975 of 975.
2026-09-02 18:09:30 +08:00

80 lines
2.6 KiB
Swift

import Foundation
import Testing
@testable import Termind
@Suite
struct ChatMessageTimestampTests {
@Test
func todayUsesOnlyTheLocalizedShortTime() throws {
let timeZone = try #require(TimeZone(identifier: "Asia/Shanghai"))
let locale = Locale(identifier: "zh_CN")
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = timeZone
let message = try #require(
calendar.date(
from: DateComponents(
year: 2026, month: 8, day: 26, hour: 9, minute: 5
)))
let now = try #require(
calendar.date(
from: DateComponents(
year: 2026, month: 8, day: 26, hour: 17
)))
#expect(
ChatMessageTimestampFormatter.string(
for: message, now: now, calendar: calendar,
locale: locale, timeZone: timeZone
)
== expected(
message, dateStyle: .none, locale: locale,
calendar: calendar, timeZone: timeZone
))
}
@Test
func anOlderDayIncludesLocalizedDateAndTime() throws {
let timeZone = try #require(TimeZone(identifier: "America/Los_Angeles"))
let locale = Locale(identifier: "en_US")
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = timeZone
let message = try #require(
calendar.date(
from: DateComponents(
year: 2026, month: 8, day: 25, hour: 23, minute: 15
)))
let now = try #require(
calendar.date(
from: DateComponents(
year: 2026, month: 8, day: 26, hour: 8
)))
#expect(
ChatMessageTimestampFormatter.string(
for: message, now: now, calendar: calendar,
locale: locale, timeZone: timeZone
)
== expected(
message, dateStyle: .short, locale: locale,
calendar: calendar, timeZone: timeZone
))
}
private func expected(
_ date: Date,
dateStyle: DateFormatter.Style,
locale: Locale,
calendar: Calendar,
timeZone: TimeZone
) -> String {
let formatter = DateFormatter()
formatter.locale = locale
formatter.calendar = calendar
formatter.timeZone = timeZone
formatter.dateStyle = dateStyle
formatter.timeStyle = .short
return formatter.string(from: date)
}
}