Skip to content

Commit e513972

Browse files
committed
Add non-debug printing support
1 parent 35779a1 commit e513972

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

Sources/EmbeddedIntegerCollection/EmbeddedIntegerCollection.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,22 @@ extension EmbeddedIntegerCollection: Sendable where Wrapped: Sendable {}
100100
extension EmbeddedIntegerCollection: BitwiseCopyable
101101
where Wrapped: BitwiseCopyable {}
102102

103-
// MARK: Debugging
103+
// MARK: Printing
104+
105+
extension EmbeddedIntegerCollection: CustomStringConvertible {
106+
public var description: String {
107+
var result = "["
108+
print(
109+
lazy.map {
110+
String($0, radix: 16, uppercase: true)
111+
}.joined(separator: ", "),
112+
separator: "",
113+
terminator: "",
114+
to: &result
115+
)
116+
return result + "]"
117+
}
118+
}
104119

105120
extension EmbeddedIntegerCollection: CustomDebugStringConvertible {
106121
public var debugDescription: String {

Tests/EmbeddedIntegerCollectionTests/EmbeddedIntegerCollectionTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,37 @@ func sequenceInitialization(
278278
#expect(shortPrefixCollection == nil)
279279
#expect(shortFullCollection == nil)
280280
}
281+
282+
@Test(
283+
"Normal Printing",
284+
arguments: zip(
285+
[
286+
(0, true),
287+
(0, false),
288+
(.max, true),
289+
(.max, false),
290+
(0x4041_4243, true),
291+
(0x4041_4243, false),
292+
],
293+
[
294+
"[0, 0, 0, 0]",
295+
"[0, 0, 0, 0]",
296+
"[FF, FF, FF, FF]",
297+
"[FF, FF, FF, FF]",
298+
"[40, 41, 42, 43]",
299+
"[43, 42, 41, 40]",
300+
]
301+
)
302+
)
303+
func normalPrint(_ input: (base: UInt32, isBigEndian: Bool), expected: String)
304+
async throws
305+
{
306+
let collection = EmbeddedIntegerCollection(
307+
embedding: UInt8.self,
308+
within: input.base,
309+
iteratingFrom: input.isBigEndian
310+
? .mostSignificantFirst
311+
: .leastSignificantFirst
312+
)
313+
#expect(String(describing: collection) == expected)
314+
}

0 commit comments

Comments
 (0)