Skip to content

Commit ee6fbcf

Browse files
committed
PR changes
1 parent 194227f commit ee6fbcf

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Sources/GRPCCore/Metadata.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,15 +494,23 @@ extension Metadata.Value: ExpressibleByArrayLiteral {
494494

495495
extension Metadata: CustomStringConvertible {
496496
public var description: String {
497-
String(describing: self.map({ ($0.key.description, $0.value.description) }))
497+
var description = "["
498+
description = self.dropLast().reduce(into: description) { partialResult, nextPair in
499+
partialResult += "\"\(nextPair.key)\": \(nextPair.value), "
500+
}
501+
if let lastElement = self.last {
502+
description += "\"\(lastElement.key)\": \(lastElement.value)"
503+
}
504+
description += "]"
505+
return description
498506
}
499507
}
500508

501509
extension Metadata.Value: CustomStringConvertible {
502510
public var description: String {
503511
switch self {
504512
case .string(let stringValue):
505-
return stringValue
513+
return "\"\(stringValue)\""
506514
case .binary(let binaryValue):
507515
return String(describing: binaryValue)
508516
}

Tests/GRPCCoreTests/MetadataTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,17 @@ struct MetadataTests {
314314
)
315315
}
316316
}
317+
318+
@Suite("Description")
319+
struct Description {
320+
@Test("Metadata")
321+
func describeMetadata() async throws {
322+
let metadata: Metadata = [
323+
"key1": "value1",
324+
"key2": "value2",
325+
"key-bin": .binary([1,2,3]),
326+
]
327+
#expect("\(metadata)" == #"["key1": "value1", "key2": "value2", "key-bin": [1, 2, 3]]"#)
328+
}
329+
}
317330
}

0 commit comments

Comments
 (0)