@@ -1176,6 +1176,34 @@ class TestNumberFormatter: XCTestCase {
1176
1176
#endif
1177
1177
}
1178
1178
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
+
1179
1207
static var allTests : [ ( String , ( TestNumberFormatter ) -> ( ) throws -> Void ) ] {
1180
1208
return [
1181
1209
( " test_defaultPropertyValues " , test_defaultPropertyValues) ,
@@ -1238,6 +1266,7 @@ class TestNumberFormatter: XCTestCase {
1238
1266
( " test_usingFormat " , test_usingFormat) ,
1239
1267
( " test_propertyChanges " , test_propertyChanges) ,
1240
1268
( " test_scientificStrings " , test_scientificStrings) ,
1269
+ ( " test_copy " , test_copy) ,
1241
1270
]
1242
1271
}
1243
1272
}
0 commit comments