Raise protocol coverage to 99 percent (#1058)

* Expand protocol coverage with edge-case tests

* Stabilize read receipt transport test

* Stabilize BLE duplicate packet test

---------

Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
jack
2026-03-12 17:55:41 -10:00
committed by GitHub
co-authored by jack
parent 8562a76367
commit 264a95b61a
9 changed files with 288 additions and 9 deletions
@@ -69,4 +69,25 @@ final class BinaryEncodingUtilsTests: XCTestCase {
XCTAssertNil(shortData.readFixedBytes(at: &offset, count: 2))
XCTAssertEqual(offset, 0)
}
func test_sha256Hex_andExtendedLengthStringRoundTrip() throws {
XCTAssertEqual(
Data("abc".utf8).sha256Hex(),
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
)
var data = Data()
data.appendString("hello", maxLength: 300)
var offset = 0
XCTAssertEqual(data.readString(at: &offset, maxLength: 300), "hello")
}
func test_readString_returnsNilForInvalidUTF8ExtendedPayload() {
let invalidUTF8 = Data([0x00, 0x02, 0xFF, 0xFF])
var offset = 0
XCTAssertNil(invalidUTF8.readString(at: &offset, maxLength: 300))
XCTAssertEqual(offset, invalidUTF8.count)
}
}