Skip to content

Commit 7c0b9dc

Browse files
committed
Added tests
Signed-off-by: Adam Fowler <adamfowler71@gmail.com>
1 parent 9f7fdf9 commit 7c0b9dc

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Sources/Valkey/RESP/RESPBulkString.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ public struct RESPBulkString: Sendable, Equatable, Hashable, RandomAccessCollect
7878
}
7979
#endif
8080

81-
// These are implemented as no-ops for performance reasons.
81+
// These are implemented as no-ops for performance reasons. The range check will be performed
82+
// when the slice is indexed with an index and not a range.
83+
// See https://github.com/swiftlang/swift/blob/153dd02cd8709f8c6afcda5f173237320a3eec87/stdlib/public/core/Collection.swift#L638
8284
@inlinable
8385
public func _failEarlyRangeCheck(_ index: Index, bounds: Range<Index>) {}
8486

Tests/ValkeyTests/RESPTokenTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,22 @@ struct RESPTokenTests {
448448
]
449449
)
450450
}
451+
452+
@Test
453+
func testBulkStringConversion() throws {
454+
let buffer = ByteBuffer(string: "Hello, world!")
455+
let bulkString = RESPBulkString(buffer)
456+
#expect(String(bulkString) == "Hello, world!")
457+
}
458+
459+
@Test
460+
func testBulkStringAsCollection() throws {
461+
let buffer = ByteBuffer(string: "Hello, world!")
462+
let bulkString = RESPBulkString(buffer)
463+
#expect(bulkString[1] == 101)
464+
let world = bulkString[7...11]
465+
#expect(world[world.startIndex] == 119)
466+
}
451467
}
452468

453469
extension RESPToken {

0 commit comments

Comments
 (0)