Skip to content

Commit a8de83b

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

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
@@ -503,7 +503,7 @@ class TestDecimal: XCTestCase {
503503
XCTAssertEqual(1, ten._length)
504504
}
505505

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

529554
func test_PositivePowers() {

0 commit comments

Comments
 (0)