Skip to content

Commit ed618f9

Browse files
committed
Add test for NSUUID.UUIDString
1 parent 1c3eac7 commit ed618f9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Foundation/NSUUID.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public class NSUUID : NSObject, NSCopying, NSSecureCoding, NSCoding {
4646
public var UUIDString: String {
4747
get {
4848
let strPtr = UnsafeMutablePointer<Int8>.alloc(37)
49-
_cf_uuid_unparse_upper(buffer, strPtr)
50-
return String(strPtr)
49+
_cf_uuid_unparse_lower(buffer, strPtr)
50+
return String.fromCString(strPtr)!
5151
}
5252
}
5353

TestFoundation/TestNSUUID.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class TestNSUUID : XCTestCase {
2424
("test_Equality", test_Equality),
2525
("test_InvalidUUID", test_InvalidUUID),
2626
("test_InitializationWithNil", test_InitializationWithNil),
27+
("test_UUIDString", test_UUIDString),
2728
]
2829
}
2930

@@ -47,4 +48,9 @@ class TestNSUUID : XCTestCase {
4748
let uuid = NSUUID(UUIDBytes: nil)
4849
XCTAssertEqual(uuid, NSUUID(UUIDBytes: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), "The convenience initializer `init(UUIDBytes bytes:)` must return the Nil UUID when UUIDBytes is nil.")
4950
}
51+
52+
func test_UUIDString() {
53+
let uuid = NSUUID(UUIDBytes: [0xe6,0x21,0xe1,0xf8,0xc3,0x6c,0x49,0x5a,0x93,0xfc,0x0c,0x24,0x7a,0x3e,0x6e,0x5f])
54+
XCTAssertEqual(uuid.UUIDString, "e621e1f8-c36c-495a-93fc-0c247a3e6e5f", "The UUIDString representation must be lowercase as defined by RFC 4122.")
55+
}
5056
}

0 commit comments

Comments
 (0)