Skip to content

Commit 7cb608f

Browse files
committed
SR-1464: Add NSDecimalNumber.description
1 parent 2480df6 commit 7cb608f

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
@@ -212,7 +212,11 @@ open class NSDecimalNumber : NSNumber {
212212
public required convenience init(bytes buffer: UnsafeRawPointer, objCType type: UnsafePointer<Int8>) {
213213
NSRequiresConcreteImplementation()
214214
}
215-
215+
216+
open override var description: String {
217+
return self.decimal.description
218+
}
219+
216220
open override func description(withLocale locale: Locale?) -> String {
217221
guard locale == nil else {
218222
fatalError("Locale not supported: \(locale!)")

TestFoundation/TestDecimal.swift

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ class TestDecimal: XCTestCase {
518518
XCTAssertEqual(1, ten._length)
519519
}
520520

521-
func test_NSDecimal() {
521+
func test_NSDecimal() throws {
522522
var nan = Decimal.nan
523523
XCTAssertTrue(NSDecimalIsNotANumber(&nan))
524524
var zero = Decimal()
@@ -539,6 +539,31 @@ class TestDecimal: XCTestCase {
539539
let nsd1 = NSDecimalNumber(decimal: Decimal(2657.6))
540540
let nsd2 = NSDecimalNumber(floatLiteral: 2657.6)
541541
XCTAssertEqual(nsd1, nsd2)
542+
543+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.min)).description, Int8.min.description)
544+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.max)).description, Int8.max.description)
545+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt8.min)).description, UInt8.min.description)
546+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt8.max)).description, UInt8.max.description)
547+
548+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.min)).description, Int16.min.description)
549+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.max)).description, Int16.max.description)
550+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt16.min)).description, UInt16.min.description)
551+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt16.max)).description, UInt16.max.description)
552+
553+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.min)).description, Int32.min.description)
554+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.max)).description, Int32.max.description)
555+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt32.min)).description, UInt32.min.description)
556+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt32.max)).description, UInt32.max.description)
557+
558+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.min)).description, Int64.min.description)
559+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.max)).description, Int64.max.description)
560+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt64.min)).description, UInt64.min.description)
561+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt64.max)).description, UInt64.max.description)
562+
563+
XCTAssertEqual(try NSDecimalNumber(decimal: Decimal(string: "12.34").unwrapped()).description, "12.34")
564+
XCTAssertEqual(try NSDecimalNumber(decimal: Decimal(string: "0.0001").unwrapped()).description, "0.0001")
565+
XCTAssertEqual(try NSDecimalNumber(decimal: Decimal(string: "-1.0002").unwrapped()).description, "-1.0002")
566+
XCTAssertEqual(try NSDecimalNumber(decimal: Decimal(string: "0.0").unwrapped()).description, "0")
542567
}
543568

544569
func test_PositivePowers() {

0 commit comments

Comments
 (0)