Skip to content

Commit dca57b4

Browse files
committed
SR-1464: Add NSDecimalNumber.description
(cherry picked from commit 7cb608f)
1 parent 4d12a18 commit dca57b4

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

Foundation/NSDecimalNumber.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ open class NSDecimalNumber : NSNumber {
147147
public required convenience init(bytes buffer: UnsafeRawPointer, objCType type: UnsafePointer<Int8>) {
148148
NSRequiresConcreteImplementation()
149149
}
150-
150+
151+
open override var description: String {
152+
return self.decimal.description
153+
}
154+
151155
open override func description(withLocale locale: Locale?) -> String {
152156
guard locale == nil else {
153157
fatalError("Locale not supported: \(locale!)")

TestFoundation/TestDecimal.swift

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ class TestDecimal: XCTestCase {
504504
XCTAssertEqual(1, ten._length)
505505
}
506506

507-
func test_NSDecimal() {
507+
func test_NSDecimal() throws {
508508
var nan = Decimal.nan
509509
XCTAssertTrue(NSDecimalIsNotANumber(&nan))
510510
var zero = Decimal()
@@ -525,6 +525,31 @@ class TestDecimal: XCTestCase {
525525
let nsd1 = NSDecimalNumber(decimal: Decimal(2657.6))
526526
let nsd2 = NSDecimalNumber(floatLiteral: 2657.6)
527527
XCTAssertEqual(nsd1, nsd2)
528+
529+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.min)).description, Int8.min.description)
530+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.max)).description, Int8.max.description)
531+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt8.min)).description, UInt8.min.description)
532+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt8.max)).description, UInt8.max.description)
533+
534+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.min)).description, Int16.min.description)
535+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.max)).description, Int16.max.description)
536+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt16.min)).description, UInt16.min.description)
537+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt16.max)).description, UInt16.max.description)
538+
539+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.min)).description, Int32.min.description)
540+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.max)).description, Int32.max.description)
541+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt32.min)).description, UInt32.min.description)
542+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt32.max)).description, UInt32.max.description)
543+
544+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.min)).description, Int64.min.description)
545+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.max)).description, Int64.max.description)
546+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt64.min)).description, UInt64.min.description)
547+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt64.max)).description, UInt64.max.description)
548+
549+
XCTAssertEqual(try NSDecimalNumber(decimal: Decimal(string: "12.34").unwrapped()).description, "12.34")
550+
XCTAssertEqual(try NSDecimalNumber(decimal: Decimal(string: "0.0001").unwrapped()).description, "0.0001")
551+
XCTAssertEqual(try NSDecimalNumber(decimal: Decimal(string: "-1.0002").unwrapped()).description, "-1.0002")
552+
XCTAssertEqual(try NSDecimalNumber(decimal: Decimal(string: "0.0").unwrapped()).description, "0")
528553
}
529554

530555
func test_PositivePowers() {

0 commit comments

Comments
 (0)