Skip to content

Commit 1585dca

Browse files
committed
Add a test for SR-14913.
1 parent 2e9d97d commit 1585dca

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Tests/Foundation/Tests/TestNumberFormatter.swift

+29
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,34 @@ class TestNumberFormatter: XCTestCase {
11761176
#endif
11771177
}
11781178

1179+
func test_copy() throws {
1180+
let original = NumberFormatter()
1181+
let copied = try XCTUnwrap(original.copy() as? NumberFormatter)
1182+
XCTAssertFalse(original === copied)
1183+
1184+
func __assert<T>(_ property: KeyPath<NumberFormatter, T>,
1185+
original expectedValueOfOriginalFormatter: T,
1186+
copy expectedValueOfCopiedFormatter: T,
1187+
file: StaticString = #file,
1188+
line: UInt = #line) where T: Equatable {
1189+
XCTAssertEqual(original[keyPath: property], expectedValueOfOriginalFormatter,
1190+
"Unexpected value in `original`.", file: file, line: line)
1191+
XCTAssertEqual(copied[keyPath: property], expectedValueOfCopiedFormatter,
1192+
"Unexpected value in `copied`.", file: file, line: line)
1193+
}
1194+
1195+
copied.numberStyle = .decimal
1196+
__assert(\.numberStyle, original: .none, copy: .decimal)
1197+
__assert(\.maximumIntegerDigits, original: 42, copy: 2_000_000_000)
1198+
__assert(\.maximumFractionDigits, original: 0, copy: 3)
1199+
__assert(\.groupingSize, original: 0, copy: 3)
1200+
1201+
original.numberStyle = .percent
1202+
original.percentSymbol = ""
1203+
__assert(\.numberStyle, original: .percent, copy: .decimal)
1204+
__assert(\.format, original: "#,##0%;0%;#,##0%", copy: "#,##0.###;0;#,##0.###")
1205+
}
1206+
11791207
static var allTests: [(String, (TestNumberFormatter) -> () throws -> Void)] {
11801208
return [
11811209
("test_defaultPropertyValues", test_defaultPropertyValues),
@@ -1238,6 +1266,7 @@ class TestNumberFormatter: XCTestCase {
12381266
("test_usingFormat", test_usingFormat),
12391267
("test_propertyChanges", test_propertyChanges),
12401268
("test_scientificStrings", test_scientificStrings),
1269+
("test_copy", test_copy),
12411270
]
12421271
}
12431272
}

0 commit comments

Comments
 (0)