Merge pull request #7 from yaslab/rename-parameter
Rename the parameter name of `init(timestamp:uuid:)`
This commit is contained in:
commit
f36cc11787
|
@ -39,11 +39,11 @@ public struct ULID: Hashable, Equatable, Comparable, CustomStringConvertible {
|
|||
/// Creates a new ULID instance from a given timestamp and a random part that you provide
|
||||
/// - Parameters:
|
||||
/// - timestamp: -
|
||||
/// - uuid: Data representation of the random part of the ULID
|
||||
/// - Returns: **NIL** if the ULID is less than 80 bits or 10 bytes in size
|
||||
public init?(timestamp: Date = Date(), uuid: Data){
|
||||
/// - randomPartData: Data representation of the random part of the ULID
|
||||
/// - Returns: **NIL** if the `randomPartData` is less than 80 bits or 10 bytes in size
|
||||
public init?(timestamp: Date = Date(), randomPartData data: Data){
|
||||
let randomDataInBytes = 10
|
||||
guard uuid.count >= randomDataInBytes else { return nil }
|
||||
guard data.count >= randomDataInBytes else { return nil }
|
||||
|
||||
withUnsafeMutableBytes(of: &ulid) { (buffer) in
|
||||
var i = 0
|
||||
|
@ -55,10 +55,10 @@ public struct ULID: Hashable, Equatable, Comparable, CustomStringConvertible {
|
|||
}
|
||||
}
|
||||
var randomPart:Data = Data()
|
||||
if uuid.count > randomDataInBytes{
|
||||
randomPart = uuid.prefix(randomDataInBytes)
|
||||
if data.count > randomDataInBytes{
|
||||
randomPart = data.prefix(randomDataInBytes)
|
||||
}else{
|
||||
randomPart = uuid
|
||||
randomPart = data
|
||||
}
|
||||
|
||||
withUnsafeBytes(of: &randomPart) {
|
||||
|
|
|
@ -39,7 +39,7 @@ final class ULIDTests: XCTestCase {
|
|||
0x01, 0x68, 0x3D, 0x17, 0x73, 0x09, 0x69, 0xF4, 0xA2, 0xB1
|
||||
]
|
||||
|
||||
let actual = ULID(timestamp: timestamp, uuid: Data(uuidCorrectSize))!
|
||||
let actual = ULID(timestamp: timestamp, randomPartData: Data(uuidCorrectSize))!
|
||||
XCTAssertEqual(timestamp, actual.timestamp)
|
||||
|
||||
XCTAssertEqual(0x01, actual.ulid.6)
|
||||
|
@ -60,7 +60,7 @@ final class ULIDTests: XCTestCase {
|
|||
0x01, 0x68, 0x3D, 0x17, 0x73, 0x09, 0x69, 0xF4, 0xA2, 0xB1, 0x99, 0x55
|
||||
]
|
||||
|
||||
let actual2 = ULID(timestamp: timestamp, uuid: Data(uuidTooBigSize))!
|
||||
let actual2 = ULID(timestamp: timestamp, randomPartData: Data(uuidTooBigSize))!
|
||||
XCTAssertEqual(timestamp, actual.timestamp)
|
||||
|
||||
XCTAssertEqual(0x01, actual2.ulid.6)
|
||||
|
@ -79,7 +79,7 @@ final class ULIDTests: XCTestCase {
|
|||
0x01, 0x68, 0x3D, 0x17, 0x73,
|
||||
]
|
||||
|
||||
XCTAssertNil(ULID(timestamp: timestamp, uuid: Data(uuidTooSmallSize)))
|
||||
XCTAssertNil(ULID(timestamp: timestamp, randomPartData: Data(uuidTooSmallSize)))
|
||||
}
|
||||
|
||||
func testGenerateRandomness() {
|
||||
|
|
Loading…
Reference in New Issue