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
8 changes: 7 additions & 1 deletion Sources/PokeTokenBar/Core/TokenFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ enum TokenFormatter {
}

/// 팝오버 상세용 천 단위 구분 (190,612,940)
static func grouped(_ value: Int) -> String {
///
/// 구분기호는 macOS 관례대로 *시스템 지역 설정*(`Locale.current`)을 따른다 — 앱 언어가 아니다.
/// (en/ko/ja `253,412,890` · es/de `253.412.890` · fr/ru `253 412 890`)
/// `locale` 파라미터는 그 관례를 바꾸려는 게 아니라 테스트가 러너의 지역 설정에 좌우되지 않게
/// 하려고 있다 — 기본값을 쓰면 프로덕션 동작은 그대로다.
static func grouped(_ value: Int, locale: Locale = .current) -> String {
let f = NumberFormatter()
f.numberStyle = .decimal
f.locale = locale
return f.string(from: NSNumber(value: value)) ?? "\(value)"
}

Expand Down
9 changes: 8 additions & 1 deletion Tests/PokeTokenBarTests/LocalUsageCacheTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,15 @@ final class LocalUsageCacheTests: XCTestCase {
}

/// 포매터 — grouped/cost/costCompact 경계값(메뉴바·팝오버 표기 계약).
///
/// `grouped` 는 로케일을 명시해 단언한다. 기본값(`Locale.current`)으로 두면 쉼표를 쓰지 않는
/// 지역 설정의 기여자 머신에서만 빨갛게 뜬다(`253 412 890` — PR #160 보고). CI(en_US)와
/// 국내 머신(ko_KR)은 둘 다 쉼표라 이 실패를 영영 못 본다.
/// cost/costCompact/percent 는 `String(format:)` 이라 로케일과 무관하다.
func testFormatterEdges() {
XCTAssertEqual(TokenFormatter.grouped(253_412_890), "253,412,890")
XCTAssertEqual(TokenFormatter.grouped(253_412_890, locale: Locale(identifier: "en_US")), "253,412,890")
// 구분기호가 지역 설정을 따르는지 — locale 인자가 무시되면 여기서 걸린다.
XCTAssertEqual(TokenFormatter.grouped(253_412_890, locale: Locale(identifier: "es_ES")), "253.412.890")
XCTAssertEqual(TokenFormatter.cost(48.104), "$48.10")
XCTAssertEqual(TokenFormatter.costCompact(9.54), "$9.5") // < 100 → 소수 1자리
XCTAssertEqual(TokenFormatter.costCompact(311.4), "$311") // < 10K → 정수
Expand Down