Skip to content

Commit

Permalink
Add a test for SR-14913.
Browse files Browse the repository at this point in the history
  • Loading branch information
YOCKOW committed Oct 4, 2021
1 parent 2e9d97d commit 1585dca
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Tests/Foundation/Tests/TestNumberFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,34 @@ class TestNumberFormatter: XCTestCase {
#endif
}

func test_copy() throws {
let original = NumberFormatter()
let copied = try XCTUnwrap(original.copy() as? NumberFormatter)
XCTAssertFalse(original === copied)

func __assert<T>(_ property: KeyPath<NumberFormatter, T>,
original expectedValueOfOriginalFormatter: T,
copy expectedValueOfCopiedFormatter: T,
file: StaticString = #file,
line: UInt = #line) where T: Equatable {
XCTAssertEqual(original[keyPath: property], expectedValueOfOriginalFormatter,
"Unexpected value in `original`.", file: file, line: line)
XCTAssertEqual(copied[keyPath: property], expectedValueOfCopiedFormatter,
"Unexpected value in `copied`.", file: file, line: line)
}

copied.numberStyle = .decimal
__assert(\.numberStyle, original: .none, copy: .decimal)
__assert(\.maximumIntegerDigits, original: 42, copy: 2_000_000_000)
__assert(\.maximumFractionDigits, original: 0, copy: 3)
__assert(\.groupingSize, original: 0, copy: 3)

original.numberStyle = .percent
original.percentSymbol = ""
__assert(\.numberStyle, original: .percent, copy: .decimal)
__assert(\.format, original: "#,##0%;0%;#,##0%", copy: "#,##0.###;0;#,##0.###")
}

static var allTests: [(String, (TestNumberFormatter) -> () throws -> Void)] {
return [
("test_defaultPropertyValues", test_defaultPropertyValues),
Expand Down Expand Up @@ -1238,6 +1266,7 @@ class TestNumberFormatter: XCTestCase {
("test_usingFormat", test_usingFormat),
("test_propertyChanges", test_propertyChanges),
("test_scientificStrings", test_scientificStrings),
("test_copy", test_copy),
]
}
}

0 comments on commit 1585dca

Please sign in to comment.