diff --git a/Sources/Datadog/Tracing/UUIDs/TracingUUID.swift b/Sources/Datadog/Tracing/UUIDs/TracingUUID.swift index 7cead494b4..947482273a 100644 --- a/Sources/Datadog/Tracing/UUIDs/TracingUUID.swift +++ b/Sources/Datadog/Tracing/UUIDs/TracingUUID.swift @@ -40,9 +40,9 @@ internal struct TracingUUID: Equatable, Hashable { case .hexadecimal: return String(rawValue, radix: 16) case .hexadecimal16Chars: - return String(format: "%016x", rawValue) + return String(format: "%016llx", rawValue) case .hexadecimal32Chars: - return String(format: "%032x", rawValue) + return String(format: "%032llx", rawValue) } } } diff --git a/Tests/DatadogTests/Datadog/Tracing/UUIDs/TracingUUIDTests.swift b/Tests/DatadogTests/Datadog/Tracing/UUIDs/TracingUUIDTests.swift index 85ed3e5651..41589e803b 100644 --- a/Tests/DatadogTests/Datadog/Tracing/UUIDs/TracingUUIDTests.swift +++ b/Tests/DatadogTests/Datadog/Tracing/UUIDs/TracingUUIDTests.swift @@ -18,6 +18,26 @@ class UUIDTests: XCTestCase { XCTAssertEqual(TracingUUID(rawValue: .max).toString(.hexadecimal), "ffffffffffffffff") } + func testTo16CharHexadecimalStringConversion() { + XCTAssertEqual(TracingUUID(rawValue: 0).toString(.hexadecimal16Chars), "0000000000000000") + XCTAssertEqual(TracingUUID(rawValue: 1).toString(.hexadecimal16Chars), "0000000000000001") + XCTAssertEqual(TracingUUID(rawValue: 15).toString(.hexadecimal16Chars), "000000000000000f") + XCTAssertEqual(TracingUUID(rawValue: 16).toString(.hexadecimal16Chars), "0000000000000010") + XCTAssertEqual(TracingUUID(rawValue: 123).toString(.hexadecimal16Chars), "000000000000007b") + XCTAssertEqual(TracingUUID(rawValue: 123_456).toString(.hexadecimal16Chars), "000000000001e240") + XCTAssertEqual(TracingUUID(rawValue: .max).toString(.hexadecimal16Chars), "ffffffffffffffff") + } + + func testTo32CharHexadecimalStringConversion() { + XCTAssertEqual(TracingUUID(rawValue: 0).toString(.hexadecimal32Chars), "00000000000000000000000000000000") + XCTAssertEqual(TracingUUID(rawValue: 1).toString(.hexadecimal32Chars), "00000000000000000000000000000001") + XCTAssertEqual(TracingUUID(rawValue: 15).toString(.hexadecimal32Chars), "0000000000000000000000000000000f") + XCTAssertEqual(TracingUUID(rawValue: 16).toString(.hexadecimal32Chars), "00000000000000000000000000000010") + XCTAssertEqual(TracingUUID(rawValue: 123).toString(.hexadecimal32Chars), "0000000000000000000000000000007b") + XCTAssertEqual(TracingUUID(rawValue: 123_456).toString(.hexadecimal32Chars), "0000000000000000000000000001e240") + XCTAssertEqual(TracingUUID(rawValue: .max).toString(.hexadecimal32Chars), "0000000000000000ffffffffffffffff") + } + func testToDecimalStringConversion() { XCTAssertEqual(TracingUUID(rawValue: 0).toString(.decimal), "0") XCTAssertEqual(TracingUUID(rawValue: 1).toString(.decimal), "1")