Skip to content

Commit

Permalink
Merge pull request #1311 from changm4n/a-fix-string-format
Browse files Browse the repository at this point in the history
Fix TracingUUID toString string format
  • Loading branch information
ncreated authored Jun 26, 2023
2 parents d0a633d + 8588f3c commit 18d46c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/Datadog/Tracing/UUIDs/TracingUUID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions Tests/DatadogTests/Datadog/Tracing/UUIDs/TracingUUIDTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 18d46c6

Please sign in to comment.