Skip to content

Commit

Permalink
Reintroduce deprecated version from fromUnparsedString
Browse files Browse the repository at this point in the history
As this instance method is being actively used by a project, I'm
reimplementing this method in the short term, marking it as deprecated,
which should usually introduce compiler warnings.
  • Loading branch information
Jitsusama committed Jul 12, 2017
1 parent 4afcf8d commit e28166f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
27 changes: 23 additions & 4 deletions Sources/UInt128.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,17 @@ public struct UInt128 {
lowerBits: source.value.lowerBits)
}

/// Initialize a UInt128 value from a string.
///
/// - parameter source: the string that will be converted into a
/// UInt128 value. Defaults to being analyzed as a base10 number,
/// but can be prefixed with `0b` for base2, `0o` for base8
/// or `0x` for base16.
public init(_ source: String) throws {
if let result = UInt128._valueFromString(source) {
self = result
}
else {
guard let result = UInt128._valueFromString(source) else {
throw UInt128Errors.invalidString
}
self = result
}
}

Expand Down Expand Up @@ -744,6 +748,21 @@ extension UInt128 : ExpressibleByStringLiteral {
}
}

// MARK: - Deprecated API

extension UInt128 {
/// Initialize a UInt128 value from a string.
///
/// - parameter source: the string that will be converted into a
/// UInt128 value. Defaults to being analyzed as a base10 number,
/// but can be prefixed with `0b` for base2, `0o` for base8
/// or `0x` for base16.
@available(swift, deprecated: 3.2, renamed: "init(_:)")
public static func fromUnparsedString(_ source: String) throws -> UInt128 {
return try UInt128.init(source)
}
}

// MARK: - FloatingPoint Interworking

extension FloatingPoint {
Expand Down
8 changes: 8 additions & 0 deletions Tests/UInt128Tests/UInt128Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,14 @@ class ExpressibleByStringLiteralTests : XCTestCase {
}
}

@available(swift, deprecated: 3.2)
class DeprecatedAPITests : XCTestCase {
func testFromUnparsedString() {
XCTAssertThrowsError(try UInt128.fromUnparsedString(""))
XCTAssertEqual(try UInt128.fromUnparsedString("1"), UInt128(1))
}
}

class FloatingPointInterworkingTests : XCTestCase {
func testNonFailableInitializer() {
var tests = [(input: UInt128(), output: Float(0))]
Expand Down

0 comments on commit e28166f

Please sign in to comment.